Skip to content

Simple Path finding using for simple world using A* pathfinding algorithm. for cocos2dx v3

Notifications You must be signed in to change notification settings

quannv108/CCSimplePathFinding

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

CCSimplePathFinding

Simple Path finding using for simple world using A* pathfinding algorithm. for cocos2dx v3

Document:
http://en.wikipedia.org/wiki/A*_search_algorithm
Thanks to Ray Wenderlich:
http://www.raywenderlich.com/4970/how-to-implement-a-pathfinding-with-cocos2d-tutorial
How to use:
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); ```
  1. Init PathFinding
    Example:
_pathFinder = pathfinding::PathFinding::create();
_pathFinder->retain();
_pathFinder->setupMap(matrix);
  1. Find the path:
    Example:
Vec2 beginCoord = Vec2(1,1);
Vec2 endCoord = Vec2(3,3);
std::vector<Vec2> path = _pathFinder->getShortestPath(beginCoord, endCoord);
  1. In PathFinding.cpp, you can enable debug print
    change
#define DEBUG_PRINT 0
to 
#define DEBUG_PRINT 1

About

Simple Path finding using for simple world using A* pathfinding algorithm. for cocos2dx v3

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages