added FOV
This commit is contained in:
parent
1b5d512a4b
commit
0a0ff2d1ed
2 changed files with 24 additions and 5 deletions
|
|
@ -16,7 +16,7 @@ from game.screens import Push, Screen, ScreenResult
|
|||
from game.tags import IsItem, IsPlayer, IsDoor, IsActor
|
||||
from game.constants import WALL_CHAR
|
||||
from game.screens import menu_screens
|
||||
|
||||
from game.world_tools import world_pos_to_map_pos, map_pos_to_world_pos
|
||||
|
||||
@attrs.define()
|
||||
class MainScreen(Screen):
|
||||
|
|
@ -34,7 +34,8 @@ 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[None].components[Map].walkable[g.world_center.y+new_pos.y][g.world_center.x+new_pos.x]:
|
||||
map_pos = world_pos_to_map_pos(new_pos)
|
||||
if not g.world[None].components[Map].walkable[map_pos.y][map_pos.x]:
|
||||
return None
|
||||
player.components[Position] = new_pos
|
||||
# Auto pickup gold
|
||||
|
|
@ -56,20 +57,32 @@ class MainScreen(Screen):
|
|||
camera_pos = camera_pos.mod(len(centers))
|
||||
h = console.height//2
|
||||
w = console.width//2
|
||||
|
||||
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):
|
||||
screen_pos = e_pos - camera_pos
|
||||
mp = world_pos_to_map_pos(e_pos)
|
||||
if (-w <= screen_pos.x < w\
|
||||
and -h <= screen_pos.y < h):
|
||||
and -h <= screen_pos.y < h)\
|
||||
and map.fov[mp.y][mp.x]:
|
||||
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[None].components[Map].walkable):
|
||||
|
||||
# Draw walls
|
||||
for (y, row) in enumerate(map.walkable):
|
||||
for (x, val) in enumerate(row):
|
||||
if not val:
|
||||
draw(Position(x,y)-g.world_center, Graphic(WALL_CHAR))
|
||||
draw(map_pos_to_world_pos(Position(x,y)), Graphic(WALL_CHAR))
|
||||
# draw all entities that are not actors
|
||||
for entity in g.world.Q.all_of(components=[Position, Graphic]).none_of(tags=[IsActor]):
|
||||
draw(entity.components[Position], entity.components[Graphic])
|
||||
# draw all actors
|
||||
for actor in g.world.Q.all_of(components=[Position, Graphic], tags=[IsActor]).none_of(tags=[IsPlayer]):
|
||||
draw(actor.components[Position], entity.components[Graphic])
|
||||
# draw the player
|
||||
for player in g.world.Q.all_of(tags=[IsPlayer]):
|
||||
draw(player.components[Position], player.components[Graphic])
|
||||
if text := g.world[None].components.get(("Text", str)):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue