Storing the Dungeon Map

Learn how to store a map in the structure of a tile and how this leads to an efficient and simple map-rendering system.

Most games include some sort of map, typically an array of tiles. For a dungeon-crawler game, the map structure represents the dungeon layout. Platform games use maps to represent the location of ledges, platforms, and ladders.

A minesweeper game represents the discovered areas and the positions of mines on the map. Most two-dimensional games represent their map as a series of tiles in a grid pattern. Each tile has a type, describing how it’s rendered and what happens if we try to enter it.

We’ll represent the map as a vector. Each entry in the vector represents one tile, so for an 80x50 map, we’ll have 4,000 tiles. Tiles represent portions of the map, and the same tile graphic is reused to represent tiles of a particular type. Entities such as the player or any monsters are overlaid on top:

Get hands-on with 1200+ tech skills courses.