Skip to content

Commit

Permalink
Open adjacent doors with mouse.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julioevm committed Feb 1, 2024
1 parent 77e8716 commit 60e1060
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
13 changes: 13 additions & 0 deletions components/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import List, Optional, Tuple, TYPE_CHECKING
import actor_factories
import color
import tile_types
import numpy as np # type: ignore
import tcod
from actions import (
Expand All @@ -12,6 +13,7 @@
EnergyAction,
MeleeAction,
MovementAction,
OpenDoorAction,
PickupAction,
PounceAction,
RangedAttackAction,
Expand Down Expand Up @@ -149,6 +151,17 @@ def get_action(self) -> Optional[Action]:
# Restore the AI if we see an enemy to avoid dying.
self.entity.restore_ai()

# Open the door action if the tile you have to move to is a door

if (
self.engine.game_map.tiles[self.dest_x, self.dest_y]
in tile_types.door_tiles
and distance <= 1
):
print(f"Opening door at {self.dest_x}, {self.dest_y}.")
self.entity.restore_ai()
return OpenDoorAction(self.entity, self.dest_x, self.dest_y)

actor = self.engine.game_map.get_actor_at_location(self.dest_x, self.dest_y)
if distance <= 1 and actor and actor is not self.entity:
return MeleeAction(self.entity, dx, dy)
Expand Down
7 changes: 6 additions & 1 deletion event_handlers/main_game_event_handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from __future__ import annotations
from typing import Optional, TYPE_CHECKING


import tile_types
import tcod.event
import color
import actions
Expand Down Expand Up @@ -35,7 +37,10 @@ def ev_mousebuttondown(
self.engine.game_map.in_bounds(event.tile.x, event.tile.y)
and game_map.explored[event.tile.x, event.tile.y]
):
if game_map.tiles["walkable"][event.tile.x, event.tile.y]:
if (
game_map.tiles["walkable"][event.tile.x, event.tile.y]
or game_map.tiles[event.tile.x, event.tile.y] in tile_types.door_tiles
):
return MoveToTileAction(self.engine.player, event.tile.x, event.tile.y)

return action
Expand Down

0 comments on commit 60e1060

Please sign in to comment.