def determine_target_tile(self): # TODO: Implement override for scatter if self.state == State.SCATTER: return (self.home_tile.x, self.home_tile.y) elif self.state == State.CHASE: pacman_entity = scene_tree.get_entity("pacman") return global_obj.level_grid.convert_position_to_grid( pacman_entity.position.x, pacman_entity.position.y) else: return super().determine_target_tile()
def determine_target_tile(self): if self.state == State.CHASE: ( grid_position_x, grid_position_y, ) = global_obj.level_grid.convert_position_to_grid( self.position.x, self.position.y) # Get pacman grid position pacman_entity = scene_tree.get_entity("pacman") ( pacman_grid_position_x, pacman_grid_position_y, ) = global_obj.level_grid.convert_position_to_grid( pacman_entity.position.x, pacman_entity.position.y) if pacman_entity.direction == Direction.left: pacman_grid_position_x -= 2 elif pacman_entity.direction == Direction.right: pacman_grid_position_x += 2 if pacman_entity.direction == Direction.up: pacman_grid_position_y -= 2 elif pacman_entity.direction == Direction.down: pacman_grid_position_y += 2 # Get blinky grid position blinky_entity = scene_tree.get_entity("blinky") ( blinky_grid_position_x, blinky_grid_position_y, ) = global_obj.level_grid.convert_position_to_grid( blinky_entity.position.x, blinky_entity.position.y) return ( grid_position_x + (pacman_grid_position_x - blinky_grid_position_x) * 2, grid_position_y + (pacman_grid_position_y - blinky_grid_position_y) * 2, ) else: return super().determine_target_tile()
def determine_target_tile(self): if self.state == State.CHASE: grid_position = global_obj.level_grid.convert_position_to_grid( self.position.x, self.position.y ) pacman_entity = scene_tree.get_entity("pacman") pacman_grid_position = global_obj.level_grid.convert_position_to_grid( pacman_entity.position.x, pacman_entity.position.y ) if Vector2.distance(grid_position, pacman_grid_position) > 8: return pacman_grid_position else: return (self.home_tile.x, self.home_tile.y) else: return super().determine_target_tile()
def determine_target_tile(self): if self.state == State.CHASE: pacman_entity = scene_tree.get_entity("pacman") ( pacman_grid_position_x, pacman_grid_position_y, ) = global_obj.level_grid.convert_position_to_grid( pacman_entity.position.x, pacman_entity.position.y) if pacman_entity.direction == Direction.left: pacman_grid_position_x -= 4 elif pacman_entity.direction == Direction.right: pacman_grid_position_x += 4 if pacman_entity.direction == Direction.up: pacman_grid_position_y -= 4 elif pacman_entity.direction == Direction.down: pacman_grid_position_y += 4 return (pacman_grid_position_x, pacman_grid_position_y) else: return super().determine_target_tile()
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()