Adding Stairs to the Map

Hands-on Rust — by Herbert Wolverson (96 / 120)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Chapter 14 Deeper Dungeons | TOC | Tracking Game Level 👉

Staircases provide a popular means of conveyance to deeper levels. Stairs can occupy a single tile, are relatively easy to render, and are intuitive. In this section, you’ll define stairs as a new type of map tile. You’ll add stairs to your map rendering and theming system, and update the navigation system to allow the player to enter the staircase. Rather than spawn the Amulet of Yala at the end of each level, you’ll only add it to the last level — the other levels will feature an exit to the next dungeon layer.

Let’s start by adding the staircase to the game map.

Making and Rendering Staircases

To render staircases within your dungeon, you’ll need a new type of map tile. Open map.rs and find the TileType enumeration. Add a new Exit entry for the staircases:

DeeperDungeons/more_levels/src/map.rs

​ ​#​[​derive​(Copy, Clone, PartialEq)]
​ ​pub​ ​enum​ TileType {
​ Wall,
​ Floor,
» Exit
​ }

If you’re using a text editor with real-time error detection, you’ll notice that it just marked every match on TileType as an error. This happens because Rust matches must include all possible options — and you just added a new option to TileType.

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.