From c055eeef6d41269d11b2ddf7f9aba6f8867da65d Mon Sep 17 00:00:00 2001 From: Nikita Kostovsky Date: Tue, 23 Dec 2025 15:28:05 +0100 Subject: initial commit --- core/src/cpp/animation.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 core/src/cpp/animation.h (limited to 'core/src/cpp/animation.h') 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? +}; -- cgit v1.2.3-70-g09d2