blob: fd3f99fdce67e9a1518b132451e559c69549ce9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
//--------------------------------------------------------------------------------------------------
// CSprite.
// A class to represent a game sprite.
// The sprite system is simple: we grab the background from the screen and then store it in the
// CSurface *mBackroung variable. After that we draw the sprite frame onto the screen, and before we
// draw the next frame, we restore the screen from mBackground.
//--------------------------------------------------------------------------------------------------
#ifndef __CSPRITE_H__
#define __CSPRITE_H__
#include <math.h>
#include "CParticle.h"
#include "CSpriteAnimation.h"
#include "CSurface.h"
class CSprite
{
public:
CSprite(void);
CSprite(CSpriteAnimation *aSpriteAnimation, CSurface *aScreen);
~CSprite(void);
void destroy(void);
void update(void);
void render(void);
void setXVel(float aXVel);
void setYVel(float aYVel);
void setAnim(int startFrame, int endFrame, bool isLooping);
void setRenderOffsets(int aOffsetX, int aOffsetY);
void setXY(int aX, int aY);
int getIntX(void);
int getIntY(void);
private:
void saveBackground(void);
void restoreBackground(void);
void draw(void);
bool mDrawn;
// A pointer to the sprite animation (all the frame images) for this sprite.
CSpriteAnimation *mSpriteAnimation;
// Used to redraw the background after drawing the frame.
CSurface *mBackground;
// Pointer to the screen surface.
CSurface *mScreen;
// Tells us whether this sprite is currently animating or not.
bool mAnimating;
// Used when clearing the screen.
int mOldX;
int mOldY;
// Time of the last update.
long mLastUpdate;
// Current frame of the animation.
int mFrame;
// Position of the sprite and its forces.
CParticle *mParticle;
// Variables for the animations.
int mStartFrame;
int mEndFrame;
bool mIsLooping;
// Rendering offsets.
int mOffsetX;
int mOffsetY;
};
#endif /* __CSPRITE_H__ */
|