-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticle.cpp
executable file
·105 lines (73 loc) · 1.56 KB
/
particle.cpp
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#ifndef __PARTICLE__
#define __PARTICLE__
#include "tools.cpp"
extern const int SCREEN_WIDTH;
extern const int SCREEN_HEIGHT;
class Particle {
private:
int offsetX;
int offsetY;
int velocityX;
int velocityY;
SDL_Surface *object;
SDL_Rect tile;
public:
Particle( int, int );
~Particle( );
SDL_Rect getRect( );
int getX( );
int getY( );
bool offScreen( );
void setPart( );
void setVelocity( int x, int y );
void setParticleSurface( SDL_Surface * );
void handleMovement( );
void render( SDL_Surface * );
};
Particle::Particle( int x, int y ) {
offsetX = x;
offsetY = y;
}
Particle::~Particle( ) {
}
SDL_Rect Particle::getRect( ) {
return tile;
}
int Particle::getX( ) {
return offsetX;
}
int Particle::getY( ) {
return offsetY;
}
void Particle::setParticleSurface( SDL_Surface *sur ) {
object = sur;
}
bool Particle::offScreen( ) {
if( offsetY > SCREEN_HEIGHT ) return true;
if( offsetX+tile.w < 0 ) return true;
if( offsetX > SCREEN_WIDTH ) return true;
if( offsetY+tile.h < 0 ) return true;
return false;
}
void Particle::setPart( ) {
do {
tile.x = rand() % 500-24;
} while ( tile.x < 0 );
do {
tile.y = rand() % 500-24;
} while( tile.y < 0 );
tile.w = 24;
tile.h = 24;
}
void Particle::setVelocity( int x, int y ) {
velocityX = x;
velocityY = y;
}
void Particle::handleMovement( ) {
offsetX += velocityX;
offsetY += velocityY;
}
void Particle::render( SDL_Surface *screen ) {
apply_surface( offsetX, offsetY, object, screen, &tile );
}
#endif