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) --- res/scripts/common.lua | 9 +++++++++ res/scripts/underwater.lua | 1 + res/scripts/underwater_start.lua | 1 + src/animation_system.cpp | 11 +++++++++++ src/script_system.cpp | 3 ++- src/sprite.h | 2 ++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/res/scripts/common.lua b/res/scripts/common.lua index 825d2e5..2a51419 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua @@ -344,3 +344,12 @@ function StopBobbing(spriteName) local sprite = getSprite(spriteId) sprite.bobsWhenNormal = false end + +--- Sets the animation slowdown for a sprite. +-- @param spriteName the alias of the sprite to modify +-- @param amount the number of animation frames needed to advance the sprite's animation (1 means the effect is disabled) +function SetAnimationSlowdown(spriteName, amount) + local spriteId = getSpriteByAlias(spriteName) + local sprite = getSprite(spriteId) + sprite.animSlowdown = amount +end diff --git a/res/scripts/underwater.lua b/res/scripts/underwater.lua index 3500079..8e1ae1a 100644 --- a/res/scripts/underwater.lua +++ b/res/scripts/underwater.lua @@ -3,6 +3,7 @@ underwater = {} function underwater.leave() AllowCrouching() StopBobbing("lucas") + SetAnimationSlowdown("lucas", 1) end function underwater.fish2() diff --git a/res/scripts/underwater_start.lua b/res/scripts/underwater_start.lua index c14f4b8..0852885 100644 --- a/res/scripts/underwater_start.lua +++ b/res/scripts/underwater_start.lua @@ -3,6 +3,7 @@ underwater_start = {} function underwater_start.init() PreventCrouching() StartBobbing("lucas") + SetAnimationSlowdown("lucas", 2) end function underwater_start.talk_to_fish1() 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