Adding the Adventurer

The adventurer is the player’s avatar in the dungeon. The player roams the dungeon, hopefully collecting loot and probably dying at the hands of vicious monsters. The game needs to know what tiles the adventurers can enter so they don’t walk through walls. It also needs to store where the player is, handle moving them with the keyboard, and perform the movement. This section will address each of these requirements.

Extend the Map API

Let’s add some more map functions to support player functionality. You need to determine if an x/y coordinate pair is within the bounds of the map. If you don’t perform bounds-checking, the player can move off the edge of the map, and either wrap around or crash the program. Add the following ...

Get Hands-on Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.