-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoin.pde
83 lines (73 loc) · 2.18 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
/*
* INVERT - Coin Class
* CGRA151 Assignment 5
* Author: Leyton Blackler
* ID: 300368625
*/
class Coin {
PVector[] points;
float size = 20;
boolean deleted = false;
//Initialise the coin with it's intial position.
Coin () {
points = new PVector[4];
float randomY = random(80, height - 50);
points[0] = new PVector(width + size/2, randomY - size/2);
points[1] = new PVector(width + size, randomY);
points[2] = new PVector(width + size/2, randomY + size/2);
points[3] = new PVector(width, randomY);
}
//Draws the coin at it's current position.
void drawCoin() {
if (!deleted) {
colorMode(RGB);
fill(255, 140);
noStroke();
beginShape();
for (PVector point : points) {
vertex(point.x, point.y);
}
endShape(CLOSE);
}
}
//Moves the coin across the screen by shifting the position of each of the PVector points.
void moveCoin() {
for (PVector point : points) {
point.x -= Invert.getGameSpeed();
}
}
//Returns the current position of the coin.
PVector[] getLocation() {
return points;
}
//Return the point at the centre of the coin.
PVector getCentrePoint() {
return new PVector(points[0].x + size/2, points[0].y + size/2);
}
//Set the state of the coin as deleted.
void delete() {
deleted = true;
}
//Returns whether the coin has been deleted.
boolean isDeleted() {
return deleted;
}
//Returns whether any of the points in the given array are contained within the area of the coin.
boolean containsPoints(PVector[] points) {
for (PVector point : points) {
int a, b;
boolean result = false;
int sides = this.points.length;
for (a = 0, b = sides - 1; a < sides; b = a++) {
if ((((this.points[a].y <= point.y) && (point.y < this.points[b].y)) || ((this.points[b].y <= point.y) && (point.y < this.points[a].y))) &&
(point.x < (this.points[b].x - this.points[a].x) * (point.y - this.points[a].y) / (this.points[b].y - this.points[a].y) + this.points[a].x)) {
result = !result;
}
}
if (result == true) {
return result;
}
}
return false;
}
}