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 void DoActionOnce(EntityAction action) { action.Do(this); }
public void ForceAction(Entity entity, EntityAction action) { action.Do(entity); }