public Point GetAnimalNextWaypoint(Point startPoint, Point destinationPoint, MovingType movingType) { int resultX = 0, resultY = 0, speed; double distance; speed = _field.Animals[startPoint.Y, startPoint.X].Speed; distance = _distanceHandler.GetDistance(startPoint, destinationPoint); if (movingType == MovingType.Pursuit) { resultX = startPoint.X + CountPositionDelta(startPoint.X, destinationPoint.X, speed, distance); resultY = startPoint.Y + CountPositionDelta(startPoint.Y, destinationPoint.Y, speed, distance); } else if (movingType == MovingType.Runaway) { resultX = startPoint.X - CountPositionDelta(startPoint.X, destinationPoint.X, speed, distance); resultY = startPoint.Y - CountPositionDelta(startPoint.Y, destinationPoint.Y, speed, distance); } int CountPositionDelta(int from, int to, int animalSpeed, double distanceToPoint) { return((int)Math.Round((to - from) * animalSpeed / distanceToPoint)); } return(new Point(resultX, resultY)); }
public Point SelectNearestAnimalByType(Point position, AnimalType searchingAnimalType) { List <Point> animals = FindNearestAnimals(position); Point nearestAnimal = new Point(-1, -1); foreach (Point animal in animals) { if (_field.Animals[animal.Y, animal.X].Type == searchingAnimalType) { if (nearestAnimal.X == -1) { nearestAnimal = animal; } else if (_distanceHandler.GetDistance(position, animal) < _distanceHandler.GetDistance(position, nearestAnimal)) { nearestAnimal = animal; } } } return(nearestAnimal); }