moved walls to static map object

This commit is contained in:
Lukas Nöllemeyer 2024-08-17 00:00:01 +02:00
parent a4981d1575
commit 9b85305481
3 changed files with 32 additions and 22 deletions

View file

@ -12,11 +12,23 @@ from tcod.map import Map
from game.components import Gold, Graphic, Position
from game.tags import IsActor, IsItem, IsPlayer, IsWall, IsDoor
def add_wall(x, y, remove=False):
g.world_map.walkable[50+y][50+x] = remove
def add_door(x, y):
door = g.world[object()]
door.tags.add(IsDoor)
door.components[Position] = Position(x,y)
door.components[Graphic] = Graphic(ord("\\"))
add_wall(x,y)
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
rng = world[None].components[Random] = Random()
player = world[object()]
@ -34,19 +46,15 @@ def new_world() -> Registry:
for i in range(20):
if i == 5 or i == 9:
door = world[object()]
door.components[Position] = Position(10, i)
door.components[Graphic] = Graphic(ord("\\"))
door.tags |= {IsDoor}
continue
wall = world[object()]
wall.components[Position] = Position(10, i)
wall.components[Graphic] = Graphic(ord("#"))
wall.tags |= {IsWall}
add_door(10,i)
else:
add_wall(10, i)
return world
def unlock_door(door: Entity):
door.components[Graphic] = Graphic(ord("_"))
door.tags.discard(IsDoor)
door.tags.clear()
pos = door.components[Position]
add_wall(pos.x,pos.y, remove=True)