made door actionable
This commit is contained in:
parent
6a5e5d3137
commit
0d9de5b208
4 changed files with 13 additions and 14 deletions
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Final, Self
|
from typing import Final, Self, Callable
|
||||||
|
|
||||||
import attrs
|
import attrs
|
||||||
import math
|
import math
|
||||||
|
|
@ -65,6 +65,8 @@ class Graphic:
|
||||||
ch: int = ord("!")
|
ch: int = ord("!")
|
||||||
fg: tuple[int, int, int] = (255, 255, 255)
|
fg: tuple[int, int, int] = (255, 255, 255)
|
||||||
|
|
||||||
|
Action: Final = ("Action", Callable[[tcod.ecs.Entity], None])
|
||||||
|
"""Possible action."""
|
||||||
|
|
||||||
Gold: Final = ("Gold", int)
|
Gold: Final = ("Gold", int)
|
||||||
"""Amount of gold."""
|
"""Amount of gold."""
|
||||||
|
|
|
||||||
|
|
@ -10,10 +10,10 @@ from tcod.event import KeySym
|
||||||
from tcod.map import Map
|
from tcod.map import Map
|
||||||
|
|
||||||
import g
|
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.constants import DIRECTION_KEYS, ACTION_KEYS
|
||||||
from game.screens import Push, Screen, ScreenResult
|
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.constants import WALL_CHAR
|
||||||
from game.screens import menu_screens
|
from game.screens import menu_screens
|
||||||
from game.world_tools import world_pos_to_map_pos, map_pos_to_world_pos
|
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]
|
map: Map = g.world[None].components[Map]
|
||||||
match event:
|
match event:
|
||||||
case tcod.event.KeyDown(sym=sym) if sym in ACTION_KEYS:
|
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]
|
player_pos = player.components[Position]
|
||||||
if (player_pos - door.components[Position]).length() < 2:
|
if (player_pos - entity.components[Position]).length() < 2:
|
||||||
ACTION_KEYS[sym](door)
|
entity.components[Action](entity)
|
||||||
cam_map = world_pos_to_map_pos(player_pos)
|
cam_map = world_pos_to_map_pos(player_pos)
|
||||||
map.compute_fov(cam_map.x, cam_map.y, 100)
|
map.compute_fov(cam_map.x, cam_map.y, 100)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,3 @@ IsActor: Final = "IsActor"
|
||||||
|
|
||||||
IsItem: Final = "IsItem"
|
IsItem: Final = "IsItem"
|
||||||
"""Entity is an item."""
|
"""Entity is an item."""
|
||||||
|
|
||||||
IsDoor: Final = "IsDoor"
|
|
||||||
"""Entiy is a door."""
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@ from tcod.map import Map
|
||||||
|
|
||||||
import g
|
import g
|
||||||
|
|
||||||
from game.components import Gold, Graphic, Position
|
from game.components import Action, Gold, Graphic, Position
|
||||||
from game.tags import IsActor, IsItem, IsPlayer, IsDoor
|
from game.tags import IsActor, IsItem, IsPlayer
|
||||||
|
|
||||||
world_center: Final = Position(50, 50)
|
world_center: Final = Position(50, 50)
|
||||||
|
|
||||||
|
|
@ -30,9 +30,9 @@ def add_door(world, pos):
|
||||||
world.new_entity(
|
world.new_entity(
|
||||||
components={
|
components={
|
||||||
Position: pos,
|
Position: pos,
|
||||||
Graphic: Graphic(ord('\\'))
|
Graphic: Graphic(ord('\\')),
|
||||||
},
|
Action: unlock_door
|
||||||
tags=[IsDoor]
|
}
|
||||||
)
|
)
|
||||||
add_wall(world, pos)
|
add_wall(world, pos)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue