How to implement A * pathfinding algorithm in cocos2d games (eight)

Source: Internet
Author: User

Panda Pig • Patty original or translated works. Welcome reprint, Reprint please indicate the source.
If you feel that the writing is not good please tell me, if you feel good please support a lot of praise. Thank you! Hopy;)

Disclaimer: All translations provided by this blog are from the Internet and are for learning and communication purposes only. Also, do not remove this statement when reproduced. In case of any dispute, there is no relationship between the blogger and the person who published the translation. Thank you for your cooperation!

Take the upper left corner of the case and raise a chestnut.

The cat wants to go from the origin (O) to the diagonal in the lower-left corner. If there is a wall on the left or bottom (or all) and the test crosses the diagonal, it will plunge into a corner (or 2). So the diagonal box in the lower left corner is only added to the open list when there is a wall on the left or bottom

Tip: You can simulate different terrains and take the terrain into account by updating the Costtomovefromstep method. In fact, if you lower the G cost, the cat will go faster on those blocks and vice versa.

What's the next thing to do?

Here is the Cat Maze project that can be downloaded, which includes all of the above content code (including diagonal moves).

Congratulations, now that you understand the basic knowledge of a * pathfinding algorithm and have the experience to implement it! Now you should be ready to go:

  • Implement a A * algorithm in your own game
  • Make the necessary improvements (such as allowing different kinds 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 participate in the discussion below!

(This series is complete, thanks for watching;)

How to implement A * pathfinding algorithm in cocos2d games (eight)

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.