From c1fc60c5a2a4b96b830afc29942648714944b9d7 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Fri, 26 Feb 2021 18:54:38 -0500 Subject: Added sprite bobbing (for Lucas underwater) --- src/animation_system.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/animation_system.cpp') 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) { } } } + + bobbingTimer_.accumulate(dt); + while (bobbingTimer_.step()) { + for (Sprite& sprite : game_.getSprites() | game_.spriteView()) { + if (sprite.isAnimated && sprite.bobbing) { + if (sprite.bobbingDown) { + sprite.bobAmount--; + if (sprite.bobAmount == 0) { + sprite.bobbingDown = false; + } + } else { + sprite.bobAmount++; + if (sprite.bobAmount == 4) { + sprite.bobbingDown = true; + } + } + } + } + } } void AnimationSystem::setSpriteDirection(int spriteId, Direction dir) { -- cgit 1.4.1