How to implement A * pathfinding Algorithm in Cocos2D games (8)
Let's take the upper left corner of the page as an example.
The cat wants to go from the origin (O) to the Diagonal Square in the lower left corner. if there is a wall on the left or bottom (or all of them) and the test passes through the diagonal line, it will cut into a corner (or two ). therefore, the Diagonal Square in the lower left corner is added to the open list only when there is a wall on the left or bottom.
Tip: You can simulate different terrain and update the costToMoveFromStep method to consider the terrain. In fact, if you reduce the G cost, the cat will go faster on those blocks, and vice versa.
What should we do next?
The Cat Maze project can be downloaded, including all the above Code (including diagonal movement ).
Congratulations! Now you know the basic knowledge of A * pathfinding algorithm and have the experience to implement it! Now you should prepare:
Implement A * Algorithm in your own game to make necessary improvements (for example, to allow different types of terrain, better heuristic algorithms, etc.) and optimization. read Other topics, such as this wonderful guide: Amit's A * Pages
If you have any questions or comments about this course, please join the discussion below!