made door actionable

This commit is contained in:
Lukas Nöllemeyer 2024-08-17 14:47:34 +02:00
parent 6a5e5d3137
commit 0d9de5b208
4 changed files with 13 additions and 14 deletions

View file

@ -10,10 +10,10 @@ from tcod.event import KeySym
from tcod.map import Map
import g
from game.components import Gold, Graphic, Position
from game.components import Action, Gold, Graphic, Position
from game.constants import DIRECTION_KEYS, ACTION_KEYS
from game.screens import Push, Screen, ScreenResult
from game.tags import IsItem, IsPlayer, IsDoor, IsActor
from game.tags import IsItem, IsPlayer, IsActor
from game.constants import WALL_CHAR
from game.screens import menu_screens
from game.world_tools import world_pos_to_map_pos, map_pos_to_world_pos
@ -28,10 +28,10 @@ class MainScreen(Screen):
map: Map = g.world[None].components[Map]
match event:
case tcod.event.KeyDown(sym=sym) if sym in ACTION_KEYS:
for door in g.world.Q.all_of(tags=[IsDoor]):
for entity in g.world.Q.all_of(components=[Action, Position]):
player_pos = player.components[Position]
if (player_pos - door.components[Position]).length() < 2:
ACTION_KEYS[sym](door)
if (player_pos - entity.components[Position]).length() < 2:
entity.components[Action](entity)
cam_map = world_pos_to_map_pos(player_pos)
map.compute_fov(cam_map.x, cam_map.y, 100)