summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2021-07-05 10:39:06 -0400
committerStar Rauchenberger <fefferburbia@gmail.com>2021-07-05 10:39:06 -0400
commitd983ef6b8d66d916ed7502cf6d35b573c5366257 (patch)
tree2a98734180fc64f66a8623dc5c0d70b178e7b5af
parent35fffb8cf13258a4ff36a3bf56751e106c954a71 (diff)
downloadtanetane-d983ef6b8d66d916ed7502cf6d35b573c5366257.tar.gz
tanetane-d983ef6b8d66d916ed7502cf6d35b573c5366257.tar.bz2
tanetane-d983ef6b8d66d916ed7502cf6d35b573c5366257.zip
Added fading in/out sprites
-rw-r--r--res/scripts/common.lua14
-rw-r--r--src/animation_system.cpp19
-rw-r--r--src/animation_system.h1
-rw-r--r--src/script_system.cpp3
-rw-r--r--src/sprite.h3
5 files changed, 38 insertions, 2 deletions
diff --git a/res/scripts/common.lua b/res/scripts/common.lua index e355a32..2e95f26 100644 --- a/res/scripts/common.lua +++ b/res/scripts/common.lua
@@ -423,6 +423,20 @@ function SetOpacity(spriteName, amount)
423 sprite.opacity = amount 423 sprite.opacity = amount
424end 424end
425 425
426--- Fades out the given sprite.
427function FadeOutSprite(spriteName)
428 local spriteId = getSpriteByAlias(spriteName)
429 local sprite = getSprite(spriteId)
430 sprite.shouldBeFadedIn = false
431end
432
433--- Fades out the given sprite.
434function FadeInSprite(spriteName)
435 local spriteId = getSpriteByAlias(spriteName)
436 local sprite = getSprite(spriteId)
437 sprite.shouldBeFadedIn = true
438end
439
426--- Sets the enclosure zone for a sprite. 440--- Sets the enclosure zone for a sprite.
427-- The sprite will be prevented from exiting the area defined by that zone. 441-- The sprite will be prevented from exiting the area defined by that zone.
428function AddEnclosureZone(spriteName, zone) 442function AddEnclosureZone(spriteName, zone)
diff --git a/src/animation_system.cpp b/src/animation_system.cpp index ce5cc02..73d30d5 100644 --- a/src/animation_system.cpp +++ b/src/animation_system.cpp
@@ -166,6 +166,25 @@ void AnimationSystem::tick(double dt) {
166 } 166 }
167 } 167 }
168 } 168 }
169
170 fadingTimer_.accumulate(dt);
171 while (fadingTimer_.step()) {
172 for (Sprite& sprite : game_.getSprites() | game_.spriteView()) {
173 if (sprite.isAnimated) {
174 if (sprite.shouldBeFadedIn && sprite.opacity < 1.0) {
175 sprite.opacity += 0.05;
176 if (sprite.opacity > 1.0) {
177 sprite.opacity = 1.0;
178 }
179 } else if (!sprite.shouldBeFadedIn && sprite.opacity > 0.0) {
180 sprite.opacity -= 0.05;
181 if (sprite.opacity < 0.0) {
182 sprite.opacity = 0.0;
183 }
184 }
185 }
186 }
187 }
169} 188}
170 189
171void AnimationSystem::setSpriteDirection(int spriteId, Direction dir) { 190void AnimationSystem::setSpriteDirection(int spriteId, Direction dir) {
diff --git a/src/animation_system.h b/src/animation_system.h index 42aa516..7474c54 100644 --- a/src/animation_system.h +++ b/src/animation_system.h
@@ -31,6 +31,7 @@ private:
31 Game& game_; 31 Game& game_;
32 std::vector<Timer> animTimers_ = {{1000/5}, {1000/60}};//30fps * 1000 t/s;; 32 std::vector<Timer> animTimers_ = {{1000/5}, {1000/60}};//30fps * 1000 t/s;;
33 Timer bobbingTimer_ {1000/7}; 33 Timer bobbingTimer_ {1000/7};
34 Timer fadingTimer_ {1000/60};
34}; 35};
35 36
36#endif /* end of include guard: ANIMATION_SYSTEM_H_CCCC7CB8 */ 37#endif /* end of include guard: ANIMATION_SYSTEM_H_CCCC7CB8 */
diff --git a/src/script_system.cpp b/src/script_system.cpp index 56a6012..b4a7b9b 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp
@@ -56,7 +56,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) {
56 "behaviourType", &Sprite::behaviourType, 56 "behaviourType", &Sprite::behaviourType,
57 "followSpriteId", &Sprite::followSpriteId, 57 "followSpriteId", &Sprite::followSpriteId,
58 "interactionScript", &Sprite::interactionScript, 58 "interactionScript", &Sprite::interactionScript,
59 "opacity", &Sprite::opacity); 59 "opacity", &Sprite::opacity,
60 "shouldBeFadedIn", &Sprite::shouldBeFadedIn);
60 61
61 engine_.new_usertype<MessageSystem>( 62 engine_.new_usertype<MessageSystem>(
62 "message", 63 "message",
diff --git a/src/sprite.h b/src/sprite.h index 782ae14..e7cb55b 100644 --- a/src/sprite.h +++ b/src/sprite.h
@@ -100,13 +100,14 @@ public:
100 int bobAmount = 0; 100 int bobAmount = 0;
101 bool bobbingDown = false; 101 bool bobbingDown = false;
102 int animSlowdownProgress = 0; 102 int animSlowdownProgress = 0;
103 double opacity = 1.0;
104 103
105 // Animation (controls) 104 // Animation (controls)
106 bool normallyHasShadow = false; 105 bool normallyHasShadow = false;
107 bool animPaused = false; 106 bool animPaused = false;
108 bool bobbing = false; 107 bool bobbing = false;
109 int animSlowdown = 1; // Animation will only advance every X frames (so, 1 means it's disabled) 108 int animSlowdown = 1; // Animation will only advance every X frames (so, 1 means it's disabled)
109 double opacity = 1.0;
110 bool shouldBeFadedIn = true;
110 111
111 // Character 112 // Character
112 bool orientable = false; 113 bool orientable = false;