private void Chase(Vector2 position, ref Creature prey, ref float orientation, float turnSpeed) { if (prey == null || prey.state == 4) { this.state = 0; return; } Vector2 preyPosition = prey.position; // we may want to include a flocking algorithm so multiple predators dont get stuck behind the same prey /* if (prey.Predator != null) { Vector2 otherPredPosition = position - prey.Predator.position; orientation = TurnToFace(position, otherPredPosition, orientation, .5f * turnSpeed); } */ orientation = TurnToFace(position, preyPosition, orientation, 0.75f * turnSpeed); }
private void Evade(Vector2 position, ref Creature pred, ref float orientation, float turnSpeed) { if (pred == null || pred.state == 4) { // it died this.state = 0; return; } Vector2 predPosition = pred.position; // bug here, because they can die now Vector2 seekPosition = 2 * position - predPosition; // optimal direction to run away (not very exciting) float distanceToGoal = Vector2.Distance(position, goalPosition); float distanceToPred = Vector2.Distance(position, pred.position); if (distanceToGoal < 200) { // assign a new random goal position randomGoal(mapWidth, mapHeight); } if (distanceToPred < 75) { // high priority choose optimal, can't have full turn speed orientation = TurnToFace(position, seekPosition, orientation, 3f * turnSpeed); } else { // choose random point to run to orientation = TurnToFace(position, goalPosition, orientation, 1.2f * turnSpeed); } }
public void reproduce(Creature parent) { creatures.Add(new Creature((short)parent.Position.X,(short)parent.Position.Y, stats, random,this)); }