enhanced FOV
This commit is contained in:
parent
0a0ff2d1ed
commit
1bd0ab372d
4 changed files with 20 additions and 15 deletions
|
|
@ -64,18 +64,23 @@ class MainScreen(Screen):
|
|||
|
||||
def draw(e_pos, e_graph):
|
||||
screen_pos = e_pos - camera_pos
|
||||
mp = world_pos_to_map_pos(e_pos)
|
||||
map_pos = world_pos_to_map_pos(e_pos)
|
||||
if (-w <= screen_pos.x < w\
|
||||
and -h <= screen_pos.y < h)\
|
||||
and map.fov[mp.y][mp.x]:
|
||||
graphic = e_graph
|
||||
and -h <= screen_pos.y < h):
|
||||
if map.fov[map_pos.y][map_pos.x]:
|
||||
graphic = e_graph
|
||||
else:
|
||||
graphic = Graphic(0x2591, (50, 50, 50))
|
||||
console.rgb[["ch", "fg"]][screen_pos.y + h, screen_pos.x + w] = graphic.ch, graphic.fg
|
||||
|
||||
# Draw walls
|
||||
for (y, row) in enumerate(map.walkable):
|
||||
for (x, val) in enumerate(row):
|
||||
if not val:
|
||||
draw(map_pos_to_world_pos(Position(x,y)), Graphic(WALL_CHAR))
|
||||
pos = map_pos_to_world_pos(Position(x,y))
|
||||
if val:
|
||||
draw(pos, Graphic(0)) # open air
|
||||
else:
|
||||
draw(pos, 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])
|
||||
|
|
|
|||
|
|
@ -1,25 +1,27 @@
|
|||
"""Functions for working with worlds."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from random import Random
|
||||
|
||||
import g
|
||||
from typing import Final
|
||||
|
||||
from tcod.ecs import Registry, Entity
|
||||
from tcod.map import Map
|
||||
|
||||
import g
|
||||
|
||||
from game.components import Gold, Graphic, Position
|
||||
from game.tags import IsActor, IsItem, IsPlayer, IsDoor
|
||||
|
||||
world_center: Final = Position(50, 50)
|
||||
|
||||
def world_pos_to_map_pos(pos):
|
||||
return pos+g.world_center
|
||||
return pos+world_center
|
||||
|
||||
def map_pos_to_world_pos(pos):
|
||||
return pos-g.world_center
|
||||
return pos-world_center
|
||||
|
||||
def add_wall(world, pos, remove=False):
|
||||
r_pos = g.world_center + pos
|
||||
r_pos = world_pos_to_map_pos(pos)
|
||||
map = world[None].components[Map]
|
||||
map.walkable[r_pos.y][r_pos.x] = remove
|
||||
map.transparent[r_pos.y][r_pos.x] = remove
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue