// returns accessible nodes adjacent to this node public override List <Node2D <W> > GetNeighbors() { List <Node2D <W> > neighbors = new List <Node2D <W> >(); // look at neighbors 1 spot away for (int dx = -1; dx <= 1; dx++) { for (int dy = -1; dy <= 1; dy++) { // skip this node's coordinates if (dx == 0 && dy == 0) { continue; } // create node Node2D <W> neighbor = new Node2D <W>(X + dx, Y + dy, _world); // if this node can be traveled to, add it to the list // KEEP IN MIND THAT THE ALGORITHM SEARCHES FROM FINISH TO START POSITION // THEREFORE, IF YOU WANT TO SEE IF YOU CAN GO FROM TILE A TO TILE B // YOU NEED TO CALL "_conditions.CanGo(B, A)" INSTEAD if (_conditions.CanGo(neighbor, this)) { neighbor.SetTravelConditions(_conditions); neighbor.SetParent(this); neighbors.Add(neighbor); } } } // return list of neighbors return(neighbors); }
public Queue <Node2D <W> > FindPath(Node2D <W> start, Node2D <W> finish, PathConditions <W> conditions) { start.SetTravelConditions(conditions); finish.SetTravelConditions(conditions); return(_pathfinder.FindPath(start, finish, _type)); }