center player and stuff
This commit is contained in:
parent
6cd571476f
commit
36d6b63c31
4 changed files with 21 additions and 5 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue