Revisiting the A* algorithm
Let's review the A* algorithm before we proceed to implement it in the next section. The foundation of any pathfinding algorithm is a representation of the world. Pathfinding algorithms cannot search over the noisy structure of polygons in the game map; instead, we need to provide them with a simplified version of the world. Using this simplified structure, we can identify the locations that an agent can traverse, as well as the inaccessible ones.
There are many ways of doing this; however, for this example, we use one of the most straightforward solutions: a 2D grid. Therefore, we implement the GridManager
class to convert the "real" map into a 2D tile representation. The GridManager
class keeps a list of Node
objects representing a single tile in the 2D grid. First, of course, we need to implement the Node
class too: this class stores node information such as its position, whether it's a traversable node or an obstacle, the cost...