public void HandleRunEvent(InputEvent moveEvent) { if (moveEvent.KeyEvent != ActionBindings.KeyEvent.KeyPressed) { return; } var moveComponent = ComponentManager.GetEntityComponentOrDefault <MoveComponent>(moveEvent.EntityId); if (moveComponent == null) { return; } var entityId = moveEvent.EntityId; var animationComponent = GetOrCreateDefault(entityId); var animation = new GeneralAnimation { AnimationType = SprintEventName, StartOfAnimation = moveEvent.EventTime, Unique = true, Length = 8000 }; AddNewSprintAnimation(animation, moveComponent, 2000); SetNewSprintMaxVelocity(moveComponent, VelocityBonus); animationComponent.Animations.Add(animation); }
private void AddNewSprintAnimation(GeneralAnimation generalAnimation, MoveComponent moveComponent, int sprintTime) { var previousMaxVelocity = moveComponent.MaxVelocitySpeed; var sprintIsDone = false; generalAnimation.Animation = delegate(double currentTime) { var elapsedTime = currentTime - generalAnimation.StartOfAnimation; if (elapsedTime > generalAnimation.Length) { generalAnimation.IsDone = true; return; } if (elapsedTime > sprintTime && !sprintIsDone) { sprintIsDone = true; moveComponent.MaxVelocitySpeed = previousMaxVelocity; moveComponent.Speed = (float)(moveComponent.MaxVelocitySpeed * 0.2); } }; }