/
ParticleManager.pde
57 lines (56 loc) · 1.37 KB
/
ParticleManager.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
//-----------------------------------------------//
//ParticleManager
//-----------------------------------------------//
static class ParticleManager {
static HashMap<Particle, Boolean> particleList = new HashMap<Particle, Boolean>();
static Stage stage;
static int max = 300;
static float fps = 60;
static int size;
static void addParticle(Particle particle) {
//particle.setManager(this);
particleList.put(particle, true);
int i = 0;
if (particleList.size() > max) {
for (Particle p : new HashMap<Particle, Boolean> (particleList).keySet()) {
removeParticle(p);
i++;
if(i > 3){
return;
}
}
}
}
static void setStage(Stage stage) {
//this.stage = stage;
}
static void removeParticle(Particle particle) {
particleList.remove(particle);
particle = null;
}
static void updateFPS(float _fps){
fps = _fps;
}
static void update() {
if(fps < 58){
max -= 10;
if(max < 0){
max = 0;
}
}else{
if(particleList.size() >= max){
max += 100;
}
}
//image(stage.getDataLayer(), 0, 0);
for (Particle particle : new HashMap<Particle, Boolean> (particleList).keySet()) {
particle.update();
}
println(max);
}
static void render() {
for (Particle particle : particleList.keySet ()) {
particle.render();
}
}
}