+
+class AnimationRunner {
+
+public:
+ explicit AnimationRunner(const Animation *a = 0, int colOffset = 0, int rowOffset = 0)
+ : animation(a), sprite(0), frameShift(0), colOffset(colOffset), rowOffset(rowOffset) { }
+
+public:
+ bool Valid() const { return animation; }
+ void Clear() { animation = 0; timer = app::Timer<Uint32>(); }
+
+ void Start(app::State &ctrl);
+ void Start(app::Application &ctrl);
+ void Stop();
+ bool Started() const;
+ bool Running() const;
+ bool Finished() const;
+ bool JustFinished() const;
+
+ const app::Timer<Uint32> &GetTimer() { return timer; }
+
+ void SetFrameShift(int offset) { frameShift = offset; }
+ int FrameShift() const { return frameShift; }
+ void SetColOffset(int offset) { colOffset = offset; }
+ int ColOffset() const { return colOffset; }
+ void SetRowOffset(int offset) { rowOffset = offset; }
+ int RowOffset() const { return rowOffset; }
+
+ void ChangeAnimation(const Animation *a) { animation = a; }
+ const Animation *GetAnimation() const { return animation; }
+
+ void ChangeSprite(const Sprite *s) { sprite = s; }
+ const Sprite *GetSprite() const { return sprite ? sprite : animation->GetSprite(); }
+
+ void Draw(SDL_Surface *dest, geometry::Vector<int> position) const;
+ void DrawTopRight(SDL_Surface *dest, geometry::Vector<int> position) const;
+ void DrawCenter(SDL_Surface *dest, geometry::Vector<int> position) const;
+ void DrawCenterBottom(SDL_Surface *dest, geometry::Vector<int> position) const;
+
+ int Frame() const;
+
+private:
+ const Animation *animation;
+ const graphics::Sprite *sprite;
+ app::Timer<Uint32> timer;
+ int frameShift;
+ int colOffset;
+ int rowOffset;
+
+};
+