-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoin.pde
91 lines (76 loc) · 2.31 KB
/
coin.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
/*
* coin.pde
*
* A collectible coin
*
* Created on: January 26, 2020
* Author: Sean LaPlante
*/
class Coin extends WorldObject {
/*
* A coin that can be collected
*/
private float left; // x value of left side of the coin (same as location.x - radius)
private float right; // x value of right side of the coin (same as location.x + radius)
private float top; // y position of top of the coin (same as location.y - radius)
private float bottom; // y position of bottom of the coin (same as location.y + radius)
private float radius; // the distance from the middle to the edge of the coin
private PVector middle; // x, y coords of the middle of the coin (same as location)
private float bWidth; // diameter of the coin
Coin(float x, float y) {
super(x, y, true, ObjectType.COIN);
bWidth = COIN_RADIUS * 2.0;
radius = COIN_RADIUS;
left = location.x - radius;
right = location.x + radius;
top = location.y - radius;
bottom = location.y + radius;
middle = location; // Same thing just store ref
}
void display() {
pushMatrix();
noFill();
stroke(237, 165, 16);
strokeWeight(5);
ellipse(location.x, location.y, bWidth, bWidth);
popMatrix();
}
void slide(float amount) {
super.slide(amount);
top += amount;
bottom += amount;
}
float getLeft() {
return left;
}
float getRight() {
return right;
}
float getTop() {
return top;
}
float getBottom() {
return bottom;
}
float getRadius() {
return radius;
}
float getWidth() {
return bWidth;
}
PVector getMiddle() {
return middle;
}
boolean collide(Ball ball) {
/*
* Called when a ball collides with this object
*/
if (!isCircleInCircle(ball.location, BALL_RADIUS, this.location, this.radius)) {
return false;
}
if (!ball.isSimulated) {
ENGINE.world.deleteCoin(this);
}
return true;
}
}