summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--res/scripts/common.lua9
-rw-r--r--res/scripts/underwater.lua1
-rw-r--r--res/scripts/underwater_start.lua1
-rw-r--r--src/animation_system.cpp11
-rw-r--r--src/script_system.cpp3
-rw-r--r--src/sprite.h2
6 files changed, 26 insertions, 1 deletions
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)
344 local sprite = getSprite(spriteId) 344 local sprite = getSprite(spriteId)
345 sprite.bobsWhenNormal = false 345 sprite.bobsWhenNormal = false
346end 346end
347
348--- Sets the animation slowdown for a sprite.
349-- @param spriteName the alias of the sprite to modify
350-- @param amount the number of animation frames needed to advance the sprite's animation (1 means the effect is disabled)
351function SetAnimationSlowdown(spriteName, amount)
352 local spriteId = getSpriteByAlias(spriteName)
353 local sprite = getSprite(spriteId)
354 sprite.animSlowdown = amount
355end
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 = {}
3function underwater.leave() 3function underwater.leave()
4 AllowCrouching() 4 AllowCrouching()
5 StopBobbing("lucas") 5 StopBobbing("lucas")
6 SetAnimationSlowdown("lucas", 1)
6end 7end
7 8
8function underwater.fish2() 9function 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 = {}
3function underwater_start.init() 3function underwater_start.init()
4 PreventCrouching() 4 PreventCrouching()
5 StartBobbing("lucas") 5 StartBobbing("lucas")
6 SetAnimationSlowdown("lucas", 2)
6end 7end
7 8
8function underwater_start.talk_to_fish1() 9function 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) {
120 sprite.animations[sprite.animationId].timerNum == timerNum && 120 sprite.animations[sprite.animationId].timerNum == timerNum &&
121 !sprite.animFinished && 121 !sprite.animFinished &&
122 !sprite.animPaused) { 122 !sprite.animPaused) {
123 if (sprite.animSlowdown > 1) {
124 sprite.animSlowdownProgress++;
125
126 if (sprite.animSlowdownProgress == sprite.animSlowdown) {
127 sprite.animSlowdownProgress = 0;
128 } else {
129 continue;
130 }
131 }
132
123 sprite.animationFrame++; 133 sprite.animationFrame++;
124 134
125 if (sprite.animationFrame >= sprite.animations[sprite.animationId].frameIndices.size()) { 135 if (sprite.animationFrame >= sprite.animations[sprite.animationId].frameIndices.size()) {
@@ -177,4 +187,5 @@ void AnimationSystem::updateAnimation(int spriteId) {
177 sprite.animationFrame = 0; 187 sprite.animationFrame = 0;
178 sprite.animFinished = false; 188 sprite.animFinished = false;
179 sprite.animPaused = false; 189 sprite.animPaused = false;
190 sprite.animSlowdownProgress = 0;
180} 191}
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) {
41 "paused", &Sprite::paused, 41 "paused", &Sprite::paused,
42 "clipping", &Sprite::clipping, 42 "clipping", &Sprite::clipping,
43 "cantCrouch", &Sprite::cantCrouch, 43 "cantCrouch", &Sprite::cantCrouch,
44 "bobsWhenNormal", &Sprite::bobsWhenNormal); 44 "bobsWhenNormal", &Sprite::bobsWhenNormal,
45 "animSlowdown", &Sprite::animSlowdown);
45 46
46 engine_.new_usertype<MessageSystem>( 47 engine_.new_usertype<MessageSystem>(
47 "message", 48 "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:
78 bool hasShadow = false; 78 bool hasShadow = false;
79 int bobAmount = 0; 79 int bobAmount = 0;
80 bool bobbingDown = false; 80 bool bobbingDown = false;
81 int animSlowdownProgress = 0;
81 82
82 // Animation (controls) 83 // Animation (controls)
83 bool normallyHasShadow = false; 84 bool normallyHasShadow = false;
84 bool animPaused = false; 85 bool animPaused = false;
85 bool bobbing = false; 86 bool bobbing = false;
87 int animSlowdown = 1; // Animation will only advance every X frames (so, 1 means it's disabled)
86 88
87 // Character 89 // Character
88 bool orientable = false; 90 bool orientable = false;