13.1. Building the map
Creating the map object
First, you have to allocate a map of the same size as your dungeon.
TCODMap::TCODMap (int width, int height)
TCOD_map_t TCOD_map_new (int width, int height)
map_new (width, height)
TCODMap::TCODMap(int width, int height)
Parameter | Description |
---|---|
width, | height The size of the map (in map cells). |
Defining the cell properties
Then, build your dungeon by defining which cells let the light pass (by default, all cells block the light) and which cells are walkable (by default, all cells are not-walkable).
void TCODMap::setProperties (int x, int y, bool isTransparent, bool isWalkable)
void TCOD_map_set_properties (TCOD_map_t map, int x, int y, bool is_transparent, bool is_walkable)
map_set_properties (map, x, y, is_transparent, is_walkable)
void TCODMap::setProperties (int x, int y, bool isTransparent, bool isWalkable)
Parameter | Description |
---|---|
map | In the C version, the map handler returned by the TCOD_map_new function. |
x, | y Coordinate of the cell that we want to update. |
isTransparent | If true, this cell will let the light pass else it will block the light. |
isWalkable | If true, creatures can walk true this cell (it is not a wall). |
Clearing the map
You can clear an existing map (setting all cells to the chosen walkable/transparent values) with:
void TCODMap::clear (bool transparent = false, bool walkable = false)
void TCOD_map_clear (TCOD_map_t map, bool transparent, bool walkable)
map_clear (map, transparent = False, walkable = False)
void TCODMap::clear()
void TCODMap::clear(bool transparent)
void TCODMap::clear(bool transparent, bool walkable)
Parameter | Description |
---|---|
map | In the C version, the map handler returned by the TCOD_map_new function. |
walkable | Whether the cells should be walkable. |
transparent | Whether the cells should be transparent. |
Copying a map
You can copy an existing map into another. You have to allocate the destination map first.
void TCODMap::copy (const TCODMap * source)
void TCOD_map_copy (TCOD_map_t source, TCOD_map_t dest)
map_copy (source, dest)
void TCODMap::copy (TCODMap source)
Parameter | Description |
---|---|
source | The map containing the source data. |
dest | In C and python version, the map where data is copied. |
Example:
TCODMap * map = new TCODMap(50,50); // allocate the map
map->setProperties(10,10,true,true); // set a cell as 'empty'
TCODMap * map2 = new TCODMap(10,10); // allocate another map
map2->copy(map);
TCOD_map_t map = TCOD_map_new(50,50);
TCOD_map_t map2 = TCOD_map_new(10,10);
TCOD_map_set_properties(map,10,10,true,true);
TCOD_map_copy(map,map2);
map = libtcod.map_new(50,50)
map2 = libtcod.map_new(10,10)
libtcod.map_set_properties(map,10,10,True,True)
libtcod.map_copy(map,map2)