summaryrefslogtreecommitdiff
path: root/core/src/cpp/animation.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/cpp/animation.h')
-rw-r--r--core/src/cpp/animation.h45
1 files changed, 45 insertions, 0 deletions
diff --git a/core/src/cpp/animation.h b/core/src/cpp/animation.h
new file mode 100644
index 0000000..d74ca75
--- /dev/null
+++ b/core/src/cpp/animation.h
@@ -0,0 +1,45 @@
+#pragma once
+
+#include "sprite.h"
+
+struct Animation : public Sprite
+{
+ explicit Animation(
+ SDL_Renderer* renderer,
+ const std::string& filename,
+ const int width,
+ const double durationS,
+ const bool repeat
+ );
+ ~Animation() override = default;
+
+public:
+ /*!
+ * \brief animation_ended - is the animation sequence ended as specified
+ * timestamp?
+ * \param timestamp
+ * \return true if ended, false otherwise
+ */
+ bool animation_ended(const TimeStamp timestamp) const;
+
+ /*!
+ * \brief frame - compute the frame number at current time for the the
+ * animation started at timestamp
+ * \param timestamp
+ * \return frame number
+ */
+ int frame(const TimeStamp timestamp) const;
+
+ /*!
+ * \brief rect - choose the right frame from the texture
+ * \param timestamp
+ * \return frame rect
+ */
+ SDL_Rect rect(const TimeStamp timestamp) const;
+
+ /*!
+ * \brief durationS - durationS of the animation sequence in seconds
+ */
+ const double durationS{1.};
+ const bool repeat{false}; // should we repeat the animation?
+};