diff --git a/g.py b/g.py index 8f18308..52bf2ab 100644 --- a/g.py +++ b/g.py @@ -7,6 +7,7 @@ import tcod.context import tcod.ecs import game.state +from game.components import Position context: tcod.context.Context """The window managed by tcod.""" @@ -17,7 +18,7 @@ world: tcod.ecs.Registry world_map: tcod.map.Map """Wall Map of current World""" -world_center: tuple[int,int] = (50, 50) +world_center: tuple[int,int] = Position(50, 50) states: list[game.state.State] = [] """A stack of states with the last item being the active state.""" diff --git a/game/states.py b/game/states.py index 50dc67b..181a13c 100644 --- a/game/states.py +++ b/game/states.py @@ -15,7 +15,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, IsActor +from game.tags import IsItem, IsPlayer, IsDoor, IsActor from game.constants import WALL_CHAR @attrs.define() @@ -34,7 +34,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 not g.world_map.walkable[g.world_center[1]+new_pos.y][g.world_center[0]+new_pos.x]: + if not g.world_map.walkable[g.world_center.y+new_pos.y][g.world_center.x+new_pos.x]: return None player.components[Position] = new_pos # Auto pickup gold diff --git a/game/tags.py b/game/tags.py index 954fb52..bfbbe7c 100644 --- a/game/tags.py +++ b/game/tags.py @@ -13,8 +13,5 @@ IsActor: Final = "IsActor" IsItem: Final = "IsItem" """Entity is an item.""" -IsWall: Final = "IsWall" -"""Entity is a wall.""" - IsDoor: Final = "IsDoor" """Entiy is a door.""" diff --git a/game/world_tools.py b/game/world_tools.py index 6eb0df1..65b93c7 100644 --- a/game/world_tools.py +++ b/game/world_tools.py @@ -10,17 +10,18 @@ from tcod.ecs import Registry, Entity from tcod.map import Map from game.components import Gold, Graphic, Position -from game.tags import IsActor, IsItem, IsPlayer, IsWall, IsDoor +from game.tags import IsActor, IsItem, IsPlayer, IsDoor -def add_wall(x, y, remove=False): - g.world_map.walkable[50+y][50+x] = remove +def add_wall(pos, remove=False): + r_pos = g.world_center + pos + g.world_map.walkable[r_pos.y][r_pos.x] = remove -def add_door(x, y): +def add_door(pos): door = g.world[object()] door.tags.add(IsDoor) - door.components[Position] = Position(x,y) + door.components[Position] = pos door.components[Graphic] = Graphic(ord("\\")) - add_wall(x,y) + add_wall(pos) def new_world() -> Registry: @@ -46,9 +47,9 @@ def new_world() -> Registry: for i in range(20): if i == 5 or i == 9: - add_door(10,i) + add_door(Position(10,i)) else: - add_wall(10, i) + add_wall(Position(10, i)) return world @@ -57,4 +58,4 @@ def unlock_door(door: Entity): door.components[Graphic] = Graphic(ord("_")) door.tags.clear() pos = door.components[Position] - add_wall(pos.x,pos.y, remove=True) + add_wall(pos, remove=True)