Working visibility (at least relatively good), but a few lines untested
This commit is contained in:
parent
86628fdea6
commit
762bed888a
|
@ -0,0 +1,41 @@
|
||||||
|
1 6
|
||||||
|
################################################################################
|
||||||
|
#..............................................................................#
|
||||||
|
#..#...........................................................................#
|
||||||
|
#...........#..................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
#..............................................................................#
|
||||||
|
################################################################################
|
|
@ -17,6 +17,8 @@ class MapDisplay(Display):
|
||||||
def update_pad(self) -> None:
|
def update_pad(self) -> None:
|
||||||
for j in range(len(self.map.tiles)):
|
for j in range(len(self.map.tiles)):
|
||||||
for i in range(len(self.map.tiles[j])):
|
for i in range(len(self.map.tiles[j])):
|
||||||
|
if not self.map.seen_tiles[j][i]:
|
||||||
|
continue
|
||||||
color = self.pack.tile_fg_visible_color if \
|
color = self.pack.tile_fg_visible_color if \
|
||||||
self.map.visibility[j][i] else self.pack.tile_fg_color
|
self.map.visibility[j][i] else self.pack.tile_fg_color
|
||||||
self.addstr(self.pad, j, self.pack.tile_width * i,
|
self.addstr(self.pad, j, self.pack.tile_width * i,
|
||||||
|
@ -25,9 +27,11 @@ class MapDisplay(Display):
|
||||||
# self.addstr(self.pad, 0, 0, self.map.draw_string(self.pack),
|
# self.addstr(self.pad, 0, 0, self.map.draw_string(self.pack),
|
||||||
# self.pack.tile_fg_color, self.pack.tile_bg_color)
|
# self.pack.tile_fg_color, self.pack.tile_bg_color)
|
||||||
for e in self.map.entities:
|
for e in self.map.entities:
|
||||||
|
if self.map.visibility[e.y][e.x]:
|
||||||
self.addstr(self.pad, e.y, self.pack.tile_width * e.x,
|
self.addstr(self.pad, e.y, self.pack.tile_width * e.x,
|
||||||
self.pack[e.name.upper()],
|
self.pack[e.name.upper()],
|
||||||
self.pack.entity_fg_color, self.pack.entity_bg_color)
|
self.pack.entity_fg_color,
|
||||||
|
self.pack.entity_bg_color)
|
||||||
|
|
||||||
# Display Path map for debug purposes
|
# Display Path map for debug purposes
|
||||||
# from squirrelbattle.entities.player import Player
|
# from squirrelbattle.entities.player import Player
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Player(InventoryHolder, FightingEntity):
|
||||||
strength: int = 5, intelligence: int = 1, charisma: int = 1,
|
strength: int = 5, intelligence: int = 1, charisma: int = 1,
|
||||||
dexterity: int = 1, constitution: int = 1, level: int = 1,
|
dexterity: int = 1, constitution: int = 1, level: int = 1,
|
||||||
current_xp: int = 0, max_xp: int = 10, inventory: list = None,
|
current_xp: int = 0, max_xp: int = 10, inventory: list = None,
|
||||||
hazel: int = 42, vision: int = 5, *args, **kwargs) \
|
hazel: int = 42, vision: int = 50, *args, **kwargs) \
|
||||||
-> None:
|
-> None:
|
||||||
super().__init__(name=name, maxhealth=maxhealth, strength=strength,
|
super().__init__(name=name, maxhealth=maxhealth, strength=strength,
|
||||||
intelligence=intelligence, charisma=charisma,
|
intelligence=intelligence, charisma=charisma,
|
||||||
|
|
|
@ -70,6 +70,7 @@ class Map:
|
||||||
start_x: int
|
start_x: int
|
||||||
tiles: List[List["Tile"]]
|
tiles: List[List["Tile"]]
|
||||||
visibility: List[List[bool]]
|
visibility: List[List[bool]]
|
||||||
|
seen_tiles: List[List[bool]]
|
||||||
entities: List["Entity"]
|
entities: List["Entity"]
|
||||||
logs: Logs
|
logs: Logs
|
||||||
# coordinates of the point that should be
|
# coordinates of the point that should be
|
||||||
|
@ -86,6 +87,8 @@ class Map:
|
||||||
self.tiles = tiles
|
self.tiles = tiles
|
||||||
self.visibility = [[False for _ in range(len(tiles[0]))]
|
self.visibility = [[False for _ in range(len(tiles[0]))]
|
||||||
for _ in range(len(tiles))]
|
for _ in range(len(tiles))]
|
||||||
|
self.seen_tiles = [[False for _ in range(len(tiles[0]))]
|
||||||
|
for _ in range(len(tiles))]
|
||||||
self.entities = []
|
self.entities = []
|
||||||
self.logs = Logs()
|
self.logs = Logs()
|
||||||
|
|
||||||
|
@ -191,7 +194,7 @@ class Map:
|
||||||
for line in self.visibility:
|
for line in self.visibility:
|
||||||
for i in range(len(line)):
|
for i in range(len(line)):
|
||||||
line[i] = False
|
line[i] = False
|
||||||
self.visibility[y][x] = True
|
self.set_visible(0, 0, 0, (y, x))
|
||||||
for octant in range(8):
|
for octant in range(8):
|
||||||
self.compute_visibility_octant(octant, (y, x), max_range, 1,
|
self.compute_visibility_octant(octant, (y, x), max_range, 1,
|
||||||
Slope(1, 1), Slope(0, 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))
|
or ((y != top_y or top > Slope(y * 4 - 1, x * 4 + 1))
|
||||||
and (y != bottom_y
|
and (y != bottom_y
|
||||||
or bottom < Slope(y * 4 + 1, x * 4 - 1)))
|
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:
|
if is_visible:
|
||||||
self.set_visible(y, x, octant, origin)
|
self.set_visible(y, x, octant, origin)
|
||||||
if x == max_range:
|
if x == max_range:
|
||||||
|
@ -304,6 +310,7 @@ class Map:
|
||||||
y, x = self.translate_coord(y, x, octant, origin)
|
y, x = self.translate_coord(y, x, octant, origin)
|
||||||
if 0 <= y < len(self.tiles) and 0 <= x < len(self.tiles[0]):
|
if 0 <= y < len(self.tiles) and 0 <= x < len(self.tiles[0]):
|
||||||
self.visibility[y][x] = True
|
self.visibility[y][x] = True
|
||||||
|
self.seen_tiles[y][x] = True
|
||||||
|
|
||||||
def tick(self) -> None:
|
def tick(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -133,7 +133,7 @@ class TestEntities(unittest.TestCase):
|
||||||
self.assertEqual(item.y, 42)
|
self.assertEqual(item.y, 42)
|
||||||
self.assertEqual(item.x, 42)
|
self.assertEqual(item.x, 42)
|
||||||
# Wait for the explosion
|
# Wait for the explosion
|
||||||
for ignored in range(5):
|
for _ignored in range(5):
|
||||||
item.act(self.map)
|
item.act(self.map)
|
||||||
self.assertTrue(hedgehog.dead)
|
self.assertTrue(hedgehog.dead)
|
||||||
self.assertTrue(teddy_bear.dead)
|
self.assertTrue(teddy_bear.dead)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from squirrelbattle.display.texturepack import TexturePack
|
from squirrelbattle.display.texturepack import TexturePack
|
||||||
from squirrelbattle.interfaces import Map, Tile
|
from squirrelbattle.interfaces import Map, Tile, Slope
|
||||||
from squirrelbattle.resources import ResourceManager
|
from squirrelbattle.resources import ResourceManager
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,3 +37,21 @@ class TestInterfaces(unittest.TestCase):
|
||||||
self.assertFalse(Tile.WALL.can_walk())
|
self.assertFalse(Tile.WALL.can_walk())
|
||||||
self.assertFalse(Tile.EMPTY.can_walk())
|
self.assertFalse(Tile.EMPTY.can_walk())
|
||||||
self.assertRaises(ValueError, Tile.from_ascii_char, 'unknown')
|
self.assertRaises(ValueError, Tile.from_ascii_char, 'unknown')
|
||||||
|
|
||||||
|
def test_slope(self) -> None:
|
||||||
|
"""
|
||||||
|
Test good behaviour of slopes (basically vectors, compared according to
|
||||||
|
the determinant)
|
||||||
|
"""
|
||||||
|
a = Slope(1, 1)
|
||||||
|
b = Slope(0, 1)
|
||||||
|
self.assertTrue(b < a)
|
||||||
|
self.assertTrue(b <= a)
|
||||||
|
self.assertTrue(a <= a)
|
||||||
|
self.assertTrue(a == a)
|
||||||
|
self.assertTrue(a > b)
|
||||||
|
self.assertTrue(a >= b)
|
||||||
|
|
||||||
|
# def test_visibility(self) -> None:
|
||||||
|
# m = Map.load(ResourceManager.get_asset_path("example_map_3.txt"))
|
||||||
|
# m.compute_visibility(1, 1, 50)
|
||||||
|
|
Loading…
Reference in New Issue