The real fun of the A* algorithm comes from applying it to more complex scenarios. In this recipe, we will apply the grid-based technique of the last recipe to a Box2D world filled with randomly generated polygons.
Execute the following code:
@interface Ch7_Box2DPathfinding : GameArea2D { NSMutableArray *grid; float nodeSpace; //The space between each node, increase this to increase A* efficiency at the cost of accuracy int gridSizeX; int gridSizeY; } @end @implementation Ch7_Box2DPathfinding -(CCLayer*) runRecipe { //Initial variables nodeSpace = 32.0f; actorRadius = nodeSpace/PTM_RATIO/3; /* CODE OMITTED */ //Remove neighbors from positive TestPoint and RayCast tests for(int x=0; x<gridSizeX; x++){ for(int y=0; y<gridSizeY; y++){ //Add a node AStarNode *node = [[grid objectAtIndex:x] objectAtIndex:y];...