fixed pause menu and made world_map a component of world

This commit is contained in:
Lukas Nöllemeyer 2024-08-17 11:29:39 +02:00
parent bfabba3d82
commit 45e7a8927a
3 changed files with 41 additions and 25 deletions

View file

@ -7,6 +7,7 @@ import tcod.console
import tcod.constants
import tcod.event
from tcod.event import KeySym
from tcod.map import Map
import g
from game.components import Gold, Graphic, Position
@ -33,7 +34,7 @@ class MainScreen(Screen):
raise SystemExit()
case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS:
new_pos = player.components[Position] + DIRECTION_KEYS[sym]
if not g.world_map.walkable[g.world_center.y+new_pos.y][g.world_center.x+new_pos.x]:
if not g.world[None].components[Map].walkable[g.world_center.y+new_pos.y][g.world_center.x+new_pos.x]:
return None
player.components[Position] = new_pos
# Auto pickup gold
@ -44,7 +45,7 @@ class MainScreen(Screen):
gold.clear()
return None
case tcod.event.KeyDown(sym=KeySym.ESCAPE):
return Push(menu_screens())
return Push(menu_screens.MainMenu())
case _:
return None
@ -61,7 +62,7 @@ class MainScreen(Screen):
and -h <= screen_pos.y < h):
graphic = e_graph
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 (y, row) in enumerate(g.world[None].components[Map].walkable):
for (x, val) in enumerate(row):
if not val:
draw(Position(x,y)-g.world_center, Graphic(WALL_CHAR))