Ejemplo n.º 1
0
 def update_animations(self):
     # Update animations
     if self.state == State.FRIGHTENED:
         if self.frightened_flash:
             game.play_animation(
                 entity_id=self.entity_id, animation_name="frightened_flash"
             )
         else:
             game.play_animation(
                 entity_id=self.entity_id, animation_name="frightened"
             )
     else:
         animation_prefix = ""
         if self.state == State.DEFEATED_TRAVELING_TO_HOUSE or self.state == State.DEFEATED_ENTERING_HOUSE:
             animation_prefix = "blank_"
         if self.velocity.y > 0:
             game.play_animation(
                 entity_id=self.entity_id, animation_name=f"{animation_prefix}down"
             )
         elif self.velocity.y < 0:
             game.play_animation(
                 entity_id=self.entity_id, animation_name=f"{animation_prefix}up"
             )
         elif self.velocity.x > 0:
             game.play_animation(
                 entity_id=self.entity_id, animation_name=f"{animation_prefix}right"
             )
         elif self.velocity.x < 0:
             game.play_animation(
                 entity_id=self.entity_id, animation_name=f"{animation_prefix}left"
             )
         else:
             game.stop_animation(entity_id=self.entity_id)
Ejemplo n.º 2
0
 def update_animations(self):
     # Update animations
     if self.velocity.y > 0:
         game.play_animation(entity_id=self.entity_id,
                             animation_name="down")
     elif self.velocity.y < 0:
         game.play_animation(entity_id=self.entity_id, animation_name="up")
     elif self.velocity.x > 0:
         game.play_animation(entity_id=self.entity_id,
                             animation_name="right")
     elif self.velocity.x < 0:
         game.play_animation(entity_id=self.entity_id,
                             animation_name="left")
     else:
         game.stop_animation(entity_id=self.entity_id)
         if not self.on_stop_animation_frame:
             game.set_animation_frame(entity_id=self.entity_id, frame=1)
             self.on_stop_animation_frame = True
Ejemplo n.º 3
0
    def __process__(self, delta_time):
        if global_obj.game_started and not global_obj.game_paused:

            # Determine speed
            grid_space_x, grid_space_y = self.get_level_grid_position(
                self.position.x, self.position.y
            )
            if global_obj.level_grid.has_ghost_slow_down_space(
                grid_space_x, grid_space_y
            ):
                self.speed = self.MIDDLE_SPEED
            else:
                self.speed = self.NORMAL_SPEED

            self.accumulated_delta += delta_time * self.speed
            if self.state == State.DEFEATED_TRAVELING_TO_HOUSE or self.state == State.DEFEATED_ENTERING_HOUSE:
                self.accumulated_delta *= 1.75
            move_speed = 1.0
            while self.accumulated_delta >= move_speed:
                self.accumulated_delta -= move_speed
                if self.state == State.IN_HOUSE:
                    self.in_house_move(move_speed)
                elif self.state == State.LEAVE_HOUSE:
                    self.leave_house_move(move_speed)
                elif self.state == State.FRIGHTENED:
                    self.frightened_move(move_speed)
                elif self.state == State.DEFEATED_ENTERING_HOUSE:
                    self.defeated_entering_house_move(move_speed)
                else:
                    self.move(move_speed)

            self.update_animations()

            if abs(self.velocity.x) == 0 and abs(self.velocity.y) == 0:
                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)
Ejemplo n.º 4
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()
Ejemplo n.º 5
0
 def _on_pacman_animation_finished(self):
     if (global_obj.game_paused
             and global_obj.game_state == GameState.PACMAN_LOSE_LIFE):
         game.stop_animation(entity_id=self.entity_id)
         game.set_entity_visibility(entity_id=self.entity_id, visible=False)