diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-13 20:50:21 -0500 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2021-02-13 20:50:21 -0500 |
commit | 470b1d43fb6f8e17624ee90f87270de5bd6ff77e (patch) | |
tree | 966f1e18d496f12c3273684be299573e4bf443ec /src/animation_system.cpp | |
parent | ed933607765a6e010689aaaf85184053ff6e8a2b (diff) | |
download | tanetane-470b1d43fb6f8e17624ee90f87270de5bd6ff77e.tar.gz tanetane-470b1d43fb6f8e17624ee90f87270de5bd6ff77e.tar.bz2 tanetane-470b1d43fb6f8e17624ee90f87270de5bd6ff77e.zip |
Added lightning sprite to mailbox event
Sprites can be destroyed now, which really just means that their index is removed from the list of active sprites. The actual memory is not freed until all sprites are deleted on map change. Sprite layers are introduced. All sprites by default are on layer 0 (Normal) which renders them in between the lower and upper map layers. There is also a layer 1 (Above) that renders above the upper map layer, and the sprite for the lightning strike uses this layer in order to not be hidden by the trees. Fixed a bug where waiting for the end of a non-looping animation would trip the flag immediately upon the final frame activating, instead of waiting the length of the last frame.
Diffstat (limited to 'src/animation_system.cpp')
-rw-r--r-- | src/animation_system.cpp | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/src/animation_system.cpp b/src/animation_system.cpp index 3f3f22a..c43d0ca 100644 --- a/src/animation_system.cpp +++ b/src/animation_system.cpp | |||
@@ -65,7 +65,7 @@ void AnimationSystem::initSprite(int spriteId, std::string_view filename) { | |||
65 | std::string animLine; | 65 | std::string animLine; |
66 | std::getline(datafile, animLine); // blank | 66 | std::getline(datafile, animLine); // blank |
67 | while (std::getline(datafile, animLine)) { | 67 | while (std::getline(datafile, animLine)) { |
68 | std::regex re(R"(([a-z!]+)\[([a-z_]+)\]: ([0-9,]+))"); | 68 | std::regex re(R"(([a-z!_]+)\[([a-z_]+)\]: ([0-9,]+))"); |
69 | std::smatch m; | 69 | std::smatch m; |
70 | std::regex_match(animLine, m, re); | 70 | std::regex_match(animLine, m, re); |
71 | 71 | ||
@@ -96,14 +96,13 @@ void AnimationSystem::tick(double dt) { | |||
96 | for (Sprite& sprite : game_.getSprites() | game_.spriteView()) { | 96 | for (Sprite& sprite : game_.getSprites() | game_.spriteView()) { |
97 | if (sprite.isAnimated && !sprite.animFinished) { | 97 | if (sprite.isAnimated && !sprite.animFinished) { |
98 | sprite.animationFrame++; | 98 | sprite.animationFrame++; |
99 | if (sprite.animations[sprite.animationId].looping) { | 99 | |
100 | if (sprite.animationFrame >= sprite.animations[sprite.animationId].frameIndices.size()) { | 100 | if (sprite.animationFrame >= sprite.animations[sprite.animationId].frameIndices.size()) { |
101 | if (sprite.animations[sprite.animationId].looping) { | ||
101 | sprite.animationFrame = 0; | 102 | sprite.animationFrame = 0; |
102 | } | 103 | } else { |
103 | } else { | ||
104 | if (sprite.animationFrame >= sprite.animations[sprite.animationId].frameIndices.size() - 1) { | ||
105 | sprite.animationFrame = sprite.animations[sprite.animationId].frameIndices.size() - 1; | ||
106 | sprite.animFinished = true; | 104 | sprite.animFinished = true; |
105 | sprite.animationFrame = sprite.animations[sprite.animationId].frameIndices.size() - 1; | ||
107 | } | 106 | } |
108 | } | 107 | } |
109 | } | 108 | } |