Top-down Dungeon-crawler Controls
This recipe shows how to walk a character around a top-down 2D space, as is common in dungeon
crawlers and Zelda-like games. In this recipe, the character is always in the center of the
screen and the dungeon scrolls as they walk around.
Live Demo
Controls
Source Code
Exercises
- If you're not perfectly lined up with a hallway, the game won't let you enter. Modify
the collision detection code to ease you toward the center of the tile if you're walking
toward a tile that is passable, but are bumping into the corner of an impassable
tile.
- Reveal dungeon areas as the player walks around. Most commonly one also reveals a whole
room as soon as the player walks into it, but you could also just reveal the 3x3 area
around the player and force them to map out each room as well.
Back to cookbook.