summaryrefslogtreecommitdiff
path: root/src/graphics
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2022-11-13 12:05:43 +0100
committerEkaitz Zarraga <ekaitz@elenq.tech>2022-11-13 12:05:43 +0100
commit3293d06b364bc91348f6a305f97e607ff610eb98 (patch)
tree25b5c0801cb96208c225121a7a18c9d896ba5ac6 /src/graphics
parentc8663de4fbdb30534723df6c8d1331535dcdadc2 (diff)
Make animations use runtime polimorphism:
Lets us make different animation types but use them interchangeably
Diffstat (limited to 'src/graphics')
-rw-r--r--src/graphics/animation.cpp6
-rw-r--r--src/graphics/animation.h15
2 files changed, 13 insertions, 8 deletions
diff --git a/src/graphics/animation.cpp b/src/graphics/animation.cpp
index b93387e..577324a 100644
--- a/src/graphics/animation.cpp
+++ b/src/graphics/animation.cpp
@@ -64,6 +64,10 @@ namespace Graphics{
rect_.top = row_ * h_;
}
+ bool Animation::finished(){
+ return false;
+ }
+
Animation::~Animation(){}
// ONESHOT ANIMATION
@@ -75,7 +79,7 @@ namespace Graphics{
}
bool OneShotAnimation::finished(){
- return i_ == count_ - 1;
+ return (i_ == count_ - 1);
}
sf::IntRect& OneShotAnimation::next(int deltaTime){
diff --git a/src/graphics/animation.h b/src/graphics/animation.h
index 9f5dfa5..503b75d 100644
--- a/src/graphics/animation.h
+++ b/src/graphics/animation.h
@@ -21,20 +21,21 @@ namespace Graphics{
~Animation();
Animation(const sf::Texture& texture, int count, int switchTime,
int height, int width, int row);
- sf::IntRect& next(int deltaTime);
- void reset();
+ virtual sf::IntRect& next(int deltaTime);
+ virtual void reset();
+ virtual bool finished();
};
- class OneShotAnimation : Animation {
+ class OneShotAnimation : public Animation {
public:
OneShotAnimation();
OneShotAnimation(const sf::Texture& texture, int count, int
switchTime, int height, int width, int row);
- bool finished();
- sf::IntRect& next(int deltaTime);
+ sf::IntRect& next(int deltaTime) override;
+ bool finished() override;
};
- class BouncingAnimation : Animation{
+ class BouncingAnimation : public Animation{
private:
bool up_;
public:
@@ -42,7 +43,7 @@ namespace Graphics{
BouncingAnimation(const sf::Texture& texture, int count, int
switchTime, int height, int width, int row);
~BouncingAnimation();
- sf::IntRect& next(int deltaTime);
+ sf::IntRect& next(int deltaTime) override;
};
}
#endif // GRAPHICS_ANIMATION_H