/
RowAnimation.pde
103 lines (86 loc) · 2.13 KB
/
RowAnimation.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
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
// Thread Class //
public class RowAnimation extends Animation implements Runnable {
Thread thread;
//int pauseTime; // Time to wait between loops
float level;
float levelBase;
float x;
float y;
float w;
float h;
float size;
int id;
float drawX;
float drawY;
float drawH;
float drawW;
float elapsed;
public RowAnimation(PApplet parent, int x, int y, int w, int h, int id) {
// parent.registerDispose(this);
// println("row animation constructor");
this.level = 150;
this.levelBase = this.level;
this.done = false;
this.id = id;
this.h = h;
this.w = w;
//this.size = 32; // this is the size
this.x = x;
this.y = y;
}
// draw does not contain the elapsed because it's not the update really
// store it for run()
public void draw()
{
//println("row animation draw()");
fill(255, 255, 255, (level/levelBase)*255);
//drawX = x + 255 / level;
drawX = x;
drawY = y - ((h / 2) * ((level-levelBase)/levelBase));
//drawW = w - level / 255;
drawW = w;
drawH = h * (level / levelBase);
rect(drawX, drawY, drawW, drawH);
//fill(255,125,0, level);
//text(level, drawX, drawY + drawH + h / 2);
}
public void update(float elapsed) {
//println("update() elapsed:" + elapsed + " level:" + level);
this.elapsed = elapsed;
}
public void start()
{
thread = new Thread(this);
//boomCreated();
thread.start();
super.started = true;
}
public void run()
{
// do something threaded here
while(this.level > 1) {
// level-- plus a little extra for lost time between draws
this.level = this.level - 1 - this.elapsed;
try
{
// add random waiting to make each boom different
Thread.sleep( (int)random(1, 10) );
} catch(InterruptedException e)
{
// do nothing, to the horror of good coding
}
}
// while loop finished, level is 0
super.done = true;
//boomDestroyed(id);
}
public void stop()
{
thread = null;
}
// this will magically be called by the parent once the user hits stop
// this functionality hasn't been tested heavily so if it doesn't work, file a bug
public void dispose() {
stop();
}
}