public override void Do(Entity entity) { double squaredDistance = Utilities.SquaredDistance(entity.Position, fleeObject.Position); if (squaredDistance < entity.VisionRange * entity.VisionRange) { double x = entity.Position.X + entity.Position.X - fleeObject.Position.X; double y = entity.Position.Y + entity.Position.Y - fleeObject.Position.Y; activeAction = new GotoAction(x, y, entity.Size); activeAction.Do(entity); } else { entity.ApplyNeedDeltas(UtilityDeltas); End(); } if (activeAction != null && activeAction.State == ActionState.Failure) // If the entity has hit a wall while running away, head to a random point. { OrderedPair <int> randomPoint = Utilities.GetDirectionalPoint(entity.CollisionDirection, entity.Position); activeAction = new GotoAction(randomPoint.X, randomPoint.Y, entity.Size); } }
public override void DoWithTime(Entity entity, GameTime time) { if (!started) { // Make entity get close to mate. if (Math.Sqrt(Utilities.SquaredDistance(entity.Position, mate.Position)) > Person.mateRange) { entity.Goto(mate.Position.X, mate.Position.Y); return; } else { ((Person)entity).MateWith(mate); started = true; } } if (!timerEnabled) { StartWaitTimer(entity, time); } if (time >= stopTime) { ((Person)entity).ReproduceWith(mate); Release(entity); } entity.ApplyNeedDeltas(UtilityDeltas); mate.ApplyNeedDeltas(UtilityDeltas); }
public override void Do(Entity entity) { if (Math.Sqrt(Utilities.SquaredDistance(entity.Position, target.Position)) > entity.AttackRange) { entity.Goto(target.Position.X, target.Position.Y); } else { entity.Attack((IMortal)target); End(); entity.ApplyNeedDeltas(UtilityDeltas); } }
public override void Do(Entity entity) { if (Utilities.SquaredDistance(entity.Position, basePosition) > distance * distance) // If too far away, move closer. { entity.Goto(basePosition.X, basePosition.Y); } else // Otherwise stop. { Console.WriteLine($"GameObject {entity.ObjectID} guarding house"); entity.Stop(); entity.ApplyNeedDeltas(UtilityDeltas); } }
public override void Do(Entity entity) { double distance = Math.Sqrt(Utilities.SquaredDistance(entity.Position, target.Position)); if (distance > 30) { entity.GotoWithDistance(target.Position.X + dx, target.Position.Y + dy, 30); } else if (distance > entity.VisionRange) { End(); } else { entity.ApplyNeedDeltas(UtilityDeltas); } }
public void DoWithSearchAndTime(Entity entity, ObjectMesh objectMesh, GameTime time) { if (timerEnabled && stopTime != null) { if (time >= stopTime) { entity.SetCanMove(true); End(); } return; } if (entity is Person person) { int range = Person.mateRange; int mateRangeSquared = Person.mateRange * Person.mateRange; // Search all nearbyObjects for people to mate with. Then mate with all of them that are in range. List <GameObject> nearbyObjects = objectMesh.GetObjectsInRange(person.Position.X, person.Position.Y, range); foreach (GameObject gameObject in nearbyObjects) { if (gameObject is Person mate && mate.Sex != person.Sex && !person.IsPregnant && !mate.IsPregnant && Utilities.SquaredDistance(person.Position, mate.Position) < mateRangeSquared) { person.ReproduceWith(mate); // Start timer. Initialize stopTime to the current time plus x number of seconds. Start checking time to allow player to move. if (!timerEnabled) { timerEnabled = true; person.SetCanMove(false); stopTime = time.Copy(); stopTime.AddSeconds(Person.mateTime); } } } } if (!timerEnabled) { End(); } }