Path Nodes

 

This example might help you set up your nodes for path finding. You are not required to build on this example but you can if you find it helpful. I have created a node class that can be rendered as a blue dot with lines to show its connections to other nodes (very useful for debugging). I laid out the nodes as an array that matches up with the array of tiles so that each tiles has a node, and for each node, I can check what type of tile is present. The text book does things a little differently, so you might want to use the tile based levels example as your starting point.

The Buckland source code (linked to on WebCT) contains all the code you need to perform the A* search. Your job is to adapt his code to this environment so that you can find a path starting at the green circle in the bottom-left corner of the screen and connect it using the shortest rout possible to the gold coin in the top-left corner. Shown below is my implementation of A* to solve this problem. I have changed the tiles that make up the path so that they are displayed as arrows (the arrows are part of the sprite sheet). You may use the arrow graphics provided or you can show the path and area searched using lines like Buckland’s example.

 

 

Don’t worry if your path or area searched is slightly different than mine. I didn’t use any of his code, instead I wrote it from scratch using a priority queue. Path finding can be tricky to implement, my advice is to read up on A* and make sure you understand it before starting. Start early and don’t expect to get it right on the first try. Render lines and dots to help you debug it visually. If the book’s code is giving you problems, you may use any code you find online or write your own. Note: if you use someone else’s code, reference them using comments and make sure you understand how it works so that you can explain the code to me, and answer any questions I might have about it.

 

PathNodes.zip  34KB