passable doors and stuff

This commit is contained in:
staubsauger 2024-08-16 20:28:51 +02:00
parent 1e731f5a80
commit 6cd571476f

View file

@ -14,7 +14,7 @@ import game.world_tools
from game.components import Gold, Graphic, Position from game.components import Gold, Graphic, Position
from game.constants import DIRECTION_KEYS, ACTION_KEYS from game.constants import DIRECTION_KEYS, ACTION_KEYS
from game.state import Push, Reset, State, StateResult from game.state import Push, Reset, State, StateResult
from game.tags import IsItem, IsPlayer, IsWall, IsDoor from game.tags import IsItem, IsPlayer, IsWall, IsDoor, IsActor
@attrs.define() @attrs.define()
@ -33,7 +33,7 @@ class InGame(State):
raise SystemExit() raise SystemExit()
case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS: case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS:
new_pos = player.components[Position] + DIRECTION_KEYS[sym] new_pos = player.components[Position] + DIRECTION_KEYS[sym]
if g.world.Q.all_of(tags=[new_pos, IsWall]): if g.world.Q.all_of(tags=[new_pos, IsWall]) or g.world.Q.all_of(tags=[new_pos, IsDoor]):
return None return None
player.components[Position] = new_pos player.components[Position] = new_pos
# Auto pickup gold # Auto pickup gold
@ -50,13 +50,18 @@ class InGame(State):
def on_draw(self, console: tcod.console.Console) -> None: def on_draw(self, console: tcod.console.Console) -> None:
"""Draw the standard screen.""" """Draw the standard screen."""
for entity in g.world.Q.all_of(components=[Position, Graphic]): def draw(e):
pos = entity.components[Position] pos = e.components[Position]
if not (0 <= pos.x < console.width and 0 <= pos.y < console.height): if (0 <= pos.x < console.width and 0 <= pos.y < console.height):
continue graphic = e.components[Graphic]
graphic = entity.components[Graphic] console.rgb[["ch", "fg"]][pos.y, pos.x] = graphic.ch, graphic.fg
console.rgb[["ch", "fg"]][pos.y, pos.x] = graphic.ch, graphic.fg
for entity in g.world.Q.all_of(components=[Position, Graphic]).none_of(tags=[IsActor]):
draw(entity)
for actor in g.world.Q.all_of(components=[Position, Graphic], tags=[IsActor]).none_of(tags=[IsPlayer]):
draw(actor)
for player in g.world.Q.all_of(tags=[IsPlayer]):
draw(player)
if text := g.world[None].components.get(("Text", str)): if text := g.world[None].components.get(("Text", str)):
console.print(x=0, y=console.height - 1, string=text, fg=(255, 255, 255), bg=(0, 0, 0)) console.print(x=0, y=console.height - 1, string=text, fg=(255, 255, 255), bg=(0, 0, 0))