Time for action – beginning the implementation of A*
Add a new class called PathFinder to the Robot Rampage project.
Add the following
using
directive to the top of the class file:using Microsoft.Xna.Framework;
Modify the class declaration to make the class static:
static class PathFinder
Add declarations to the PathFinder class:
#region Declarations private enum NodeStatus { Open, Closed }; private static Dictionary<Vector2, NodeStatus> nodeStatus = new Dictionary<Vector2, NodeStatus>(); private const int CostStraight = 10; private const int CostDiagonal = 15; private static List<PathNode> openList = new List<PathNode>(); private static Dictionary<Vector2, float> nodeCosts = new Dictionary<Vector2, float>(); #endregion
Create a region in the PathFinder class for helper methods:
#region Helper Methods #endregion
Add the
addNodeToOpenList()
method to the Helper Methods region of the PathFinder class:static private void addNodeToOpenList(PathNode node...