diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/animation_system.cpp | 19 | ||||
-rw-r--r-- | src/animation_system.h | 1 | ||||
-rw-r--r-- | src/character_system.cpp | 3 | ||||
-rw-r--r-- | src/renderer.cpp | 3 | ||||
-rw-r--r-- | src/script_system.cpp | 3 | ||||
-rw-r--r-- | src/sprite.h | 8 |
6 files changed, 35 insertions, 2 deletions
diff --git a/src/animation_system.cpp b/src/animation_system.cpp index baf94a4..5892f64 100644 --- a/src/animation_system.cpp +++ b/src/animation_system.cpp | |||
@@ -134,6 +134,25 @@ void AnimationSystem::tick(double dt) { | |||
134 | } | 134 | } |
135 | } | 135 | } |
136 | } | 136 | } |
137 | |||
138 | bobbingTimer_.accumulate(dt); | ||
139 | while (bobbingTimer_.step()) { | ||
140 | for (Sprite& sprite : game_.getSprites() | game_.spriteView()) { | ||
141 | if (sprite.isAnimated && sprite.bobbing) { | ||
142 | if (sprite.bobbingDown) { | ||
143 | sprite.bobAmount--; | ||
144 | if (sprite.bobAmount == 0) { | ||
145 | sprite.bobbingDown = false; | ||
146 | } | ||
147 | } else { | ||
148 | sprite.bobAmount++; | ||
149 | if (sprite.bobAmount == 4) { | ||
150 | sprite.bobbingDown = true; | ||
151 | } | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | } | ||
137 | } | 156 | } |
138 | 157 | ||
139 | void AnimationSystem::setSpriteDirection(int spriteId, Direction dir) { | 158 | void AnimationSystem::setSpriteDirection(int spriteId, Direction dir) { |
diff --git a/src/animation_system.h b/src/animation_system.h index c64c2dc..42aa516 100644 --- a/src/animation_system.h +++ b/src/animation_system.h | |||
@@ -30,6 +30,7 @@ private: | |||
30 | 30 | ||
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 | }; | 34 | }; |
34 | 35 | ||
35 | #endif /* end of include guard: ANIMATION_SYSTEM_H_CCCC7CB8 */ | 36 | #endif /* end of include guard: ANIMATION_SYSTEM_H_CCCC7CB8 */ |
diff --git a/src/character_system.cpp b/src/character_system.cpp index 87407af..9b91716 100644 --- a/src/character_system.cpp +++ b/src/character_system.cpp | |||
@@ -332,12 +332,14 @@ void CharacterSystem::setAnimationFor(int spriteId, CharacterState state) { | |||
332 | 332 | ||
333 | game_.getSystem<AnimationSystem>().setSpriteAnimation(spriteId, animName); | 333 | game_.getSystem<AnimationSystem>().setSpriteAnimation(spriteId, animName); |
334 | sprite.hasShadow = sprite.normallyHasShadow; | 334 | sprite.hasShadow = sprite.normallyHasShadow; |
335 | sprite.bobbing = sprite.bobsWhenNormal; | ||
335 | 336 | ||
336 | break; | 337 | break; |
337 | } | 338 | } |
338 | case CharacterMedium::Ladder: { | 339 | case CharacterMedium::Ladder: { |
339 | game_.getSystem<AnimationSystem>().setSpriteAnimation(spriteId, "climb"); | 340 | game_.getSystem<AnimationSystem>().setSpriteAnimation(spriteId, "climb"); |
340 | sprite.hasShadow = false; | 341 | sprite.hasShadow = false; |
342 | sprite.bobbing = false; | ||
341 | 343 | ||
342 | if (state == CharacterState::Still || state == CharacterState::Crouching) { | 344 | if (state == CharacterState::Still || state == CharacterState::Crouching) { |
343 | sprite.animPaused = true; | 345 | sprite.animPaused = true; |
@@ -355,6 +357,7 @@ void CharacterSystem::setAnimationFor(int spriteId, CharacterState state) { | |||
355 | 357 | ||
356 | game_.getSystem<AnimationSystem>().setSpriteAnimation(spriteId, animName); | 358 | game_.getSystem<AnimationSystem>().setSpriteAnimation(spriteId, animName); |
357 | sprite.hasShadow = false; | 359 | sprite.hasShadow = false; |
360 | sprite.bobbing = false; | ||
358 | 361 | ||
359 | break; | 362 | break; |
360 | } | 363 | } |
diff --git a/src/renderer.cpp b/src/renderer.cpp index 1196e50..3007378 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp | |||
@@ -115,6 +115,9 @@ void Renderer::renderSprite(const Sprite& sprite) { | |||
115 | const SpriteFrame& frame = sprite.frames.at(sprite.animations.at(sprite.animationId).frameIndices.at(sprite.animationFrame)); | 115 | const SpriteFrame& frame = sprite.frames.at(sprite.animations.at(sprite.animationId).frameIndices.at(sprite.animationFrame)); |
116 | const SDL_Rect& src = frame.srcRect; | 116 | const SDL_Rect& src = frame.srcRect; |
117 | SDL_Rect dest { sprite.loc.x() - frame.center.x(), sprite.loc.y() - frame.center.y(), frame.size.w(), frame.size.h() }; | 117 | SDL_Rect dest { sprite.loc.x() - frame.center.x(), sprite.loc.y() - frame.center.y(), frame.size.w(), frame.size.h() }; |
118 | if (sprite.bobbing) { | ||
119 | dest.y -= sprite.bobAmount; | ||
120 | } | ||
118 | SDL_RenderCopy(ren_.get(), textures_.at(loadImageFromFile(sprite.spritesheet)).get(), &src, &dest); | 121 | SDL_RenderCopy(ren_.get(), textures_.at(loadImageFromFile(sprite.spritesheet)).get(), &src, &dest); |
119 | } | 122 | } |
120 | } | 123 | } |
diff --git a/src/script_system.cpp b/src/script_system.cpp index 92e6afe..e218969 100644 --- a/src/script_system.cpp +++ b/src/script_system.cpp | |||
@@ -40,7 +40,8 @@ ScriptSystem::ScriptSystem(Game& game) : game_(game) { | |||
40 | "persistent", &Sprite::persistent, | 40 | "persistent", &Sprite::persistent, |
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 | 45 | ||
45 | engine_.new_usertype<MessageSystem>( | 46 | engine_.new_usertype<MessageSystem>( |
46 | "message", | 47 | "message", |
diff --git a/src/sprite.h b/src/sprite.h index 657a692..570a906 100644 --- a/src/sprite.h +++ b/src/sprite.h | |||
@@ -64,7 +64,7 @@ public: | |||
64 | std::string walkthroughScript; | 64 | std::string walkthroughScript; |
65 | std::string enclosureZone; | 65 | std::string enclosureZone; |
66 | 66 | ||
67 | // Animation | 67 | // Animation (internals) |
68 | bool isAnimated = false; | 68 | bool isAnimated = false; |
69 | std::string spritesheet; | 69 | std::string spritesheet; |
70 | Direction dir = Direction::down; | 70 | Direction dir = Direction::down; |
@@ -76,8 +76,13 @@ public: | |||
76 | std::map<std::string, std::map<Direction, int>> nameDirToAnim; | 76 | std::map<std::string, std::map<Direction, int>> nameDirToAnim; |
77 | bool animFinished = false; | 77 | bool animFinished = false; |
78 | bool hasShadow = false; | 78 | bool hasShadow = false; |
79 | int bobAmount = 0; | ||
80 | bool bobbingDown = false; | ||
81 | |||
82 | // Animation (controls) | ||
79 | bool normallyHasShadow = false; | 83 | bool normallyHasShadow = false; |
80 | bool animPaused = false; | 84 | bool animPaused = false; |
85 | bool bobbing = false; | ||
81 | 86 | ||
82 | // Character | 87 | // Character |
83 | bool orientable = false; | 88 | bool orientable = false; |
@@ -92,6 +97,7 @@ public: | |||
92 | int runningSfxChannel = -1; | 97 | int runningSfxChannel = -1; |
93 | bool clipping = false; | 98 | bool clipping = false; |
94 | bool cantCrouch = false; // Use this to prevent running | 99 | bool cantCrouch = false; // Use this to prevent running |
100 | bool bobsWhenNormal = false; // If enabled, sets the animation bobbing flag whenever medium is Normal | ||
95 | 101 | ||
96 | // Input | 102 | // Input |
97 | bool controllable = false; | 103 | bool controllable = false; |