Debian Codegraph @

Oodle/src/CAnimation.h

raw
1 #ifndef _CANIMATION_
2 #define _CANIMATION_
3
4 #include "CSurface.h"
5 #include "CTimer.h"
6 #include <list>
7 using namespace std;
8
9 /*! The animation class handles the loading of spite animations from big-ass
10 bitmaps or from numbered files. It also provides a SDL surface of the
11 current frame of the animation.
12 */
13 class CAnimation
14 {
15 public:
16 ~CAnimation(); //! Must free all surfaces created and stored in frames list
17 CAnimation(const string &fileName, //! Filename and width and height and padding and speed (FPS) of BIGASS bitmap
18 int width, int height,
19 int padding, int speed, bool alpha, bool nopath);
20 CAnimation(const string &fileName, //! Filename and width and height and padding and speed (FPS) of BIGASS bitmap
21 int width, int height,
22 int padding, int speed, bool loop,
23 bool alpha, bool nopath);
24 CAnimation(const string &fileName,
25 bool alpha, bool nopath); //! Filename of bitmap to load (ie this will be a static animation)
26 CAnimation(CSurface* s); //! Create animation of one frame from given surface (and take ownership of this pointer)
27 CAnimation(const list<CSurface*> &s, int period, bool loop = false); //! Create animation of any number of frames from given Surfaces (and take ownership of these ptrs)
28
29 CAnimation(const CAnimation &a); //! Copy constructor for deep copy
30 const CAnimation& operator=(const CAnimation &s); //! Assignment operator for deep copy
31
32 void update(); //! updates animation's state based on current fps (must be called _every_ frame)
33 void start() { animating = true; } //! starts the animation
34 void pause() { animating = false; } //! stops the animation
35 void reset() { currentFrame = frames.begin(); done = false; start(); }
36 CSurface* getCurrentFrame() { //! returns ptr to surface containing current frame
37 return *currentFrame;
38 };
39 int getFrames();
40 bool isAnimating() { return animating; }
41 void setFrame(int n);
42 int getFrameIndex();
43 void setSpeed(int s) { timer.setPeriod(s); }
44 void setLoop(bool l = true) { loop = l; }
45 CAnimation* getClone(); //! returns clone of this animtion (new animation object backed by same list of surfaces)
46 bool isDone() { return done; }
47 void setAlpha(Uint32 flags, Uint8 alpha);
48
49 private:
50 CAnimation(const CAnimation& sprite, bool clone); //! Construct animation of given sprite if clone==true
51
52 list<CSurface*> frames; //! list holding all the frames of the animation
53 list<CSurface*>::iterator currentFrame; //! iterator to iterate through list of frames
54 int width; //! Width of each frame
55 int height; //! Height of each frame
56 bool animating; //! Animate this sprite or not
57 CTimer timer; //! Timer to time animation
58 bool isClone; //! is this animation a clone of another? (ie backed by same CSurface's)
59 bool loop; //! Loop this animation, or freeze on last frame?
60 bool done; //! is animation over (only valid if loop is false)
61 };
62
63 #endif