Time for action - finding the path

  1. 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; } PathFinder classPathFinder classFindPath() method, addingopenList.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) { ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.