completed moving walls to map

This commit is contained in:
Lukas Nöllemeyer 2024-08-17 09:56:13 +02:00
parent 9b85305481
commit 91485c0f6b
4 changed files with 14 additions and 15 deletions

View file

@ -15,7 +15,7 @@ import game.world_tools
from game.components import Gold, Graphic, Position
from game.constants import DIRECTION_KEYS, ACTION_KEYS
from game.state import Push, Reset, State, StateResult
from game.tags import IsItem, IsPlayer, IsWall, IsDoor, IsActor
from game.tags import IsItem, IsPlayer, IsDoor, IsActor
from game.constants import WALL_CHAR
@attrs.define()
@ -34,7 +34,7 @@ class InGame(State):
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[1]+new_pos.y][g.world_center[0]+new_pos.x]:
if not g.world_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

View file

@ -13,8 +13,5 @@ IsActor: Final = "IsActor"
IsItem: Final = "IsItem"
"""Entity is an item."""
IsWall: Final = "IsWall"
"""Entity is a wall."""
IsDoor: Final = "IsDoor"
"""Entiy is a door."""

View file

@ -10,17 +10,18 @@ from tcod.ecs import Registry, Entity
from tcod.map import Map
from game.components import Gold, Graphic, Position
from game.tags import IsActor, IsItem, IsPlayer, IsWall, IsDoor
from game.tags import IsActor, IsItem, IsPlayer, IsDoor
def add_wall(x, y, remove=False):
g.world_map.walkable[50+y][50+x] = remove
def add_wall(pos, remove=False):
r_pos = g.world_center + pos
g.world_map.walkable[r_pos.y][r_pos.x] = remove
def add_door(x, y):
def add_door(pos):
door = g.world[object()]
door.tags.add(IsDoor)
door.components[Position] = Position(x,y)
door.components[Position] = pos
door.components[Graphic] = Graphic(ord("\\"))
add_wall(x,y)
add_wall(pos)
def new_world() -> Registry:
@ -46,9 +47,9 @@ def new_world() -> Registry:
for i in range(20):
if i == 5 or i == 9:
add_door(10,i)
add_door(Position(10,i))
else:
add_wall(10, i)
add_wall(Position(10, i))
return world
@ -57,4 +58,4 @@ def unlock_door(door: Entity):
door.components[Graphic] = Graphic(ord("_"))
door.tags.clear()
pos = door.components[Position]
add_wall(pos.x,pos.y, remove=True)
add_wall(pos, remove=True)