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), colOffset(colOffset), rowOffset(rowOffset) { }
public:
bool Valid() const { return animation; }
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<int> 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<int> position) const {
- geometry::Vector<int> offset(-sprite->Width(), 0);
+ geometry::Vector<int> offset(-GetSprite()->Width(), 0);
Draw(dest, position + offset);
}
void DrawCenter(SDL_Surface *dest, geometry::Vector<int> position) const {
- Draw(dest, position - (sprite->Size() / 2));
+ Draw(dest, position - (GetSprite()->Size() / 2));
}
void DrawCenterBottom(SDL_Surface *dest, geometry::Vector<int> position) const {
- geometry::Vector<int> offset(-sprite->Width() / 2, -sprite->Height());
+ geometry::Vector<int> offset(-GetSprite()->Width() / 2, -GetSprite()->Height());
Draw(dest, position + offset);
}