-
Notifications
You must be signed in to change notification settings - Fork 1
/
ParticleSystem.pde
78 lines (67 loc) · 1.53 KB
/
ParticleSystem.pde
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
//----------------------------------------------------------
// ParticleSystem class
//----------------------------------------------------------
class ParticleSystem {
int num, count, xr, yr;
float x, y, fade;
color[] colors;
boolean activate;
ArrayList<Particle> particles;
ParticleSystem(float x, float y, int num, color[] colors){
this.x = x;
this.y = y;
this.num = num;
this.colors = colors;
particles = new ArrayList<Particle>();
xr = 0;
yr = 0;
count = 0;
activate = false;
fade = random(7,10);
}
void update(){
if(activate) {
if(count<num){
particles.add(new Particle(random(x-xr,x+xr), random(y-yr,y+yr), random(30,50), fade, colors));
}
if(particles.isEmpty()){
activate = false;
reset();
} else {
ArrayList<Particle> clearList = new ArrayList<Particle>();
for(int i=0; i<particles.size(); i++){
Particle p = particles.get(i);
if(p.isDead()){
clearList.add(p);
} else {
p.execute();
}
}
particles.removeAll(clearList);
count++;
}
}
}
void act(){
activate = true;
}
boolean isActing(){
return activate;
}
void reset(){
particles.clear();
count = 0;
}
// for moving game objects
void setXY(float newX, float newY){
x = newX;
y = newY;
}
void setRange(int xRange, int yRange){
xr = xRange;
yr = yRange;
}
void setFade(float f){
fade = f;
}
}