summaryrefslogtreecommitdiff
path: root/src/graphics/animation.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/graphics/animation.h')
-rw-r--r--src/graphics/animation.h70
1 files changed, 18 insertions, 52 deletions
diff --git a/src/graphics/animation.h b/src/graphics/animation.h
index 583da8a..04bf9ff 100644
--- a/src/graphics/animation.h
+++ b/src/graphics/animation.h
@@ -2,65 +2,31 @@
#define GRAPHICS_ANIMATION_H
#include <SFML/Graphics.hpp>
+#include <cstddef>
namespace Graphics{
- class Animation{
+ class Animation : public sf::Drawable, sf::Transformable{
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;
- };
- };
+ sf::Sprite sprite_;
+ sf::Vector2i frameSize_;
+ std::size_t numFrames_;
+ std::size_t currentFrame_;
+ std::size_t row_;
+ sf::Time duration_;
+ sf::Time elapsedTime_;
+ bool repeat_;
- 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;
+ Animation();
+ Animation(const sf::Texture& texture, std::size_t count,
+ sf::Time duration, bool repeat = false);
+ void update(sf::Time deltaTime);
+ void draw(sf::RenderTarget& target, sf::RenderStates states)
+ const override;
+ void reset();
+ bool finished() const;
};
- 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