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) ||
            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 ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.