center player and stuff

This commit is contained in:
staubsauger 2024-08-16 22:25:11 +02:00
parent 6cd571476f
commit 36d6b63c31
4 changed files with 21 additions and 5 deletions

View file

@ -1,6 +1,7 @@
"""A collection of game states."""
from __future__ import annotations
from functools import reduce
import attrs
import tcod.console
@ -50,9 +51,15 @@ 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 = list(map(lambda a: a.components[Position], centers))
center = reduce(lambda a,b: a.components[Position]+b.components[Position], centers)
center.mod(len(centers))
def draw(e):
pos = e.components[Position]
if (0 <= pos.x < console.width and 0 <= pos.y < console.height):
pos = e.components[Position] - center
if (-console.width//2 <= pos.x < console.width//2\
and -console.height//2 <= pos.y < console.height//2):
graphic = e.components[Graphic]
console.rgb[["ch", "fg"]][pos.y, pos.x] = graphic.ch, graphic.fg