| 1 |
#ifndef _CSPRITE_ |
| 2 |
#define _CSPRITE_ |
| 3 |
|
| 4 |
#include <map> |
| 5 |
#include <list> |
| 6 |
#include "CAnimation.h" |
| 7 |
#include "CVector.h" |
| 8 |
#include "CBounds.h" |
| 9 |
#include "CEffect.h" |
| 10 |
#include "CTimer.h" |
| 11 |
#include "SDL.h" |
| 12 |
#include "CParticle.h" |
| 13 |
using namespace std; |
| 14 |
|
| 15 |
//! Class to handle an animated (or static) sprite |
| 16 |
class CSprite : public CParticle |
| 17 |
{ |
| 18 |
public: |
| 19 |
CSprite(CVector v, CVector pos, const string &fileName, const string &animName, const CRect& b, bool alpha = false, bool nopath = false); |
| 20 |
CSprite(CVector v, CVector pos, const string &fileName, const string &animName, const CRect& b, |
| 21 |
int width, int height, int padding, int speed, bool alpha = false, bool nopath = false); |
| 22 |
CSprite(CVector v, CVector pos, CSurface* s, const string &animName); |
| 23 |
CSprite(const CSprite& surf); |
| 24 |
virtual ~CSprite(); |
| 25 |
|
| 26 |
const CSprite& operator=(const CSprite &s); |
| 27 |
|
| 28 |
virtual void update(); //! Updates the position of this sprite based on velocity and frame-per-second |
| 29 |
void draw(CSurface &surface); //! Asks sprite to draw itself |
| 30 |
|
| 31 |
CAnimation* loadAnimation(const string &fileName, const string &name, bool alpha = false, bool nopath=false); //! Loads a staic animation into this sprite from fileName |
| 32 |
CAnimation* loadAnimation(const string &fileName, const string &name, int width, int height, int padding, int speed, bool alpha = false, bool nopath=false); |
| 33 |
CAnimation* addAnimation(const string &name, CAnimation* a); |
| 34 |
void setAnimation(const string &name); //! Set currentAnimation to animations[name] |
| 35 |
void appendEffect(int duration, CEffect::Effects effect); //! Apply given effect to this sprite's current animation |
| 36 |
void setScale(double factor); |
| 37 |
void setAlpha(Uint32 flags, Uint8 alpha); |
| 38 |
void resetScale(); |
| 39 |
void setRot(double rad); |
| 40 |
void resetRot(); |
| 41 |
|
| 42 |
virtual CParticle::BoundaryInfo inBoundaryHoriz(double x); |
| 43 |
virtual CParticle::BoundaryInfo inBoundaryVert(double y); |
| 44 |
|
| 45 |
Uint32 getHeight() { return (int)(getCurrentFrame()->getHeight() * scale); } |
| 46 |
Uint32 getWidth() { return (int)(getCurrentFrame()->getWidth() * scale); } |
| 47 |
CSurface* getCurrentFrame(bool orEffect = false); |
| 48 |
CAnimation* getCurrentAnimation() { return currentAnimation; } |
| 49 |
|
| 50 |
virtual CSprite* getClone(); |
| 51 |
virtual CSprite* getClone(CVector vel, CVector pos); |
| 52 |
|
| 53 |
protected: |
| 54 |
CSprite(const CSprite& sprite, bool clone); //! Construct a clone of given sprite if clone==true |
| 55 |
CSprite(const CSprite& sprite, bool clone, CVector vel, CVector pos); //! Construct a clone of given sprite if clone==true |
| 56 |
CSprite(CVector v, CVector p); //! If this constructor is used, be _sure_ to add an animation called 'static'! |
| 57 |
CEffect* effect; //! |
| 58 |
double scale; |
| 59 |
double rot; |
| 60 |
|
| 61 |
private: |
| 62 |
map<string,CAnimation*> animations; //! map that holds all of this sprite's animations. each animation name must be unique |
| 63 |
CAnimation* currentAnimation; //! Current animation that this sprite is playing |
| 64 |
bool isClone; //! Is this a clone? i.e. don't free surface upon deletion |
| 65 |
}; |
| 66 |
|
| 67 |
#endif |