passable doors and stuff
This commit is contained in:
parent
1e731f5a80
commit
6cd571476f
1 changed files with 13 additions and 8 deletions
|
|
@ -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]
|
||||
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))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue