< index
< 12. Field of view toolkit

=====================================
12.1 Building the map
=====================================

> 12.2 Computing the field of view
First, you have to allocate a map of the same size as your dungeon.

C++ : TCODMap::TCODMap(int width, int height)
C   : TCOD_map_t TCOD_map_new(int widht, int height)

ParameterDescription
width,heightThe size of the map (in map cells).

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).

C++ : void TCODMap::setProperties(int x, int y, bool isTransparent, bool isWalkable)
C   : void TCOD_map_set_properties(TCOD_map_t map, int x, int y, bool is_transparent, bool is_walkable)

ParameterDescription
mapIn the C version, the map handler returned by the TCOD_map_new function.
x,yCoordinate of the cell that we want to update.
isTransparentIf true, this cell will let the light pass else it will block the light.
isWalkableIf true, creatures can walk true this cell (it is not a wall).

You can clear an existing map (setting all cells as 'blocking') with :

C++ : void TCODMap::clear()
C   : void TCOD_map_clear(TCOD_map_t map)

ParameterDescription
mapIn the C version, the map handler returned by the TCOD_map_new function.

Example :

C++ : TCODMap *map = new TCODMap(50,50); // allocate the map
      map->setProperties(10,10,true,true); // set a cell as 'empty'
	  map->clear(); // reset the map (all blocking cells)
C   : TCOD_map_t map = TCOD_map_new(50,50);
      TCOD_map_set_properties(map,10,10,true,true);
	  TCOD_map_clear(map);