Prefabricated Map Sections
Learn how to create different map sections.
We'll cover the following...
Random dungeons are great, but sometimes we want to represent something specific. We might have a great idea for part or even all of a map. This has been used to great effect in many games. Games as varied as Diablo and Dungeon Crawl Stone Soup procedurally generate a large portion of their content and intersperse premade sections called vaults.
Hand-made dungeons
Creating a new file named map_builder/prefab.rs
. Then add the usual use crate::prelude::*
and define our first prefabricated map section:
use crate::prelude::*;const FORTRESS : (&str, i32, i32) = ("---------------######------#----#------#-M--#----###----###---M------M---###----###----#----#------#----#------######---------------", 12, 11);
The two variables represent the size of our map section. The real magic is in the FORTRESS
string. We’re representing our desired map as characters within the string constant. -
represents an open space, and #
represents a wall. M
represents a monster spawning location. We can design any map section we want, just be sure to set the size appropriately.
Placing our vault
Unless we plan to draw the entire level as a pre-designed map (an excellent idea for boss levels to ensure a specific player experience), we’ll need to be able to place our vault on an existing map. We’ll want to place our prefab somewhere on the map ...