recalculate FOV only on movement or door opening
This commit is contained in:
parent
1bd0ab372d
commit
bbc958b36c
2 changed files with 14 additions and 6 deletions
|
|
@ -25,19 +25,27 @@ class MainScreen(Screen):
|
||||||
def on_event(self, event: tcod.event.Event) -> ScreenResult:
|
def on_event(self, event: tcod.event.Event) -> ScreenResult:
|
||||||
"""Handle events for the in-game state."""
|
"""Handle events for the in-game state."""
|
||||||
(player,) = g.world.Q.all_of(tags=[IsPlayer])
|
(player,) = g.world.Q.all_of(tags=[IsPlayer])
|
||||||
|
map: Map = g.world[None].components[Map]
|
||||||
match event:
|
match event:
|
||||||
case tcod.event.KeyDown(sym=sym) if sym in ACTION_KEYS:
|
case tcod.event.KeyDown(sym=sym) if sym in ACTION_KEYS:
|
||||||
for door in g.world.Q.all_of(tags=[IsDoor]):
|
for door in g.world.Q.all_of(tags=[IsDoor]):
|
||||||
if (player.components[Position] - door.components[Position]).length() < 2:
|
player_pos = player.components[Position]
|
||||||
|
if (player_pos - door.components[Position]).length() < 2:
|
||||||
ACTION_KEYS[sym](door)
|
ACTION_KEYS[sym](door)
|
||||||
|
cam_map = world_pos_to_map_pos(player_pos)
|
||||||
|
map.compute_fov(cam_map.x, cam_map.y, 100)
|
||||||
|
|
||||||
case tcod.event.Quit():
|
case tcod.event.Quit():
|
||||||
raise SystemExit()
|
raise SystemExit()
|
||||||
case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS:
|
case tcod.event.KeyDown(sym=sym) if sym in DIRECTION_KEYS:
|
||||||
new_pos = player.components[Position] + DIRECTION_KEYS[sym]
|
new_pos = player.components[Position] + DIRECTION_KEYS[sym]
|
||||||
map_pos = world_pos_to_map_pos(new_pos)
|
map_pos = world_pos_to_map_pos(new_pos)
|
||||||
if not g.world[None].components[Map].walkable[map_pos.y][map_pos.x]:
|
if not map.walkable[map_pos.y][map_pos.x]:
|
||||||
return None
|
return None
|
||||||
player.components[Position] = new_pos
|
player.components[Position] = new_pos
|
||||||
|
cam_map = world_pos_to_map_pos(new_pos)
|
||||||
|
map.compute_fov(cam_map.x, cam_map.y, 100)
|
||||||
|
|
||||||
# Auto pickup gold
|
# Auto pickup gold
|
||||||
for gold in g.world.Q.all_of(components=[Gold], tags=[player.components[Position], IsItem]):
|
for gold in g.world.Q.all_of(components=[Gold], tags=[player.components[Position], IsItem]):
|
||||||
player.components[Gold] += gold.components[Gold]
|
player.components[Gold] += gold.components[Gold]
|
||||||
|
|
@ -59,8 +67,6 @@ class MainScreen(Screen):
|
||||||
w = console.width//2
|
w = console.width//2
|
||||||
|
|
||||||
map: Map = g.world[None].components[Map]
|
map: Map = g.world[None].components[Map]
|
||||||
cam_map = world_pos_to_map_pos(camera_pos)
|
|
||||||
map.compute_fov(cam_map.x, cam_map.y, 100)
|
|
||||||
|
|
||||||
def draw(e_pos, e_graph):
|
def draw(e_pos, e_graph):
|
||||||
screen_pos = e_pos - camera_pos
|
screen_pos = e_pos - camera_pos
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,10 @@ def new_world() -> Registry:
|
||||||
map.transparent[:] = True
|
map.transparent[:] = True
|
||||||
|
|
||||||
rng = world[None].components[Random] = Random()
|
rng = world[None].components[Random] = Random()
|
||||||
|
player_pos = Position(5,5)
|
||||||
world.new_entity(
|
world.new_entity(
|
||||||
components={
|
components={
|
||||||
Position: Position(5,5),
|
Position: player_pos,
|
||||||
Graphic: Graphic(ord('@')),
|
Graphic: Graphic(ord('@')),
|
||||||
Gold: 0
|
Gold: 0
|
||||||
},
|
},
|
||||||
|
|
@ -77,6 +77,8 @@ def new_world() -> Registry:
|
||||||
else:
|
else:
|
||||||
add_wall(world, Position(10, i))
|
add_wall(world, Position(10, i))
|
||||||
|
|
||||||
|
cam_pos = world_pos_to_map_pos(player_pos)
|
||||||
|
map.compute_fov(cam_pos.x, cam_pos.y)
|
||||||
return world
|
return world
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue