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.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/animation.cpp (limited to 'src/animation.cpp') diff --git a/src/animation.cpp b/src/animation.cpp new file mode 100644 index 0000000..31ba21f --- /dev/null +++ b/src/animation.cpp @@ -0,0 +1,35 @@ +#include "animation.h" + +AnimationSet::AnimationSet( + Texture texture, + int frameWidth, + int frameHeight, + int framesAcross) : + texture_(std::move(texture)), + frameWidth_(frameWidth), + frameHeight_(frameHeight), + framesAcross_(framesAcross) +{ +} + +void AnimationSet::emplaceAnimation( + std::string animation, + size_t firstFrame, + size_t numFrames, + size_t delay) +{ + animations_.emplace( + std::piecewise_construct, + std::make_tuple(animation), + std::make_tuple(firstFrame, numFrames, delay)); +} + +Rectangle AnimationSet::getFrameRect(int frame) const +{ + return { + frameWidth_ * (frame % framesAcross_), + frameHeight_ * (frame / framesAcross_), + frameWidth_, + frameHeight_ + }; +} -- cgit 1.4.1