def get_enemy_intersecting_with( self, entity: WorldEntity) -> List[NonPlayerCharacter]: return [ e for e in self.non_player_characters if e.is_enemy and boxes_intersect(e.world_entity.rect(), entity.rect()) ]
def get_projectiles_intersecting_with( self, entity: WorldEntity) -> List[Projectile]: return [ p for p in self.projectile_entities if boxes_intersect(entity.rect(), p.world_entity.rect()) ]
def handle_nearby_entities(self, player_entity: WorldEntity, game_state: GameState, game_engine: GameEngine): self.entity_to_interact_with = None player_position = player_entity.get_position() distance_to_closest_entity = sys.maxsize for npc in game_state.game_world.non_player_characters: if has_npc_dialog(npc.npc_type): close_to_player = is_x_and_y_within_distance( player_position, npc.world_entity.get_position(), 75) distance = get_manhattan_distance_between_rects( player_entity.rect(), npc.world_entity.rect()) if close_to_player and distance < distance_to_closest_entity: self.entity_to_interact_with = npc distance_to_closest_entity = distance lootables_on_ground: List[LootableOnGround] = list( game_state.game_world.items_on_ground) lootables_on_ground += game_state.game_world.consumables_on_ground for lootable in lootables_on_ground: if boxes_intersect(player_entity.rect(), lootable.world_entity.rect()): self.entity_to_interact_with = lootable distance_to_closest_entity = 0 for portal in game_state.game_world.portals: close_to_player = is_x_and_y_within_distance( player_position, portal.world_entity.get_position(), 75) distance = get_manhattan_distance_between_rects( player_entity.rect(), portal.world_entity.rect()) if close_to_player: game_engine.handle_being_close_to_portal(portal) if close_to_player and distance < distance_to_closest_entity: self.entity_to_interact_with = portal distance_to_closest_entity = distance for warp_point in game_state.game_world.warp_points: close_to_player = is_x_and_y_within_distance( player_position, warp_point.world_entity.get_position(), 75) distance = get_manhattan_distance_between_rects( player_entity.rect(), warp_point.world_entity.rect()) if close_to_player and distance < distance_to_closest_entity: self.entity_to_interact_with = warp_point distance_to_closest_entity = distance for chest in game_state.game_world.chests: close_to_player = is_x_and_y_within_distance( player_position, chest.world_entity.get_position(), 75) distance = get_manhattan_distance_between_rects( player_entity.rect(), chest.world_entity.rect()) if close_to_player and distance < distance_to_closest_entity: self.entity_to_interact_with = chest distance_to_closest_entity = distance for shrine in game_state.game_world.shrines: close_to_player = is_x_and_y_within_distance( player_position, shrine.world_entity.get_position(), 75) distance = get_manhattan_distance_between_rects( player_entity.rect(), shrine.world_entity.rect()) if close_to_player and distance < distance_to_closest_entity: self.entity_to_interact_with = shrine distance_to_closest_entity = distance for dungeon_entrance in game_state.game_world.dungeon_entrances: close_to_player = is_x_and_y_within_distance( player_position, dungeon_entrance.world_entity.get_position(), 60) distance = get_manhattan_distance_between_rects( player_entity.rect(), dungeon_entrance.world_entity.rect()) if close_to_player and distance < distance_to_closest_entity: self.entity_to_interact_with = dungeon_entrance distance_to_closest_entity = distance
def does_entity_intersect_with_wall(self, entity: WorldEntity): nearby_walls = self.get_walls_close_to_position(entity.get_position()) return any([ w for w in nearby_walls if boxes_intersect(w.rect(), entity.rect()) ])
def render_world(self, all_entities_to_render: List[WorldEntity], decorations_to_render: List[DecorationEntity], camera_world_area, non_player_characters: List[NonPlayerCharacter], is_player_invisible: bool, player_active_buffs: List[BuffWithDuration], player_entity: WorldEntity, visual_effects, render_hit_and_collision_boxes, player_health, player_max_health, entire_world_area: Rect, entity_action_text: Optional[EntityActionText]): self.camera_world_area = camera_world_area self.screen_render.fill(COLOR_BACKGROUND) self._world_ground(entire_world_area) all_entities_to_render.sort(key=lambda entry: (-entry.view_z, entry.y)) for decoration_entity in decorations_to_render: self._world_entity(decoration_entity) for entity in all_entities_to_render: self._world_entity(entity) if entity == player_entity and is_player_invisible: self.world_render.rect((200, 100, 250), player_entity.rect(), 2) player_sprite_y_relative_to_entity = \ ENTITY_SPRITE_INITIALIZERS[player_entity.sprite][Direction.DOWN].position_relative_to_entity[1] if player_entity.visible: self._stat_bar_for_world_entity( player_entity, 5, player_sprite_y_relative_to_entity - 5, player_health / player_max_health, (100, 200, 0)) # Buffs related to channeling something are rendered above player's head with progress from left to right for buff in player_active_buffs: if buff.buff_effect.get_buff_type() in CHANNELING_BUFFS: ratio = 1 - buff.get_ratio_duration_remaining() self._stat_bar_for_world_entity( player_entity, 3, player_sprite_y_relative_to_entity - 11, ratio, (150, 150, 250)) if render_hit_and_collision_boxes: for entity in all_entities_to_render: self.world_render.rect((250, 250, 250), entity.rect(), 1) for npc in non_player_characters: if npc.is_enemy: if npc.is_boss: healthbar_color = (255, 215, 0) border_color = COLOR_RED else: healthbar_color = COLOR_RED border_color = None else: healthbar_color = (250, 250, 0) border_color = None if npc.quest_giver_state is not None: self._quest_giver_mark(npc) npc_sprite_y_relative_to_entity = \ ENTITY_SPRITE_INITIALIZERS[npc.world_entity.sprite][Direction.DOWN].position_relative_to_entity[1] if not npc.is_neutral: self._stat_bar_for_world_entity( npc.world_entity, 3, npc_sprite_y_relative_to_entity - 5, npc.health_resource.get_partial(), healthbar_color, border_color) if npc.active_buffs: buff = npc.active_buffs[0] if buff.should_duration_be_visualized_on_enemies(): self._stat_bar_for_world_entity( npc.world_entity, 2, npc_sprite_y_relative_to_entity - 9, buff.get_ratio_duration_remaining(), (250, 250, 250)) for visual_effect in visual_effects: self._visual_effect(visual_effect) if entity_action_text: self._entity_action_text(entity_action_text)