Adding Spatial Memory
Hands-on Rust — by Herbert Wolverson (78 / 120)
👈 Limiting Monsters’ Fields of View | TOC | Wrap-Up 👉
Whether the adventurer is unspooling thread as they work through a minotaur’s labyrinth or scribbling a map as they explore, it’s reasonable to expect the adventurer has some memory of where they have been. It also gives the player valuable clues about which parts of the dungeon they haven’t explored yet — reducing player frustration. In this section, you’ll give the player a memory of where they’ve been — and learn to render areas they remember but aren’t currently visible.
Revealing the Map
Open map.rs. Add a new vector named revealed, containing the revealed status of each tile. If the player has seen the tile, the tile’s entry in revealed will be set to true. If they haven’t, it will be false. Create the new vector and set the entire revealed vector to false:
pub struct Map {
pub tiles: Vec<TileType>,
pub revealed_tiles: Vec<bool>
}
impl Map {
pub fn new() -> Self {
Self {
tiles: vec![TileType::Floor; NUM_TILES],
revealed_tiles: vec![false; NUM_TILES]
}
}