From 6cd571476fb19fffe5376d3420ba79e842e89710 Mon Sep 17 00:00:00 2001 From: staubsauger Date: Fri, 16 Aug 2024 20:28:51 +0200 Subject: [PATCH] passable doors and stuff --- game/states.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/game/states.py b/game/states.py index d34544e..faea2f6 100644 --- a/game/states.py +++ b/game/states.py @@ -14,7 +14,7 @@ import game.world_tools from game.components import Gold, Graphic, Position from game.constants import DIRECTION_KEYS, ACTION_KEYS 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() @@ -33,7 +33,7 @@ class InGame(State): raise SystemExit() case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS: 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 player.components[Position] = new_pos # Auto pickup gold @@ -50,13 +50,18 @@ class InGame(State): def on_draw(self, console: tcod.console.Console) -> None: """Draw the standard screen.""" - for entity in g.world.Q.all_of(components=[Position, Graphic]): - pos = entity.components[Position] - if not (0 <= pos.x < console.width and 0 <= pos.y < console.height): - continue - graphic = entity.components[Graphic] - console.rgb[["ch", "fg"]][pos.y, pos.x] = graphic.ch, graphic.fg + def draw(e): + pos = e.components[Position] + if (0 <= pos.x < console.width and 0 <= pos.y < console.height): + graphic = e.components[Graphic] + 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)): console.print(x=0, y=console.height - 1, string=text, fg=(255, 255, 255), bg=(0, 0, 0))