X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FAnimation.h;h=50330957ab9d28412cb1314c70596f86d75ead1f;hb=cc3d698b8c1ad09d7a3f9e3f28bc84e0ac1735ea;hp=29948feb3bac68579ef66ecdd20cd8dc81855d4a;hpb=be7b4addf295d6193ba2527cdd17cdb524339aed;p=l2e.git diff --git a/src/graphics/Animation.h b/src/graphics/Animation.h index 29948fe..5033095 100644 --- a/src/graphics/Animation.h +++ b/src/graphics/Animation.h @@ -1,10 +1,3 @@ -/* - * Animation.h - * - * Created on: Aug 11, 2012 - * Author: holy - */ - #ifndef GRAPHICS_ANIMATION_H_ #define GRAPHICS_ANIMATION_H_ @@ -12,19 +5,19 @@ #include "../app/Application.h" #include "../app/State.h" #include "../app/Timer.h" +#include "../loader/fwd.h" #include "../geometry/Vector.h" #include #include -namespace loader { - class TypeDescription; -} - namespace graphics { class Animation { +public: + static const int TYPE_ID = 401; + public: Animation() : sprite(0), frameTime(0), repeat(false) { } @@ -48,8 +41,10 @@ public: virtual int Row(int frame) const = 0; virtual geometry::Vector Offset(int frame) const { return geometry::Vector(); } + static void CreateTypeDescription(); + protected: - static void AddFields(loader::TypeDescription &, const Animation &, std::ptrdiff_t offset, int boolId, int numberId, int spriteId); + static void AddFields(loader::TypeDescription &, const Animation &, std::ptrdiff_t offset); private: const Sprite *sprite; @@ -63,7 +58,7 @@ class AnimationRunner { public: explicit AnimationRunner(const Animation *a = 0, int colOffset = 0, int rowOffset = 0) - : animation(a), sprite(a ? a->GetSprite() : 0), colOffset(colOffset), rowOffset(rowOffset) { } + : animation(a), sprite(0), frameShift(0), colOffset(colOffset), rowOffset(rowOffset) { } public: bool Valid() const { return animation; } @@ -93,35 +88,41 @@ public: const app::Timer &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; } + const Sprite *GetSprite() const { return sprite ? sprite : animation->GetSprite(); } void Draw(SDL_Surface *dest, geometry::Vector position) const { - sprite->Draw(dest, position + animation->Offset(Frame()), animation->Col(Frame()) + ColOffset(), animation->Row(Frame()) + RowOffset()); + GetSprite()->Draw(dest, position + animation->Offset(Frame()), animation->Col(Frame()) + ColOffset(), animation->Row(Frame()) + RowOffset()); } void DrawTopRight(SDL_Surface *dest, geometry::Vector position) const { - geometry::Vector offset(-sprite->Width(), 0); + geometry::Vector offset(-GetSprite()->Width(), 0); Draw(dest, position + offset); } void DrawCenter(SDL_Surface *dest, geometry::Vector position) const { - Draw(dest, position - (sprite->Size() / 2)); + Draw(dest, position - (GetSprite()->Size() / 2)); } void DrawCenterBottom(SDL_Surface *dest, geometry::Vector position) const { - geometry::Vector offset(-sprite->Width() / 2, -sprite->Height()); + geometry::Vector offset(-GetSprite()->Width() / 2, -GetSprite()->Height()); Draw(dest, position + offset); } - int Frame() const { return Running() ? (timer.Iteration() % animation->NumFrames()) : 0; } + int Frame() const { return Running() ? ((timer.Iteration() + frameShift) % animation->NumFrames()) : 0; } private: const Animation *animation; const graphics::Sprite *sprite; app::Timer timer; + int frameShift; int colOffset; int rowOffset;