From e4e2f2d2a7b6a282b9618aa0004d9453936f43c6 Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 18 Feb 2018 15:25:52 -0500 Subject: Added player death and event scheduling Also added ability to make sprites flicker, to freeze physics for an entity, and to freeze progression of a sprite's animation loop. --- src/systems/animating.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/systems/animating.cpp') diff --git a/src/systems/animating.cpp b/src/systems/animating.cpp index 22224c9..634af67 100644 --- a/src/systems/animating.cpp +++ b/src/systems/animating.cpp @@ -13,7 +13,10 @@ void AnimatingSystem::tick(double) auto& sprite = game_.getEntityManager(). getComponent(entity); - sprite.setCountdown(sprite.getCountdown() + 1); + if (!sprite.isFrozen()) + { + sprite.setCountdown(sprite.getCountdown() + 1); + } const Animation& anim = sprite.getAnimation(); if (sprite.getCountdown() >= anim.getDelay()) @@ -26,6 +29,11 @@ void AnimatingSystem::tick(double) sprite.setFrame(anim.getFirstFrame()); } } + + if (sprite.isFlickering()) + { + sprite.setFlickerTimer((sprite.getFlickerTimer() + 1) % 6); + } } } @@ -44,6 +52,12 @@ void AnimatingSystem::render(Texture& texture) auto& transform = game_.getEntityManager(). getComponent(entity); + double alpha = 1.0; + if (sprite.isFlickering() && (sprite.getFlickerTimer() < 3)) + { + alpha = 0.0; + } + Rectangle dstrect { static_cast(transform.getX()), static_cast(transform.getY()), @@ -55,7 +69,8 @@ void AnimatingSystem::render(Texture& texture) aset.getTexture(), texture, aset.getFrameRect(sprite.getFrame()), - dstrect); + dstrect, + alpha); } } -- cgit 1.4.1