First steps

This commit is contained in:
staubsauger 2024-08-16 19:58:37 +02:00
parent 81190c687e
commit 1e731f5a80
191 changed files with 65 additions and 7 deletions

View file

@ -12,9 +12,9 @@ import g
import game.menus
import game.world_tools
from game.components import Gold, Graphic, Position
from game.constants import DIRECTION_KEYS
from game.constants import DIRECTION_KEYS, ACTION_KEYS
from game.state import Push, Reset, State, StateResult
from game.tags import IsItem, IsPlayer
from game.tags import IsItem, IsPlayer, IsWall, IsDoor
@attrs.define()
@ -25,10 +25,17 @@ class InGame(State):
"""Handle events for the in-game state."""
(player,) = g.world.Q.all_of(tags=[IsPlayer])
match event:
case tcod.event.KeyDown(sym=sym) if sym in ACTION_KEYS:
for door in g.world.Q.all_of(tags=[IsDoor]):
if (player.components[Position] - door.components[Position]).length() < 2:
ACTION_KEYS[sym](door)
case tcod.event.Quit():
raise SystemExit()
case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS:
player.components[Position] += DIRECTION_KEYS[sym]
new_pos = player.components[Position] + DIRECTION_KEYS[sym]
if g.world.Q.all_of(tags=[new_pos, IsWall]):
return None
player.components[Position] = new_pos
# Auto pickup gold
for gold in g.world.Q.all_of(components=[Gold], tags=[player.components[Position], IsItem]):
player.components[Gold] += gold.components[Gold]