public void MoveTo(Point destination) { if (destination.X < 0 || destination.Y < 0 || destination.X >= layer.Width() || destination.Y >= layer.Height() || !layer.IsPassable(destination) || Moving) { return; } destinations = new Queue <Point>(); List <Point> points = layer.Pathfind.FindPath(position, destination, Group); for (int i = 0; i < points.Count(); ++i) { if (CanMoveThrough(points[i])) { destinations.Enqueue(points[i]); } else { break; } } if (destinations.Count() > 0) { moveDest = destinations.Dequeue(); moving = true; elapsed = toMove; } }
public Pathfinder(TileLayer layer) { levelWidth = layer.Width(); levelHeight = layer.Height(); this.layer = layer; InitializeSearchNodes(layer); }
private void clamp() { if (location.X < 0) { location.X = 0; } if (location.Y < 0) { location.Y = 0; } if (location.X >= layer.Width()) { location.X = layer.Width() - 1; } if (location.Y >= layer.Height()) { location.Y = layer.Height() - 1; } }