From cefe66cdbb8786dc455657376e36f0ff8785d5bc Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Thu, 8 Feb 2018 12:34:42 -0500 Subject: Introduced animated sprites Also restyled a lot of the code. --- src/animation.h | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/animation.h (limited to 'src/animation.h') diff --git a/src/animation.h b/src/animation.h new file mode 100644 index 0000000..50446d0 --- /dev/null +++ b/src/animation.h @@ -0,0 +1,100 @@ +#ifndef ANIMATION_H_74EB0901 +#define ANIMATION_H_74EB0901 + +#include "renderer.h" +#include +#include +#include + +class Animation { +public: + + Animation( + size_t firstFrame, + size_t numFrames, + size_t delay) : + firstFrame_(firstFrame), + numFrames_(numFrames), + delay_(delay) + { + } + + inline size_t getFirstFrame() const + { + return firstFrame_; + } + + inline size_t getNumFrames() const + { + return numFrames_; + } + + inline size_t getDelay() const + { + return delay_; + } + +private: + + size_t firstFrame_; + size_t numFrames_; + size_t delay_; +}; + +class AnimationSet { +public: + + AnimationSet( + Texture texture, + int frameWidth, + int frameHeight, + int framesAcross); + + void emplaceAnimation( + std::string animation, + size_t firstFrame, + size_t numFrames, + size_t delay); + + inline const Animation& getAnimation(std::string animation) const + { + if (!animations_.count(animation)) + { + throw std::invalid_argument("Animation does not exist"); + } + + return animations_.at(animation); + } + + inline const Texture& getTexture() const + { + return texture_; + } + + inline int getFrameWidth() const + { + return frameWidth_; + } + + inline int getFrameHeight() const + { + return frameHeight_; + } + + inline int getFramesAcross() const + { + return framesAcross_; + } + + Rectangle getFrameRect(int frame) const; + +private: + + std::map animations_; + Texture texture_; + int frameWidth_; + int frameHeight_; + int framesAcross_; +}; + +#endif /* end of include guard: ANIMATION_H_74EB0901 */ -- cgit 1.4.1