Add a map shroud over tiles and compute field of view based on player position!!!

This commit is contained in:
Eryn Wells 2022-05-04 09:22:40 -07:00
parent 25aa5506c8
commit 084385f8f2
3 changed files with 51 additions and 7 deletions

View file

@ -6,7 +6,7 @@ import numpy as np
import random
import tcod
from .geometry import Direction, Point, Rect, Size
from .tile import Empty, Floor, Wall
from .tile import Empty, Floor, Shroud, Wall
from dataclasses import dataclass
from typing import Iterator, List, Optional
@ -19,6 +19,11 @@ class Map:
self.generator = RoomsAndCorridorsGenerator(size=size)
self.tiles = self.generator.generate()
# Map tiles that are currently visible to the player
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=False, order='F')
def random_walkable_position(self) -> Point:
# TODO: Include hallways
random_room: RectangularRoom = random.choice(self.generator.rooms)
@ -34,8 +39,15 @@ class Map:
return self.tiles[point.x, point.y]['walkable']
def print_to_console(self, console: tcod.Console) -> None:
'''Render the map to the console.'''
size = self.size
console.tiles_rgb[0:size.width, 0:size.height] = self.tiles["dark"]
# 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']],
default=Shroud)
class MapGenerator:
def __init__(self, *, size: Size):