How to implement A * pathfinding Algorithm in Cocos2D games (8)

Source: Internet
Author: User

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!

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.