Working visibility (at least relatively good), but a few lines untested

This commit is contained in:
Nicolas Margulies
2020-12-18 21:21:00 +01:00
parent 86628fdea6
commit 762bed888a
6 changed files with 77 additions and 7 deletions

View File

@ -70,6 +70,7 @@ class Map:
start_x: int
tiles: List[List["Tile"]]
visibility: List[List[bool]]
seen_tiles: List[List[bool]]
entities: List["Entity"]
logs: Logs
# coordinates of the point that should be
@ -86,6 +87,8 @@ class Map:
self.tiles = tiles
self.visibility = [[False for _ in range(len(tiles[0]))]
for _ in range(len(tiles))]
self.seen_tiles = [[False for _ in range(len(tiles[0]))]
for _ in range(len(tiles))]
self.entities = []
self.logs = Logs()
@ -191,7 +194,7 @@ class Map:
for line in self.visibility:
for i in range(len(line)):
line[i] = False
self.visibility[y][x] = True
self.set_visible(0, 0, 0, (y, x))
for octant in range(8):
self.compute_visibility_octant(octant, (y, x), max_range, 1,
Slope(1, 1), Slope(0, 1))
@ -242,6 +245,9 @@ class Map:
or ((y != top_y or top > Slope(y * 4 - 1, x * 4 + 1))
and (y != bottom_y
or bottom < Slope(y * 4 + 1, x * 4 - 1)))
# is_visible = is_opaque\
# or ((y != top_y or top >= Slope(y, x))
# and (y != bottom_y or bottom <= Slope(y, x)))
if is_visible:
self.set_visible(y, x, octant, origin)
if x == max_range:
@ -304,6 +310,7 @@ class Map:
y, x = self.translate_coord(y, x, octant, origin)
if 0 <= y < len(self.tiles) and 0 <= x < len(self.tiles[0]):
self.visibility[y][x] = True
self.seen_tiles[y][x] = True
def tick(self) -> None:
"""