-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlinko_Box2D.pde
89 lines (74 loc) · 1.83 KB
/
Plinko_Box2D.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
import shiffman.box2d.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.joints.*;
import org.jbox2d.collision.shapes.*;
import org.jbox2d.collision.shapes.Shape;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.*;
import org.jbox2d.dynamics.contacts.*;
Box2DProcessing box2d;
ArrayList<Particle> particles;
ArrayList<Plinko> plinkos;
ArrayList<Boundary> bounds;
int cols = 11;
int rows = 10;
void setup() {
size(600, 700);
frameRate(30);
box2d = new Box2DProcessing(this);
box2d.createWorld();
particles = new ArrayList<Particle>();
plinkos = new ArrayList<Plinko>();
bounds = new ArrayList<Boundary>();
newParticle();
float spacing = width / cols;
for (float j = 0; j < rows; j++) {
for (float i = 0; i < cols + 1; i++) {
float x = i * spacing;
if (j % 2 == 0) {
x += spacing / 2;
}
float y = spacing + j * spacing;
Plinko p = new Plinko(x, y, 16);
plinkos.add(p);
}
}
Boundary b = new Boundary(width / 2, height + 50, width, 100);
bounds.add(b);
for (int i = 0; i < cols + 2; i++) {
float x = i * spacing;
float h = 100;
float w = 10;
float y = height - h / 2;
b = new Boundary(x, y, w, h);
bounds.add(b);
}
}
void newParticle() {
Particle p = new Particle(300, 0, 10);
particles.add(p);
}
void draw() {
if (frameCount % 20 == 0) {
newParticle();
}
background(0);
for (int i = 0; i < 2; i++) {
box2d.step();
}
for (int i = 0; i < particles.size(); i++) {
Particle p = particles.get(i);
p.show();
if (p.isOffScreen()) {
box2d.destroyBody(p.body);
particles.remove(i);
i--;
}
}
for (Plinko p : plinkos) {
p.show();
}
for (Boundary b : bounds) {
b.show();
}
}