diff --git a/g.py b/g.py index 66440ab..950ef81 100644 --- a/g.py +++ b/g.py @@ -14,6 +14,9 @@ context: tcod.context.Context world: tcod.ecs.Registry """The active ECS registry and current session.""" +world_map: tcod.map.Map +"""Wall Map of current World""" + 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 107d464..1df3274 100644 --- a/game/states.py +++ b/game/states.py @@ -16,7 +16,7 @@ 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.constants import WALL_CHAR @attrs.define() class InGame(State): @@ -56,19 +56,22 @@ class InGame(State): center = sum(centers, start=Position(0,0)) center = center.mod(len(centers)) - def draw(e): - pos = e.components[Position] - center + def draw(e_pos, e_graph): + pos = e_pos - center if (-console.width//2 <= pos.x < console.width//2\ and -console.height//2 <= pos.y < console.height//2): - graphic = e.components[Graphic] + graphic = e_graph console.rgb[["ch", "fg"]][pos.y + console.height//2, pos.x + console.width//2] = graphic.ch, graphic.fg - + for (y, row) in enumerate(g.world_map.walkable): + for (x, val) in enumerate(row): + if val: + draw(Position(x,y), Graphic(WALL_CHAR)) for entity in g.world.Q.all_of(components=[Position, Graphic]).none_of(tags=[IsActor]): - draw(entity) + draw(entity.components[Position], entity.components[Graphic]) for actor in g.world.Q.all_of(components=[Position, Graphic], tags=[IsActor]).none_of(tags=[IsPlayer]): - draw(actor) + draw(actor.components[Position], entity.components[Graphic]) for player in g.world.Q.all_of(tags=[IsPlayer]): - draw(player) + draw(player.components[Position], player.components[Graphic]) 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)) diff --git a/game/world_tools.py b/game/world_tools.py index 7ef2605..c32c6da 100644 --- a/game/world_tools.py +++ b/game/world_tools.py @@ -7,6 +7,7 @@ from random import Random import g 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 @@ -15,6 +16,7 @@ from game.tags import IsActor, IsItem, IsPlayer, IsWall, IsDoor def new_world() -> Registry: """Return a freshly generated world.""" world = Registry() + g.world_map = Map(100, 100) rng = world[None].components[Random] = Random() player = world[object()]