Пример #1
0
    def __process__(self, delta_time):
        if game.is_action_just_pressed(action="confirm"):
            game.play_sound(sound_id="pacman-chomp")
            game.change_to_scene(file_path="./scenes/transition.json")

        if game.is_action_just_pressed(action="exit_game"):
            game.quit()
Пример #2
0
    def die(self):
        self.lives -= 1

        if self.lives > 0:
            game.play_sound(game.DIE_SOUND)
        else:
            game.play_sound(game.GAMEOVER_SOUND)
Пример #3
0
    def jump(self, blocks):
        self.rect.y += 1

        hit_list = pygame.sprite.spritecollide(self, blocks, False)

        if len(hit_list) > 0:
            self.vy = -1 * self.jump_power
            game.play_sound(game.JUMP_SOUND)

        self.rect.y -= 1
Пример #4
0
 def score(self, value):
     self._score = value
     game.update_label_entity_text(entity_id="player_one_point_value_label",
                                   text=f"{self._score}")
     if self._score > self.high_score:
         self.high_score = self._score
     if self._score >= 10000 and not self.extra_life_earned:
         self.lives += 1
         self.extra_life_earned = True
         game.play_sound(sound_id="pacman-extra-life")
Пример #5
0
    def process_enemies(self, enemies):
        hit_list = pygame.sprite.spritecollide(self, enemies, False)

        if len(hit_list) > 0 and self.invincibility == 0:
            if self.vy > 0:
                [e.kill() for e in hit_list]
                self.vy = -self.jump_power
                self.score += 1
                return
            game.play_sound(game.HURT_SOUND)
            if self.vx > 0: # right facing hit
                self.rect.x += -self.jump_power
            elif self.vx < 0: # left facing hit
                self.rect.x += self.jump_power
            self.hearts -= 1
            self.invincibility = int(0.75 * game.FPS)
Пример #6
0
 def _on_pacman_lose_life_start_timer_timeout(self):
     for ghost_entity_id in ["blinky", "pinky", "inky", "clyde"]:
         game.set_entity_visibility(entity_id=ghost_entity_id,
                                    visible=False)
     pacman_entity = scene_tree.get_entity("pacman")
     pacman_entity.lose_life()
     game.start_timer(timer_id=self.level_reset_timer_id)
     game.play_sound(sound_id="pacman-death")
     if global_obj.player_stats.lives <= 0:
         game.create_label_entity(entity_id="game_over_label",
                                  text="GAME  OVER",
                                  position=(147, 318),
                                  font_id="pacman-pixel",
                                  layer=5,
                                  fixed=False,
                                  wrap_length=600,
                                  color=(255, 0, 0))
Пример #7
0
window = pygame.display.set_mode([600, 600])

running = True
clock = pygame.time.Clock()

nickname = " "

me = "X"
ia = "O"

while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            play_sound("minimize_001")

        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_BACKSPACE and len(nickname) > 2:
                nickname = list(nickname)
                nickname.pop(-2)
                nickname = "".join(nickname)
                play_sound("error_001")
            elif len(nickname.strip()) <= 10:
                play_sound("bong_001")
                if len(nickname) > 1:
                    nickname = list(nickname)
                    nickname.pop(-1)
                    nickname = "".join(nickname)
                nickname += event.unicode
                nickname += " "
Пример #8
0
    def __create__(self):
        self.power_pellete_ids = []
        self.power_pelletes_visible = True
        self.one_up_visible = True
        self.start_timer_id = "start_timer"
        self.level_reset_timer_id = "level_reset_timer"
        self.level_cleared_timer_id = "level_cleared_timer"
        self.level_cleared_transtion_timer_id = "level_cleared_transtion_timer"
        power_pellete_flash_timer_id = "power_pellete_timer"
        self.pacman_lose_life_start_timer_id = "pacman_lose_life_start_timer"
        self.ghost_frightened_timer_id = "ghost_frightened_timer"
        self.show_entities_timer_id = "show_entities_timer"

        # Start Timer
        game.create_timer(timer_id=self.start_timer_id,
                          time=4.2,
                          loops=False,
                          start_on_creation=False)
        game.subscribe_to_signal(
            source_id=self.start_timer_id,
            signal_id="timeout",
            subscriber_entity_id=self.entity_id,
            function_name="_on_start_timer_timeout",
        )

        # Level Reset Timer
        game.create_timer(
            timer_id=self.level_reset_timer_id,
            time=2.0,
            loops=False,
            start_on_creation=False,
        )
        game.subscribe_to_signal(
            source_id=self.level_reset_timer_id,
            signal_id="timeout",
            subscriber_entity_id=self.entity_id,
            function_name="_on_level_reset_timer_timeout",
        )

        # Level Cleared Timer
        game.create_timer(
            timer_id=self.level_cleared_timer_id,
            time=1.5,
            loops=False,
            start_on_creation=False,
        )
        game.subscribe_to_signal(
            source_id=self.level_cleared_timer_id,
            signal_id="timeout",
            subscriber_entity_id=self.entity_id,
            function_name="_on_level_cleared_timer_timeout",
        )

        # Level Cleared Transtion Timer
        game.create_timer(
            timer_id=self.level_cleared_transtion_timer_id,
            time=2.0,
            loops=False,
            start_on_creation=False,
        )
        game.subscribe_to_signal(
            source_id=self.level_cleared_transtion_timer_id,
            signal_id="timeout",
            subscriber_entity_id=self.entity_id,
            function_name="_on_level_cleared_transition_timer_timeout",
        )

        # Pellete Flash Timer
        game.create_timer(
            timer_id=power_pellete_flash_timer_id,
            time=0.2,
            loops=True,
            start_on_creation=True,
        )
        game.subscribe_to_signal(
            source_id=power_pellete_flash_timer_id,
            signal_id="timeout",
            subscriber_entity_id=self.entity_id,
            function_name="_on_power_pellete_flash_timer_timeout",
        )

        # Pacman Lose Life Start Timer
        game.create_timer(
            timer_id=self.pacman_lose_life_start_timer_id,
            time=1.0,
            loops=False,
            start_on_creation=False,
        )
        game.subscribe_to_signal(
            source_id=self.pacman_lose_life_start_timer_id,
            signal_id="timeout",
            subscriber_entity_id=self.entity_id,
            function_name="_on_pacman_lose_life_start_timer_timeout",
        )

        # 1UP Flash Timer
        one_up_flash_timer_id = "one_up_flash_timer"
        game.create_timer(timer_id=one_up_flash_timer_id,
                          time=0.4,
                          loops=True,
                          start_on_creation=True)
        game.subscribe_to_signal(
            source_id=one_up_flash_timer_id,
            signal_id="timeout",
            subscriber_entity_id=self.entity_id,
            function_name="_on_one_up_flash_timer_timeout",
        )

        # Ghost Frightened Timer
        game.create_timer(
            timer_id=self.ghost_frightened_timer_id,
            time=7.0,
            loops=False,
            start_on_creation=False,
        )
        game.subscribe_to_signal(
            source_id=self.ghost_frightened_timer_id,
            signal_id="timeout",
            subscriber_entity_id=self.entity_id,
            function_name="_on_ghost_frightened_timer_timeout",
        )

        # Show Entities Timer
        game.create_timer(
            timer_id=self.show_entities_timer_id,
            time=2.0,
            loops=False,
            start_on_creation=False,
        )
        game.subscribe_to_signal(
            source_id=self.show_entities_timer_id,
            signal_id="timeout",
            subscriber_entity_id=self.entity_id,
            function_name="_on_show_entities_timer_timeout",
        )

        # Lose Life Signal
        pacman_entity = scene_tree.get_entity("pacman")
        game.subscribe_to_signal(
            source_id=pacman_entity.entity_id,
            signal_id="lose_life",
            subscriber_entity_id=self.entity_id,
            function_name="_on_pacman_lose_life",
        )
        # Power Pellet
        game.subscribe_to_signal(
            source_id=pacman_entity.entity_id,
            signal_id="power_pellete_eaten",
            subscriber_entity_id=self.entity_id,
            function_name="_on_pacman_power_pellete_eaten",
        )
        # Level Cleared Signal
        game.subscribe_to_signal(
            source_id=pacman_entity.entity_id,
            signal_id="level_cleared",
            subscriber_entity_id=self.entity_id,
            function_name="_on_pacman_level_cleared",
        )

        self.create_level_pellets()

        self.set_all_entities_visibility(False)

        self.reset_entity_positions()

        global_obj.player_stats.force_update_ui()

        if global_obj.game_state == GameState.BEGIN_GAME:
            global_obj.player_stats.force_update_ui()
            global_obj.game_state = GameState.PLAYING
            game.start_timer(timer_id=self.start_timer_id, time=4.2)
            game.start_timer(timer_id=self.show_entities_timer_id, time=2.0)
            game.play_sound(sound_id="pacman-begin")
            global_obj.player_stats.pelletes = 0
        elif global_obj.game_state == GameState.LEVEL_COMPLETE:
            global_obj.player_stats.level += 1
            global_obj.player_stats.force_update_ui()
            global_obj.game_state = GameState.PLAYING
            game.start_timer(timer_id=self.start_timer_id, time=1.0)
            self._on_show_entities_timer_timeout()
            global_obj.player_stats.pelletes = 0
Пример #9
0
    def __process__(self, delta_time):
        if global_obj.game_started and not global_obj.game_paused:
            collided_entity_id, collider_tag = game.check_entity_collision(
                entity_id=self.entity_id, offset_position=(0, 0))
            if collided_entity_id:
                if collider_tag == "pellete":
                    game.delete_entity(entity_id=collided_entity_id)
                    global_obj.player_stats.score += 10
                    global_obj.player_stats.pelletes += 1
                    self.pellete_counter -= 1
                    game.play_sound(sound_id="pacman-chomp")
                elif collider_tag == "power_pellete":
                    game.delete_entity(entity_id=collided_entity_id)
                    global_obj.player_stats.score += 50
                    global_obj.player_stats.pelletes += 1
                    self.pellete_counter -= 1
                    self.ghost_eaten_score = 0
                    game.emit_signal(
                        entity_id=self.entity_id,
                        signal_id=self.power_pellete_eaten_signal_id,
                    )
                elif collider_tag == "enemy":
                    collided_ghost = scene_tree.get_entity(collided_entity_id)
                    if collided_ghost.state == State.FRIGHTENED:
                        if self.ghost_eaten_score == 0:
                            self.ghost_eaten_score = 200
                        else:
                            self.ghost_eaten_score *= 2
                        global_obj.player_stats.score += self.ghost_eaten_score
                        collided_ghost.eaten(self.ghost_eaten_score)
                        game.start_timer(timer_id=self.eaten_freeze_timer_id)
                        global_obj.game_paused = True
                        game.play_sound(sound_id="pacman-eat-ghost")
                    elif (collided_ghost.state == State.CHASE
                          or collided_ghost.state == State.SCATTER):
                        game.stop_animation(entity_id=self.entity_id)
                        game.emit_signal(entity_id=self.entity_id,
                                         signal_id=self.lose_life_signal_id)
                elif collider_tag == "fruit":
                    fruit_entity = scene_tree.get_entity(collided_entity_id)
                    if not fruit_entity.collected:
                        global_obj.player_stats.score += global_obj.player_stats.get_fruit_score(
                            collided_entity_id)
                        fruit_entity.eaten()

            # Input - determines direction pacman wants to turn
            if game.is_action_pressed(action="left"):
                self.direction_to_turn = Direction.left
            elif game.is_action_pressed(action="right"):
                self.direction_to_turn = Direction.right
            elif game.is_action_pressed(action="up"):
                self.direction_to_turn = Direction.up
            elif game.is_action_pressed(action="down"):
                self.direction_to_turn = Direction.down

            # Determine speed
            if game.has_timer_stopped(timer_id=self.turn_speed_up_timer_id):
                self.speed = 100
            else:
                self.speed = 150
            self.accumulated_delta += delta_time * self.speed
            while self.accumulated_delta >= 1.0:
                self.accumulated_delta -= 1.0
                self.move(self.velocity, 1.0)

            self.update_animations()

            # Play movement sound
            if abs(self.velocity.x) > 0 or abs(self.velocity.y) > 0:
                if game.has_timer_stopped(timer_id=self.chomp_timer_id):
                    pass
                    # game.start_timer(timer_id=self.chomp_timer_id)
            else:
                self.accumulated_delta = 0.0
        elif (global_obj.game_paused
              and global_obj.game_state == GameState.PACMAN_LOSE_LIFE):
            pass
        else:
            game.stop_animation(entity_id=self.entity_id)

        if game.is_action_just_pressed(action="exit_game"):
            game.quit()
Пример #10
0
    def process_coins(self, coins):
        hit_list = pygame.sprite.spritecollide(self, coins, True)

        for coin in hit_list:
            game.play_sound(game.COIN_SOUND)
            self.score += coin.value
Пример #11
0
    def check_flag(self, level):
        hit_list = pygame.sprite.spritecollide(self, level.flag, False)

        if len(hit_list) > 0:
            level.completed = True
            game.play_sound(game.LEVELUP_SOUND)
Пример #12
0
    def process_powerups(self, powerups):
        hit_list = pygame.sprite.spritecollide(self, powerups, True)

        for p in hit_list:
            game.play_sound(game.POWERUP_SOUND)
            p.apply(self)
Пример #13
0
 def eaten(self):
     game.play_animation(entity_id=self.entity_id, animation_name="score")
     game.stop_timer(timer_id=self.life_timer_id)
     game.start_timer(timer_id=self.life_timer_id, time=1.0)
     self.collected = True
     game.play_sound(sound_id="pacman-eat-fruit")