From c304defdd7b0c5a8bea83f2540c009ededd450cb Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 26 Feb 2021 19:08:49 -0500 Subject: Added animation slowdown effect (for Lucas underwater) --- src/animation_system.cpp | 11 +++++++++++ src/script_system.cpp | 3 ++- src/sprite.h | 2 ++ 3 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/animation_system.cpp b/src/animation_system.cpp index 5892f64..997b53a 100644 --- a/src/animation_system.cpp +++ b/src/animation_system.cpp @@ -120,6 +120,16 @@ void AnimationSystem::tick(double dt) { sprite.animations[sprite.animationId].timerNum == timerNum && !sprite.animFinished && !sprite.animPaused) { + if (sprite.animSlowdown > 1) { + sprite.animSlowdownProgress++; + + if (sprite.animSlowdownProgress == sprite.animSlowdown) { + sprite.animSlowdownProgress = 0; + } else { + continue; + } + } + sprite.animationFrame++; if (sprite.animationFrame >= sprite.animations[sprite.animationId].frameIndices.size()) { @@ -177,4 +187,5 @@ void AnimationSystem::updateAnimation(int spriteId) { sprite.animationFrame = 0; sprite.animFinished = false; sprite.animPaused = false; + sprite.animSlowdownProgress = 0; } diff --git a/src/script_system.cpp b/src/script_system.cpp index e218969..18a4e39 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp @@ -41,7 +41,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { "paused", &Sprite::paused, "clipping", &Sprite::clipping, "cantCrouch", &Sprite::cantCrouch, - "bobsWhenNormal", &Sprite::bobsWhenNormal); + "bobsWhenNormal", &Sprite::bobsWhenNormal, + "animSlowdown", &Sprite::animSlowdown); engine_.new_usertype( "message", diff --git a/src/sprite.h b/src/sprite.h index 570a906..733c792 100644 --- a/src/sprite.h +++ b/src/sprite.h @@ -78,11 +78,13 @@ public: bool hasShadow = false; int bobAmount = 0; bool bobbingDown = false; + int animSlowdownProgress = 0; // Animation (controls) bool normallyHasShadow = false; bool animPaused = false; bool bobbing = false; + int animSlowdown = 1; // Animation will only advance every X frames (so, 1 means it's disabled) // Character bool orientable = false; -- cgit 1.4.1