fixed pause menu and made world_map a component of world
This commit is contained in:
parent
bfabba3d82
commit
45e7a8927a
3 changed files with 41 additions and 25 deletions
3
g.py
3
g.py
|
|
@ -15,9 +15,6 @@ context: tcod.context.Context
|
|||
world: tcod.ecs.Registry
|
||||
"""The active ECS registry and current session."""
|
||||
|
||||
world_map: tcod.map.Map
|
||||
"""Wall Map of current World"""
|
||||
|
||||
world_center: tuple[int,int] = Position(50, 50)
|
||||
|
||||
screens: list[Screen] = []
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -14,13 +14,18 @@ from game.tags import IsActor, IsItem, IsPlayer, IsDoor
|
|||
|
||||
def add_wall(pos, remove=False):
|
||||
r_pos = g.world_center + pos
|
||||
g.world_map.walkable[r_pos.y][r_pos.x] = remove
|
||||
map = g.world[None].components[Map]
|
||||
map.walkable[r_pos.y][r_pos.x] = remove
|
||||
map.transparent[r_pos.y][r_pos.x] = remove
|
||||
|
||||
def add_door(pos):
|
||||
door = g.world[object()]
|
||||
door.tags.add(IsDoor)
|
||||
door.components[Position] = pos
|
||||
door.components[Graphic] = Graphic(ord("\\"))
|
||||
g.world.new_entity(
|
||||
components={
|
||||
Position: pos,
|
||||
Graphic: Graphic(ord('\\'))
|
||||
},
|
||||
tags=[IsDoor]
|
||||
)
|
||||
add_wall(pos)
|
||||
|
||||
|
||||
|
|
@ -28,22 +33,36 @@ def new_world() -> Registry:
|
|||
"""Return a freshly generated world."""
|
||||
world = Registry()
|
||||
g.world = world
|
||||
g.world_map = Map(100, 100)
|
||||
g.world_map.walkable[:] = True
|
||||
|
||||
map = world[None].components[Map] = Map(100, 100)
|
||||
map.walkable[:] = True
|
||||
map.transparent[:] = True
|
||||
|
||||
rng = world[None].components[Random] = Random()
|
||||
|
||||
player = world[object()]
|
||||
player.components[Position] = Position(5, 5)
|
||||
player.components[Graphic] = Graphic(ord("@"))
|
||||
player.components[Gold] = 0
|
||||
player.tags |= {IsPlayer, IsActor}
|
||||
world.new_entity(
|
||||
components={
|
||||
Position: Position(5,5),
|
||||
Graphic: Graphic(ord('@')),
|
||||
Gold: 0
|
||||
},
|
||||
tags=[IsActor, IsPlayer]
|
||||
)
|
||||
# player = world[object()] # <- das hier ist das gleiche wie das world.new_entity darüber
|
||||
# player.components[Position] = Position(5, 5)
|
||||
# player.components[Graphic] = Graphic(ord("@"))
|
||||
# player.components[Gold] = 0
|
||||
# player.tags |= {IsPlayer, IsActor}
|
||||
|
||||
for _ in range(10):
|
||||
gold = world[object()]
|
||||
gold.components[Position] = Position(rng.randint(0, 20), rng.randint(0, 20))
|
||||
gold.components[Graphic] = Graphic(ord("$"), fg=(255, 255, 0))
|
||||
gold.components[Gold] = rng.randint(1, 10)
|
||||
gold.tags |= {IsItem}
|
||||
world.new_entity(
|
||||
components={
|
||||
Position: Position(rng.randint(0, 20), rng.randint(0, 20)),
|
||||
Graphic: Graphic(ord("$"), fg=(255, 255, 0)),
|
||||
Gold: rng.randint(1, 10)
|
||||
},
|
||||
tags=[IsItem]
|
||||
)
|
||||
|
||||
for i in range(20):
|
||||
if i == 5 or i == 9:
|
||||
|
|
@ -57,5 +76,4 @@ def new_world() -> Registry:
|
|||
def unlock_door(door: Entity):
|
||||
door.components[Graphic] = Graphic(ord("_"))
|
||||
door.tags.clear()
|
||||
pos = door.components[Position]
|
||||
add_wall(pos, remove=True)
|
||||
add_wall(door.components[Position], remove=True)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue