public void FindPath(Vector2 target) { var goal = TileEngine.GetTile(target); var position = Position; AStar breadth = new AStar(TileEngine.GetTile((int)position.x, (int)position.y), goal); var path = breadth.GetPath(goal); if (path != null) { foreach (var node in path) { Path.Enqueue(node.Position); } } }
public List <Tile> GetNeighbors(bool dinagonal = true) { List <Tile> neighbors = new List <Tile>(); Tile tile; tile = TileEngine.GetTile((int)Position.x - 1, (int)Position.y); if (tile != null) { neighbors.Add(tile); } tile = TileEngine.GetTile((int)Position.x + 1, (int)Position.y); if (tile != null) { neighbors.Add(tile); } tile = TileEngine.GetTile((int)Position.x, (int)Position.y - 1); if (tile != null) { neighbors.Add(tile); } tile = TileEngine.GetTile((int)Position.x, (int)Position.y + 1); if (tile != null) { neighbors.Add(tile); } if (dinagonal) { tile = TileEngine.GetTile((int)Position.x + 1, (int)Position.y + 1); if (tile != null) { neighbors.Add(tile); } tile = TileEngine.GetTile((int)Position.x - 1, (int)Position.y + 1); if (tile != null) { neighbors.Add(tile); } tile = TileEngine.GetTile((int)Position.x + 1, (int)Position.y - 1); if (tile != null) { neighbors.Add(tile); } tile = TileEngine.GetTile((int)Position.x - 1, (int)Position.y - 1); if (tile != null) { neighbors.Add(tile); } } return(neighbors); }