@ziagl/tiled-map-path-finder
v1.0.3
Published
A path finder library for 2 dimensional maps.
Downloads
2
Readme
tiled-map-path-finder
A path finding library for hexagon maps.
Sample images of usage in possible environment
This image shows how reachableTiles is used on a map with different tiles (tiles with different movement costs). In this example reachableTiles computes all tiles that can be reached with movement value of 6 (up to 6 tiles). Plain and Sand costs 1, Wood and Hills costs 2, Mountains are unpassable.
With computePath it is possible to find shortest (with the lowest costs) path.
It ignores tiles that are not passable. If no path is possible, it returns an empty path.
Sample code
const exampleMap:number [] = [
1, 1, 2, 3,
1, 2, 1, 3,
2, 4, 8, 1,
3, 1, 2, 1
];
const pf = new PathFinder(exampleMap, 4, 4);
const reachableTiles = pf.reachableTiles({q:0, r:0, s:0}, 2);
// reachableTiles.length is 7
Example usage of reachableTiles. It is important to initialize the component with a heatmap (a 2D map of all tiles used with movement value 0 -> not passable, >1 cost for passing). reachableTiles is called with a starting coordinate in cube coordinate system and a max cost value.
const exampleMap:number [] = [
1, 1, 2, 3,
1, 2, 1, 3,
2, 4, 8, 1,
3, 1, 2, 1
];
const pf = new PathFinder(exampleMap, 4, 4);
const path = pf.computePathOffsetCoordinates({x:0,y:0}, {x:3,y:3});
// path.length is 6
Example usage of computePath. Compute path is called with 2 cube coordinates for start and end. A second version computePathOffsetCoordinates does the same, but start and end can be passed as offset coordinates (normal x and y values in 2D space). It returns all tiles of shortest path.