def __init__(self, game, x, y, brain_weights=[]):
		GameObject.__init__(self, game, x, y)
		self.speed = 0
		self.direction = 90
		self.score = 0
		self.brain = NeuralNet(brain_weights)
	def destroy(self, game):
		self.brain = 0
		GameObject.destroy(self, game)
Example #3
0
 def __init__(self, game, x, y, brain_weights=[]):
     GameObject.__init__(self, game, x, y)
     self.speed = 0
     self.direction = 90
     self.score = 0
     self.brain = NeuralNet(brain_weights)
Example #4
0
 def destroy(self, game):
     self.brain = 0
     GameObject.destroy(self, game)
Example #5
0
    def run_game_loop(self, level, KREMUFKA_SCORE):
        is_game_over = False
        did_win = False

        x_direction = 0
        y_direction = 0

        pygame.mixer.stop()
        sound = pygame.mixer.Sound('sounds/sound.wav')

        player = PlayerCharacter('textures/player.png', 375, 700, 50, 50)
        treasure = GameObject('textures/treasure.png', 375, 50, 50, 50)
        cream = GameObject('textures/kremowka.png', 200, 450, 25, 25,
                           'sounds/cream_aquired.wav')

        # Enemies
        enemies = []
        enemy_0 = NonPlayerCharacter('textures/enemy.png', self.width - 40,
                                     600, 50, 50)
        enemy_0.SPEED *= level * 0.5
        enemies.append(enemy_0)

        enemy_1 = NonPlayerCharacter('textures/enemy.png', 40, 450, 50, 50)
        enemy_1.SPEED *= level * 0.5
        enemies.append(enemy_1)

        enemy_2 = NonPlayerCharacter('textures/enemy.png', self.width - 40,
                                     300, 50, 50)
        enemy_2.SPEED *= level * 0.5
        enemies.append(enemy_2)

        sound.play()

        while not is_game_over:

            # event - mouse movement, mouse button clicks, exit events
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    is_game_over = True
                elif event.type == pygame.KEYDOWN:
                    # Y axis movement
                    if event.key == pygame.K_UP:  # Move up if up key pressed
                        y_direction = 1
                    elif event.key == pygame.K_DOWN:  # Move down if down key pressed
                        y_direction = -1

                    # X axis movement
                    if event.key == pygame.K_RIGHT:
                        x_direction = 1
                    elif event.key == pygame.K_LEFT:
                        x_direction = -1

                elif event.type == pygame.KEYUP:  # RELEASE - STOP MOVEMENT
                    if event.key == pygame.K_UP or event.key == pygame.K_DOWN:
                        y_direction = 0
                    if event.key == pygame.K_LEFT or event.key == pygame.K_RIGHT:
                        x_direction = 0

                print(event)

            self.game_screen.blit(self.image, (0, 0))
            self.game_screen.blit(self.score_text(KREMUFKA_SCORE), (0, 0))
            treasure.draw(self.game_screen)
            if cream.exists:
                cream.draw(self.game_screen)

            player.move(x_direction, y_direction, self.width, self.height)
            player.draw(self.game_screen)

            #enemy_0.move(self.width)
            enemy_0.alt_move(self.width)
            enemy_0.draw(self.game_screen)

            if level > 3:
                enemy_1.move(self.width)
                enemy_1.draw(self.game_screen)
            if level > 5:
                enemy_2.move(self.width)
                enemy_2.draw(self.game_screen)

            # COLLISION DETECTION
            for enemy in enemies:
                if player.detect_collision(enemy):
                    is_game_over = True
                    did_win = False
                    text = font.render('You lose :)', True, BLACK_COLOR)
                    self.game_screen.blit(text, (300, 350))
                    self.lose_sound.play()
                    pygame.display.update()
                    clock.tick(0.5)
                    break

            if player.detect_collision(cream) and cream.exists:
                cream.sound.play()
                KREMUFKA_SCORE += 0.5
                cream.exists = 0

            if player.detect_collision(treasure):
                is_game_over = True
                did_win = True
                text = font.render('You win :(', True, BLACK_COLOR)
                self.game_screen.blit(text, (300, 350))
                self.win_sound.play()
                pygame.display.update()
                clock.tick(0.5)
                break

            pygame.display.update()
            clock.tick(self.TICK_RATE)
        if did_win:
            self.run_game_loop(level + 1, KREMUFKA_SCORE + 1)
        else:
            return
Example #6
0
    1920, 1080
)  # Since the renderer uses pixel coordinates instead of 0-1 coordinates, which is kinda lame tbh.
local_ratio = 40  # Divide local coords by this number, in order to fit them on screen. Increasing this will reduce the scale of the debug display, but will not reduce rectangle sizes.

# Debug toggles
debug_strats = True
debug_controls = False
debug_dodge = False
debug_prediction = False
debug_car = True
debug_ball = False
debug_target = True
debug_boostpads = False
debug_scenarios = True

car = GameObject()


class DebugUtils:
    debug = False

    @classmethod
    def debugprint(cls, s):
        if cls.debug:
            print(s)

    def debug_line(co1, co2, color=None):
        pass


def ensure_color(color=None):
Example #7
0
pg.init()

size = width, height = (640, 480)
black = (0, 0, 0)

screen = pg.display.set_mode(size)
screen.fill(black)

player = pg.image.load('player.jpg').convert()
resize = [int(i / 6) for i in player.get_rect() if i]
player = pg.transform.scale(player, resize)

objects = []

for i in range(10):
    o = gobj.GameObject(player, i * 40, i)
    objects.append(o)


def main():
    while True:
        for event in pg.event.get():
            if event.type == pg.QUIT:
                sys.exit()

        for o in objects:
            o.move()
            screen.blit(o.image, o.rect)

        pg.display.update()
        pg.time.delay(100)