public override void NotifyCloseToFood(int x, int y) { int newDirection = Critter.GetDirectionTo(x, y); Critter.Direction = newDirection; Critter.Speed = nominalSpeed; }
public override void NotifyCloseToFood(int x, int y) { if (!Critter.IsTerrainBlockingRouteTo(x, y)) { int newDirection = Critter.GetDirectionTo(x, y); Critter.Direction = newDirection; } }
//heads to exit if the path is not blocked private void HeadToExit() { if (!Critter.IsTerrainBlockingRouteTo(centreDestinationX, centreDestinationY)) { int direction = Critter.GetDirectionTo(centreDestinationX, centreDestinationY); Critter.Direction = direction; } }
private void Route() { { //Sets a time so it does not update the new direction before it has reached the old one lastCall = DateTime.Now; Critter.Direction = Critter.GetDirectionTo(Critter.X + xList[i], Critter.Y + yList[i]); // MessageBox.Show(Critter.Direction.ToString()); Critter.Speed = configuration.NominalSpeed; i++; } }
public override void NotifyCloseToFood(int x, int y) { //if food is nearby then head straight to it if (NotifyFood == 1) { if (!Critter.IsTerrainBlockingRouteTo(x, y)) { Critter.Direction = Critter.GetDirectionTo(x, y); } Critter.Speed = configuration.NominalSpeed; } }
public override void Think() { if (TimePast(lastCall) > 0.25) { Route(); } //The search and route should get the critter within a range of 50 to the exit, so once in range the critter should be able to see the exit and head there if (GetDistance(Critter.X, centreDestinationX, Critter.Y, centreDestinationY) <= 50) { Critter.Direction = Critter.GetDirectionTo(centreDestinationX, centreDestinationY); } }
public override void Think() { Rectangle destination = Critter.GetDestination(); int centreDestinationX = destination.X + destination.Width / 2; int centreDestinationY = destination.Y + destination.Height / 2; if (!Critter.IsTerrainBlockingRouteTo(centreDestinationX, centreDestinationY)) { int direction = Critter.GetDirectionTo(centreDestinationX, centreDestinationY); Critter.Direction = direction; Critter.Speed = nominalSpeed; } }
public override void Think() { if (Critter.Speed == 0) { this.SetSpeed(GetTarget().HasValue ? Config.RunSpeed : Config.WanderSpeed); } // Avoid poop, sort of? var poop = this.GetNearbyObjects(Constants.Poop); if (poop.Any()) { var closestPoop = this.GetClosest(poop); // Poop is *roughly* in front of critter if (Math.Abs(Critter.Direction - Critter.GetDirectionTo(closestPoop)) < 10) { Movement(); } } }
public override void Think() { IWorldObject[] scan = new IWorldObject[10]; scan = Critter.Scan(); Critter.Speed = configuration.NominalSpeed; for (int i = 0; i < scan.Length; i++) { int itemX = scan[i].X; int itemY = scan[i].Y; string itemType = scan[i].Type; if (itemType == "Poop") { //Causes the critter to stay still for two seconds if poop is within a certain distance //Will be recalled if poop has not despawned DateTime lastResponse = DateTime.Now; while (TimePast(lastResponse) < 2) { if (DrawLine(itemX, itemY) <= 50 && !Critter.IsTerrainBlockingRouteTo(itemX, itemY)) { ChangeDirection(30); Critter.Speed = 0; } } Critter.Speed = configuration.NominalSpeed; //rescan at end of loop as other things may have changed since scan = Critter.Scan(); } else if (itemType == "Food") { DateTime lastResponse = DateTime.Now; while (TimePast(lastResponse) < 2) { if (Critter.Energy <= 20) { if (!Critter.IsTerrainBlockingRouteTo(itemX, itemY)) { Critter.Direction = Critter.GetDirectionTo(itemX, itemY); } } //rescan at end of loop as other things may have changed since scan = Critter.Scan(); } } else if (itemType == "Critter") { if (DrawLine(itemX, itemY) < 25) { ChangeDirection(15); Critter.Speed = configuration.NominalSpeed; } } } if (!Critter.IsTerrainBlockingRouteTo(centreDestinationX, centreDestinationY)) { HeadToExit(); } else { //If the critter hasnt collided with the terrain for awhile it will head back right in hopes to find the end if (TimePast(lastTerrainCollision) > 4) { Critter.Direction = 90; } } }
private bool ObjectTypesInDirection(IEnumerable <string> types, int dir) => Critter .Scan() .Where(o => types.Contains(o.Type)) .Any(o => Math.Abs(dir - Critter.GetDirectionTo(o.X, o.Y)) < Config.AngularFudge);
public override void NotifyCloseToFood(int x, int y) { Critter.Direction = Critter.GetDirectionTo(x, y); }