-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drop.pde
61 lines (53 loc) · 1.23 KB
/
Drop.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
class Drop{
float r; //radius of drop
Body body;
color c;
float dying;
float alpha;
Drop(){
r = 20;
dying = 0;
alpha = 0;
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
float posxrand = calcPosx();
bd.position.set(box2d.coordPixelsToWorld(posxrand, -40));
body = box2d.createBody(bd);
CircleShape cs = new CircleShape();
cs.m_radius = box2d.scalarPixelsToWorld(r);
body.createFixture(cs, 1.0);
body.setUserData(this);
c = #b5f3f7;
}
void display(){
Vec2 pos = box2d.getBodyPixelCoord(body);
float a = body.getAngle();
pushMatrix();
translate(pos.x, pos.y);
rotate(-a);
fill(175);
stroke(0);
rectMode(CENTER);
fill(c);
noStroke();
if(dying<1){
fill(#b5f3f7);
noStroke();
for (int i = 2; i < 8; i++ ) {
ellipse(0, 0 + i*4, i*2, i*2);
}
} else{
fill(#b5f3f7, 200);
for (int i = 8; i > 2; i--) {
ellipse(0, 0 - i*2, i*1.5, i*1.5);
}
}
popMatrix();
}
//void killBody(){
// box2d.destroyBody(body);
//}
float calcPosx(){
return random(-10, width+10);
}
}