X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fgraphics%2FSimpleAnimation.h;fp=src%2Fgraphics%2FSimpleAnimation.h;h=dffd863a2be6bbf287039e2a44179d457b2aae0e;hb=b9fdb4fd361fbc0c8e2c0df9615e6eed540917a1;hp=0000000000000000000000000000000000000000;hpb=e559a146d268996a3367e370213b09a3b190e0bc;p=l2e.git diff --git a/src/graphics/SimpleAnimation.h b/src/graphics/SimpleAnimation.h new file mode 100644 index 0000000..dffd863 --- /dev/null +++ b/src/graphics/SimpleAnimation.h @@ -0,0 +1,62 @@ +/* + * SimpleAnimation.h + * + * Created on: Aug 11, 2012 + * Author: holy + */ + +#ifndef GRAPHICS_SIMPLEANIMATION_H_ +#define GRAPHICS_SIMPLEANIMATION_H_ + +#include "Sprite.h" +#include "../app/Application.h" +#include "../app/State.h" +#include "../app/Timer.h" +#include "../geometry/Point.h" + +#include + +namespace graphics { + +class SimpleAnimation { + +public: + SimpleAnimation() + : sprite(0), frameTime(0), numFrames(0), col(0), row(0), repeat(false) { } + SimpleAnimation(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) { } + +public: + void Start(app::State &ctrl) { + timer = ctrl.GraphicsTimers().StartInterval(frameTime); + } + void Start(app::Application &ctrl) { + timer = ctrl.GlobalTimers().StartInterval(frameTime); + } + void Stop() { + timer = app::Timer(); + } + bool Running() const { + 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); + } + void DrawCenterBottom(SDL_Surface *dest, geometry::Point position) const { + sprite->DrawCenterBottom(dest, position, col, Running() ? row + (timer.Iteration() % numFrames) : row); + } + +private: + const Sprite *sprite; + app::Timer timer; + int frameTime; + int numFrames; + int col; + int row; + bool repeat; + +}; + +} + +#endif /* GRAPHICS_SIMPLEANIMATION_H_ */