X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FAnimation.h;h=0c6ae288b4a5e04220f764d9c5ba6b4ee05597c4;hb=aedc31b88715246abc00a0ab333bea6e17bbb780;hp=55a16d99034fb70a30323ed6506514c67cebdfe0;hpb=ebeefe8b81fbb2e69939d67972453c01b023ec22;p=l2e.git diff --git a/src/graphics/Animation.h b/src/graphics/Animation.h index 55a16d9..0c6ae28 100644 --- a/src/graphics/Animation.h +++ b/src/graphics/Animation.h @@ -24,9 +24,9 @@ class Animation { public: Animation() - : sprite(0), frameTime(0), repeat(false) { } + : sprite(0), frameTime(0), colOffset(0), rowOffset(0), repeat(false) { } Animation(const Sprite *sprite, int frameTime, bool repeat = false) - : sprite(sprite), frameTime(frameTime), repeat(repeat) { } + : sprite(sprite), frameTime(frameTime), colOffset(0), rowOffset(0), repeat(repeat) { } virtual ~Animation() { }; public: @@ -42,8 +42,22 @@ public: bool Running() const { return timer.Running() && (repeat || timer.Iteration() < NumFrames()); } + bool JustFinished() const { + return timer.JustHit() && timer.Iteration() == NumFrames(); + } + + const app::Timer &GetTimer() { return timer; } + + void SetColOffset(int offset) { colOffset = offset; } + int ColOffset() const { return colOffset; } + void SetRowOffset(int offset) { rowOffset = offset; } + int RowOffset() const { return rowOffset; } + + const Sprite *GetSprite() const { return sprite; } + void ChangeSprite(const Sprite *s) { sprite = s; } + virtual void Draw(SDL_Surface *dest, geometry::Point position) const { - sprite->Draw(dest, position, Col(), Row()); + sprite->Draw(dest, position, Col() + ColOffset(), Row() + RowOffset()); } void DrawTopRight(SDL_Surface *dest, geometry::Point position) const { geometry::Vector offset(-sprite->Width(), 0); @@ -58,8 +72,9 @@ public: Draw(dest, position + offset); } -protected: int Frame() const { return Running() ? (timer.Iteration() % NumFrames()) : 0; } + +protected: virtual int Col() const = 0; virtual int Row() const = 0; virtual int NumFrames() const = 0; @@ -68,6 +83,8 @@ private: const Sprite *sprite; app::Timer timer; int frameTime; + int colOffset; + int rowOffset; bool repeat; };