forked from Critters/TWANG
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Particle.h
59 lines (54 loc) · 1.03 KB
/
Particle.h
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
#include "Arduino.h"
#define FRICTION 1
class Particle
{
public:
void Spawn(int pos);
void Tick(int USE_GRAVITY);
void Kill();
bool Alive();
int _pos;
int _power;
private:
int _life;
int _alive;
int _sp;
};
void Particle::Spawn(int pos){
_pos = pos;
_sp = random(-200, 200);
_power = 255;
_alive = 1;
_life = 220 - abs(_sp);
}
void Particle::Tick(int USE_GRAVITY){
if(_alive){
_life ++;
if(_sp > 0){
_sp -= _life/10;
}else{
_sp += _life/10;
}
if(USE_GRAVITY && _pos > 500) _sp -= 10;
_power = 100 - _life;
if(_power <= 0){
Kill();
}else{
_pos += _sp/7.0;
if(_pos > 1000){
_pos = 1000;
_sp = 0-(_sp/2);
}
else if(_pos < 0){
_pos = 0;
_sp = 0-(_sp/2);
}
}
}
}
bool Particle::Alive(){
return _alive;
}
void Particle::Kill(){
_alive = 0;
}