Adding Stairs to the Map
Learn how to define stairs and add stairs to map rendering and theming systems.
Staircases are a popular means of transport to deeper levels. Stairs can occupy a single tile, are relatively easy to render, and are intuitive.
Making and rendering staircases
Add a new Exit
entry in TileType
enumeration for the staircases to render staircases within our dungeon in map.rs
:
#[derive(Copy, Clone, PartialEq)]pub enum TileType {Wall,Floor,Exit}
The TileType
enum is matched in map_builder/themes.rs
because themes need to know how to render every tile type. Add a match
branch to draw the downward staircases in map_builder/themes.rs
:
impl MapTheme for DungeonTheme {fn tile_to_render(&self, tile_type: TileType) -> FontCharType {match tile_type {TileType::Floor => to_cp437('.'),TileType::Wall => to_cp437('#'),TileType::Exit => to_cp437('>'),}}}
The forest theme also needs to draw staircases, so make the same change in the forest renderer:
impl MapTheme for ForestTheme {fn tile_to_render(&self, tile_type: TileType) -> FontCharType {match tile_type {TileType::Floor => to_cp437(';'),TileType::Wall => to_cp437('"'),TileType::Exit => to_cp437('>'),}}}
Now that the game can render exit (staircase) tiles, it’s time to make them accessible to the adventurer, and perhaps the monsters too.
Update dungeon navigation
This game uses the can_enter_tile()
...