Draw a path from the hero to the current mouse point
Add a highlight grid to Map, with locations set to True if that point should be drawn with a "highlight" treatment. Add the highlight graphic_dtype to all Tiles.
This commit is contained in:
parent
f05dfdef55
commit
6c9d01771f
4 changed files with 80 additions and 29 deletions
|
@ -6,6 +6,7 @@ parts of a map.
|
|||
'''
|
||||
|
||||
import random
|
||||
from typing import Iterable
|
||||
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
|
@ -20,17 +21,17 @@ class Map:
|
|||
def __init__(self, size: Size, generator: MapGenerator):
|
||||
self.size = size
|
||||
|
||||
self.generator = generator
|
||||
self.tiles = np.full(tuple(size), fill_value=Empty, order='F')
|
||||
generator.generate(self.tiles)
|
||||
|
||||
self.up_stairs = generator.up_stairs
|
||||
self.down_stairs = generator.down_stairs
|
||||
|
||||
self.highlighted = np.full(tuple(self.size), fill_value=False, order='F')
|
||||
# Map tiles that are currently visible to the player
|
||||
self.visible = np.full(tuple(self.size), fill_value=True, order='F')
|
||||
self.visible = np.full(tuple(self.size), fill_value=False, order='F')
|
||||
# Map tiles that the player has explored
|
||||
self.explored = np.full(tuple(self.size), fill_value=True, order='F')
|
||||
self.explored = np.full(tuple(self.size), fill_value=False, order='F')
|
||||
|
||||
self.__walkable_points = None
|
||||
|
||||
|
@ -47,7 +48,14 @@ class Map:
|
|||
|
||||
def tile_is_walkable(self, point: Point) -> bool:
|
||||
'''Return True if the tile at the given point is walkable'''
|
||||
return self.tiles[point.x, point.y]['walkable']
|
||||
return self.tile_is_in_bounds(point) and self.tiles[point.x, point.y]['walkable']
|
||||
|
||||
def highlight_points(self, points: Iterable[Point]):
|
||||
'''Update the highlight graph with the list of points to highlight.'''
|
||||
self.highlighted.fill(False)
|
||||
|
||||
for pt in points if points:
|
||||
self.highlighted[pt.x, pt.y] = True
|
||||
|
||||
def print_to_console(self, console: tcod.Console) -> None:
|
||||
'''Render the map to the console.'''
|
||||
|
@ -56,6 +64,6 @@ class Map:
|
|||
# If a tile is in the visible array, draw it with the "light" color. If it's not, but it's in the explored
|
||||
# array, draw it with the "dark" color. Otherwise, draw it as Empty.
|
||||
console.tiles_rgb[0:size.width, 0:size.height] = np.select(
|
||||
condlist=[self.visible, self.explored],
|
||||
choicelist=[self.tiles['light'], self.tiles['dark']],
|
||||
condlist=[self.highlighted, self.visible, self.explored],
|
||||
choicelist=[self.tiles['highlighted'], self.tiles['light'], self.tiles['dark']],
|
||||
default=Shroud)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue