private static void MoveHandler(object sender, SpriteMoveEventArgs mover) { if (mover.Sprite is Critter critter) { critter.ConsumeEnergy(mover.Distance * mover.Speed / movementEnergyConsumptionFactor); if (critter.moveCount-- == 0) { critter.IncrementFrame(); critter.moveCount = 5 - Math.Min(5, (int)mover.Speed); } } }
/// <summary> /// Calls the Move event and returns whether or not it was canceled. /// </summary> /// <remarks> /// Calls an event; call only when neccesary. /// </remarks> /// <param name="newPosition">The position to call the move event with.</param> /// <returns>Whether or not the called move event was cancelled.</returns> protected bool IsMoveEventCanceled(Vector2 newPosition) { bool cancel = false; if (Move != null) { SpriteMoveEventArgs args = new SpriteMoveEventArgs(_pos, newPosition); foreach (EventHandler <SpriteMoveEventArgs> tmp in Move.GetInvocationList()) { tmp(this, args); cancel = args.Cancel; } } return(cancel); }