-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticle.h
More file actions
120 lines (98 loc) · 2.38 KB
/
Copy pathParticle.h
File metadata and controls
120 lines (98 loc) · 2.38 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
Name: Martin Cardozo
Copyright:
Author: Martin Cardozo
Date: 12/06/08 11:17
Description: Particula Genérica
*/
/************************
INCLUDES
************************/
/************************
CLASS
************************/
class Particle {
public:
//CONSTRUCTOR
Particle(int XC, int YC, int elasticityY, int minXC, int maxXC, int minYC, int maxYC, int lifeTimeC, float amplitudeC, float forceC, int redC, int greenC, int blueC);
//FUNCTIONS
bool move();
void checkBounds();
bool checkLife();
//VARIABLES
float X;
float Y;
int red;
int green;
int blue;
private:
//FUNCTIONS
float randAmplitude(float max);
//VARIABLES
int elasticity;
int minX;
int maxX;
int minY;
int maxY;
int lifeTime;
float weight;
float gravity;
float amplitude;
float force;
};
/************************
CONSTRUCTOR
************************/
Particle::Particle(int XC, int YC, int elasticityC, int minXC, int maxXC, int minYC, int maxYC, int lifeTimeC, float amplitudeC, float forceC, int redC, int greenC, int blueC)
{
X = XC;
Y = YC;
elasticity = elasticityC;
minX = minXC;
maxX = maxXC;
minY = minYC;
maxY = maxYC;
amplitude = randAmplitude(amplitudeC)/5000;
force = float(forceC + MathFunc.randFloat(50)/5000);
weight = MathFunc.randFloat(1)/5000;
force += weight;
lifeTime = lifeTimeC;
red = redC;
green = greenC;
blue = blueC;
gravity = 0;
};
/************************
PUBLIC METHODS
************************/
bool Particle::move(){
if (!checkLife()){return false;}
checkBounds();
X += amplitude;
Y -= force;
//gravity += .3f;
//Y += gravity;
};
void Particle::checkBounds(){
if (Y < minY){force *= -1;}
if (Y > maxY){
force = elasticity--;
gravity = 0;
}
if (X < minX){amplitude *= -1;}
if (X > maxX){amplitude *= -1;}
};
bool Particle::checkLife(){
if (!(lifeTime--) || !elasticity){return false;}
return true;
};
/************************
PRIVATE METHODS
************************/
float Particle::randAmplitude(float max){
if (rand()%2){
return -(MathFunc.randFloat(max));
}else{
return MathFunc.randFloat(max);
}
};