fixed global usage
This commit is contained in:
parent
bd0db732b6
commit
1b5d512a4b
1 changed files with 8 additions and 9 deletions
|
|
@ -12,27 +12,26 @@ from tcod.map import Map
|
||||||
from game.components import Gold, Graphic, Position
|
from game.components import Gold, Graphic, Position
|
||||||
from game.tags import IsActor, IsItem, IsPlayer, IsDoor
|
from game.tags import IsActor, IsItem, IsPlayer, IsDoor
|
||||||
|
|
||||||
def add_wall(pos, remove=False):
|
def add_wall(world, pos, remove=False):
|
||||||
r_pos = g.world_center + pos
|
r_pos = g.world_center + pos
|
||||||
map = g.world[None].components[Map]
|
map = world[None].components[Map]
|
||||||
map.walkable[r_pos.y][r_pos.x] = remove
|
map.walkable[r_pos.y][r_pos.x] = remove
|
||||||
map.transparent[r_pos.y][r_pos.x] = remove
|
map.transparent[r_pos.y][r_pos.x] = remove
|
||||||
|
|
||||||
def add_door(pos):
|
def add_door(world, pos):
|
||||||
g.world.new_entity(
|
world.new_entity(
|
||||||
components={
|
components={
|
||||||
Position: pos,
|
Position: pos,
|
||||||
Graphic: Graphic(ord('\\'))
|
Graphic: Graphic(ord('\\'))
|
||||||
},
|
},
|
||||||
tags=[IsDoor]
|
tags=[IsDoor]
|
||||||
)
|
)
|
||||||
add_wall(pos)
|
add_wall(world, pos)
|
||||||
|
|
||||||
|
|
||||||
def new_world() -> Registry:
|
def new_world() -> Registry:
|
||||||
"""Return a freshly generated world."""
|
"""Return a freshly generated world."""
|
||||||
world = Registry()
|
world = Registry()
|
||||||
g.world = world
|
|
||||||
|
|
||||||
map = world[None].components[Map] = Map(100, 100)
|
map = world[None].components[Map] = Map(100, 100)
|
||||||
map.walkable[:] = True
|
map.walkable[:] = True
|
||||||
|
|
@ -66,9 +65,9 @@ def new_world() -> Registry:
|
||||||
|
|
||||||
for i in range(20):
|
for i in range(20):
|
||||||
if i == 5 or i == 9:
|
if i == 5 or i == 9:
|
||||||
add_door(Position(10,i))
|
add_door(world, Position(10,i))
|
||||||
else:
|
else:
|
||||||
add_wall(Position(10, i))
|
add_wall(world, Position(10, i))
|
||||||
|
|
||||||
return world
|
return world
|
||||||
|
|
||||||
|
|
@ -76,4 +75,4 @@ def new_world() -> Registry:
|
||||||
def unlock_door(door: Entity):
|
def unlock_door(door: Entity):
|
||||||
door.components[Graphic] = Graphic(ord("_"))
|
door.components[Graphic] = Graphic(ord("_"))
|
||||||
door.tags.clear()
|
door.tags.clear()
|
||||||
add_wall(door.components[Position], remove=True)
|
add_wall(g.world, door.components[Position], remove=True)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue