--- tags: Sequencer-dungeon-spec --- [toc] # Storing the Dungeon Map The map structure represents the dungeon layout. A map has a series of tiles in a grid pattern. Each tile has a type describing how that tile is rendered. Map is represented as a vector. Each entry in the vector represents one tile. ## Represent tiles Tiles are limited to a pre-defined set of tile types. Tiles is an `enum`. It is a `public` enumeration named `TileType` with entries for walls and floors: ```rust #[derive(Clone, PartialEq)] pub enum TileType { Wall, Floor, } ``` ## Create an Empty Map Containing a vector of tiles ```rust #[derive(Clone, PartialEq)] pub struct Map { pub tiles: Vec<TileType>, } ``` A constructor of a map is the `NUM_TILES` number of entries each set to `TileType::Floor`, creating a map consisting entirely of floors ```rust pub const MAP_WIDTH: usize = 32; pub const MAP_HEIGHT: usize = 32; pub const NUM_TILES = MAP_WIDTH * MAP_HEIGHT; pub fn new() -> Self { Self { tiles: vec![TileType::Floor; NUM_TILES], } } ``` ## Index the map The index of a tile from `x` and `y` coordinates as follows: ```rust pub fn map_idx(x: usize, y: usize) -> usize { (y * MAP_WIDTH) + x } ``` ## State object A `Map` is add to the `State` object and initialize it `State`'s constructor. ```rust #[derive(Clone, PartialEq)] pub struct State { map: Map, } ``` The path of state of a map is storing in the durable state of tezos-smart-rollup kernel as follows: ```rust const MAP_PATH: RefPath = RefPath::assert_from(b"/state/map"); ``` When reading or writing from/to the state, using the `Runtime` function of the tezos-smart-rollup kernel library.