diff options
Diffstat (limited to 'src/graphics')
-rw-r--r-- | src/graphics/animation.h | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/graphics/animation.h b/src/graphics/animation.h index 010a64a..583da8a 100644 --- a/src/graphics/animation.h +++ b/src/graphics/animation.h @@ -24,12 +24,19 @@ namespace Graphics{ virtual sf::IntRect& next(int deltaTime); virtual void reset(); virtual bool finished(); + static sf::Sprite& flip(sf::Sprite &sprite){ + sf::IntRect frame = sprite.getTextureRect(); + frame.left += frame.width; + frame.width *= -1; + sprite.setTextureRect(frame); + return sprite; + }; }; class OneShotAnimation : public Animation { public: using Animation::Animation; - sf::IntRect& next(int deltaTime) override; + virtual sf::IntRect& next(int deltaTime) override; bool finished() override; }; @@ -39,7 +46,21 @@ namespace Graphics{ public: using Animation::Animation; ~BouncingAnimation(); - sf::IntRect& next(int deltaTime) override; + virtual sf::IntRect& next(int deltaTime) override; + }; + + template <class T> + class FlippedAnimation : public T{ + static_assert(std::is_base_of<Animation, T>::value, + "Base class of FlippedAnimation is not an Animation"); + public: + using T::T; + sf::IntRect& next(int deltaTime) override{ + T::next(deltaTime); + T::rect_.left = (T::i_ + 1) * T::w_; + T::rect_.width = -T::w_; + return T::rect_; + } }; } #endif // GRAPHICS_ANIMATION_H |