< index
< 13. Path finding
< 13.1 Creating a path

=====================================
13.2 Computing the path
=====================================

> 13.3 Reading path information
Once you created a TCODPath object, you can compute the path between two points :

C++ : bool TCODPath::compute(int ox, int oy, int dx, int dy)
C   : bool TCOD_path_compute(TCOD_path_t path, int ox,int oy, int dx, int dy)
Py  : path_compute(path, ox, oy, dx, dy)

ParameterDescription
pathIn the C version, the path handler returned by a creation function.
ox,oyCoordinates of the origin of the path.
dx,dyCoordinates of the destination of the path.
Both points should be inside the map, and at a walkable position. The function returns false if there is no possible path.

Example :

C++ : TCODMap *myMap = new TCODMap(50,50);
      TCODPath *path = new TCODPath(myMap); // allocate the path
      path->compute(5,5,25,25); // calculate path from 5,5 to 25,25
C   : TCOD_map_t my_map=TCOD_map_new(50,50);
      TCOD_path_t path = TCOD_path_new_using_map(my_map);
      TCOD_path_compute(path,5,5,25,25);
Py  : my_map=libtcod.map_new(50,50)
      path = libtcod.path_new_using_map(my_map)
      libtcod.path_compute(path,5,5,25,25)

insert a comment