-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugBall.pde
56 lines (45 loc) · 1.35 KB
/
DebugBall.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
class DebugBall extends PhysicsEntity {
color colorFill;
boolean showLabel;
String debugLabel;
PShape shape;
DebugBall(PVector origin, float mass, float bounce, float roll, boolean showLabel) {
super(origin, new PVector(), mass + 8, mass, bounce, roll);
this.zIndex = 100000;
this.colorFill = color(random(360.0), 0.5, 1.0);
this.debugLabel = "MASS: " + nf(this.mass, 0, 2) + "\nBOUNCE: " + nf(this.bounce, 0, 2) + "\nROLL: " + nf(this.roll, 0, 2);
this.showLabel = showLabel;
this.shape = createShape(ELLIPSE, 0, 0, this.radius * 2, this.radius * 2);
this.shape.setFill(colorFill);
}
void move(PVector velocity) {
this.velocity.add(velocity);
}
void OnTick() {
if (inputs.getIsActive("moveup")) {
this.move(new PVector(0, -0.1));
}
if (inputs.getIsActive("movedown")) {
this.move(new PVector(0, 0.1));
}
if (inputs.getIsActive("moveleft")) {
this.move(new PVector(-0.1, 0));
}
if (inputs.getIsActive("moveright")) {
this.move(new PVector(0.1, 0));
}
super.OnTick();
}
void OnDraw() {
shape(this.shape, this.origin.x, this.origin.y);
if (!this.showLabel) return;
textSize(12);
textLeading(14);
float textX = this.origin.x + this.radius;
float textY = this.origin.y + this.radius * 2;
fill(0);
text(this.debugLabel, textX + 1, textY + 1);
fill(colorFill);
text(this.debugLabel, textX, textY);
}
}