#ifndef GRAPHICS_ANIMATION_H #define GRAPHICS_ANIMATION_H #include namespace Graphics{ class Animation{ protected: int i_; int count_; int row_; int lastTime_; int switchTime_; unsigned int w_, h_; sf::IntRect rect_; sf::Texture texture_; bool ticked(int deltaTime); public: Animation(); ~Animation(); Animation(const sf::Texture& texture, int count, int switchTime, int height, int width, int row); 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; virtual sf::IntRect& next(int deltaTime) override; bool finished() override; }; class BouncingAnimation : public Animation{ private: bool up_; public: using Animation::Animation; ~BouncingAnimation(); virtual sf::IntRect& next(int deltaTime) override; }; template class FlippedAnimation : public T{ static_assert(std::is_base_of::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