Time for action – finding the path
Add the
FindPath()
method to the PathFinder class:#region Public Methods static public List<Vector2> FindPath( Vector2 startTile, Vector2 endTile) { if (TileMap.IsWallTile(endTile) || TileMap.IsWallTile(startTile)) { return null; } openList.Clear(); nodeCosts.Clear(); nodeStatus.Clear(); PathNode startNode; PathNode endNode; endNode = new PathNode(null, null, endTile, 0); startNode = new PathNode(null, endNode, startTile, 0); addNodeToOpenList(startNode); while (openList.Count > 0) { PathNode currentNode = openList[openList.Count - 1]; if (currentNode.IsEqualToNode(endNode)) { List<Vector2> bestPath = new List<Vector2>(); while (currentNode != null) { bestPath.Insert(0, currentNode.GridLocation); currentNode = currentNode.ParentNode; } return...