Simple Path finding using for simple world using A* pathfinding algorithm. for cocos2dx v3
http://en.wikipedia.org/wiki/A*_search_algorithm http://www.raywenderlich.com/4970/how-to-implement-a-pathfinding-with-cocos2d-tutorial 1. Create a 2-dimension matrix world:Example: ``` c++ std::vector> matrix std::vector row1 = {1,1,1,1,1}; std::vector row2 = {1,0,1,0,1}; std::vector row3 = {1,0,0,0,1}; std::vector row4 = {1,0,1,0,1}; std::vector row5 = {1,1,1,1,1}; matrix.push_back(row1); matrix.push_back(row2); matrix.push_back(row3); matrix.push_back(row4); matrix.push_back(row5); ```
- Init PathFinding
Example:
_pathFinder = pathfinding::PathFinding::create();
_pathFinder->retain();
_pathFinder->setupMap(matrix);
- Find the path:
Example:
Vec2 beginCoord = Vec2(1,1);
Vec2 endCoord = Vec2(3,3);
std::vector<Vec2> path = _pathFinder->getShortestPath(beginCoord, endCoord);
- In PathFinding.cpp, you can enable debug print
change
#define DEBUG_PRINT 0
to
#define DEBUG_PRINT 1