-
Notifications
You must be signed in to change notification settings - Fork 63
/
Flame.pde
78 lines (70 loc) · 1.52 KB
/
Flame.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
public class Flame{
public int x = 0;
public int y = 0;
int startTime;
int showingImg_num;
public Flame (int x, int y) {
this.x = x;
this.y = y;
this.showingImg_num = 0;
this.startTime = millis();
}
public int getCurrentImg() {
if (millis() - this.startTime > 100) {
return this.showingImg_num++;
}
else
{
return this.showingImg_num;
}
}
}
public class FlameMgr{
ArrayList<Flame> flames = new ArrayList<Flame>(0);
PImage flame1;
PImage flame2;
PImage flame3;
PImage flame4;
PImage flame5;
public FlameMgr() {
flame1 = loadImage("img/flame1.png");
flame2 = loadImage("img/flame2.png");
flame3 = loadImage("img/flame3.png");
flame4 = loadImage("img/flame4.png");
flame5 = loadImage("img/flame5.png");
}
void addFlame(int x, int y)
{
flames.add(new Flame(x, y));
}
public void draw() {
ArrayList<Flame> flamesToRemove = new ArrayList<Flame>(0);
for (int i = 0; i < this.flames.size(); ++i) {
Flame flame = this.flames.get(i);
int num = flame.getCurrentImg();
switch (num) {
case 0:
image(this.flame1, flame.x, flame.y);
break;
case 1:
image(this.flame2, flame.x, flame.y);
break;
case 2:
image(this.flame3, flame.x, flame.y);
break;
case 3:
image(this.flame4, flame.x, flame.y);
break;
case 4:
image(this.flame5, flame.x, flame.y);
break;
case 5:
flamesToRemove.add(flame);
break;
}
}
for (int i = 0; i < flamesToRemove.size(); ++i) {
flames.remove(flamesToRemove.get(i));
}
}
}