moved walls to static map object

This commit is contained in:
Lukas Nöllemeyer 2024-08-17 00:00:01 +02:00
parent a4981d1575
commit 9b85305481
3 changed files with 32 additions and 22 deletions

View file

@ -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 g.world.Q.all_of(tags=[new_pos, IsWall]) or g.world.Q.all_of(tags=[new_pos, IsDoor]):
if not g.world_map.walkable[g.world_center[1]+new_pos.y][g.world_center[0]+new_pos.x]:
return None
player.components[Position] = new_pos
# Auto pickup gold
@ -51,21 +51,21 @@ class InGame(State):
def on_draw(self, console: tcod.console.Console) -> None:
"""Draw the standard screen."""
centers = g.world.Q.all_of(tags=[IsPlayer])
centers = [a.components[Position] for a in centers]
center = sum(centers, start=Position(0,0))
center = center.mod(len(centers))
centers = [a.components[Position] for a in g.world.Q.all_of(tags=[IsPlayer])]
camera_pos = sum(centers, start=Position(0,0))
camera_pos = camera_pos.mod(len(centers))
h = console.height//2
w = console.width//2
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):
screen_pos = e_pos - camera_pos
if (-w <= screen_pos.x < w\
and -h <= screen_pos.y < h):
graphic = e_graph
console.rgb[["ch", "fg"]][pos.y + console.height//2, pos.x + console.width//2] = graphic.ch, graphic.fg
console.rgb[["ch", "fg"]][screen_pos.y + h, screen_pos.x + w] = 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))
if not val:
draw(Position(x,y)-g.world_center, Graphic(WALL_CHAR))
for entity in g.world.Q.all_of(components=[Position, Graphic]).none_of(tags=[IsActor]):
draw(entity.components[Position], entity.components[Graphic])
for actor in g.world.Q.all_of(components=[Position, Graphic], tags=[IsActor]).none_of(tags=[IsPlayer]):