X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;ds=inline;f=src%2Fgraphics%2FAnimation.h;h=55a16d99034fb70a30323ed6506514c67cebdfe0;hb=ebeefe8b81fbb2e69939d67972453c01b023ec22;hp=fc9de19c352f36f898a06a74cdb285cc146d7eb3;hpb=572a3272ba5c470252b2c13384b5913aa023d70a;p=l2e.git diff --git a/src/graphics/Animation.h b/src/graphics/Animation.h index fc9de19..55a16d9 100644 --- a/src/graphics/Animation.h +++ b/src/graphics/Animation.h @@ -1,5 +1,5 @@ /* - * Animation.h + * Animation.h * * Created on: Aug 11, 2012 * Author: holy @@ -12,7 +12,9 @@ #include "../app/Application.h" #include "../app/State.h" #include "../app/Timer.h" +#include "../geometry/operators.h" #include "../geometry/Point.h" +#include "../geometry/Vector.h" #include @@ -22,9 +24,10 @@ class Animation { public: Animation() - : sprite(0), frameTime(0), numFrames(0), col(0), row(0), repeat(false) { } - Animation(const Sprite *sprite, int frameTime, int numFrames, int col = 0, int row = 0, bool repeat = false) - : sprite(sprite), frameTime(frameTime), numFrames(numFrames), col(col), row(row), repeat(repeat) { } + : sprite(0), frameTime(0), repeat(false) { } + Animation(const Sprite *sprite, int frameTime, bool repeat = false) + : sprite(sprite), frameTime(frameTime), repeat(repeat) { } + virtual ~Animation() { }; public: void Start(app::State &ctrl) { @@ -37,23 +40,38 @@ public: timer = app::Timer(); } bool Running() const { - return timer.Running() && (repeat || timer.Iteration() < numFrames); + return timer.Running() && (repeat || timer.Iteration() < NumFrames()); } - void Draw(SDL_Surface *dest, geometry::Point position) { - sprite->Draw(dest, position, col, Running() ? row + (timer.Iteration() % numFrames) : row); + virtual void Draw(SDL_Surface *dest, geometry::Point position) const { + sprite->Draw(dest, position, Col(), Row()); } + void DrawTopRight(SDL_Surface *dest, geometry::Point position) const { + geometry::Vector offset(-sprite->Width(), 0); + Draw(dest, position + offset); + } + void DrawCenter(SDL_Surface *dest, geometry::Point position) const { + geometry::Vector offset(-sprite->Width() / 2, -sprite->Height() / 2); + Draw(dest, position + offset); + } + void DrawCenterBottom(SDL_Surface *dest, geometry::Point position) const { + geometry::Vector offset(-sprite->Width() / 2, -sprite->Height()); + Draw(dest, position + offset); + } + +protected: + int Frame() const { return Running() ? (timer.Iteration() % NumFrames()) : 0; } + virtual int Col() const = 0; + virtual int Row() const = 0; + virtual int NumFrames() const = 0; private: const Sprite *sprite; app::Timer timer; int frameTime; - int numFrames; - int col; - int row; bool repeat; }; } -#endif /* GRAPHICS_ANIMATION_H_ */ +#endif /* GRAPHICS_SIMPLEANIMATION_H_ */