A classic video game problem is that of pathfinding. Intelligent actors are often required to navigate around obstacles during gameplay. The A* search algorithm (also known as A Star) is commonly used to solve pathfinding by efficiently traversing a constructed node graph. In this recipe, we will demonstrate grid-based A* pathfinding.
Execute the following code:
/* AStarNode */ @interface AStarNode : NSObject { CGPoint position; //The node's position on our map NSMutableArray *neighbors; //An array of neighbor AStarNode objects bool active; //Is this node active? float costMultiplier; //Use this to multiply the normal cost to reach this node. } @end @implementation AStarNode /* Cost to node heuristic */ -(float) costToNode:(AStarNode*)node { CGPoint src = ccp(self.position.x, self.position.y); CGPoint dst = ccp(node.position.x, node...