Co-authored-by: staubsauger <staubsauger@users.noreply.github.com>

This commit is contained in:
Lukas Nöllemeyer 2024-08-16 23:20:24 +02:00
parent fe5d2bb24e
commit a4981d1575
3 changed files with 16 additions and 8 deletions

View file

@ -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))