-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoin.pde
101 lines (85 loc) · 2.56 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
92
93
94
95
96
97
98
99
100
101
/*Coin class-gold coin moving right to left. Is reset once the coin leaves the screen
**when collected, score is increased by 1*/
public class Coin {
private float xCoord, yCoord; //xy coordinates of coin
private int coinDimensions; //height and width of coin
private float speedX; //speed along the x-axis
private float coinColor; //Colour modifier
private char currency; //character code for coin currency
//Default coin constructor which calls the resetCoin
public Coin() {
this.speedX = 5;
this.currency = char(36);//currency set to american dollar character code
resetCoin();
}
/*Displays coin in program-
**coinColor used with modulo operator in game on method-changes color of every 10th coin*/
public void display(float coinColor, int coinDimensions) {
this.coinColor=coinColor;
this.coinDimensions=coinDimensions;
strokeWeight(2);
stroke(0);
fill(255-coinColor, 223-coinColor, 0+coinColor);
ellipse(xCoord, yCoord, coinDimensions, coinDimensions);
fill(0);
textAlign(CENTER);
textSize(coinDimensions);
text(currency, xCoord, yCoord+coinDimensions/3);
}
//Responsible for coin movement and calls private helper method when coin leaves screen
public void update() {
this.xCoord = xCoord - speedX;
if (xCoord < 0 - coinDimensions/2) {
resetCoin();
}
}
//resets coin when spaceman collects coin
public void coinCollected() {
resetCoin();
}
//------Getters/Accessors--------//
public float getXCoord() {
return xCoord;
}
public float getYCoord() {
return yCoord;
}
public float getSpeedX() {
return speedX;
}
public int getCoinDimensions() {
return coinDimensions;
}
public float getCoinColor() {
return coinColor;
}
public char currency() {
return currency;
}
//------Setters/Mutators--------//
public void setxCoord(float xCoord) {
this.xCoord=xCoord;
}
public void setyCoord(float yCoord) {
this.yCoord=yCoord;
}
public void setSpeedX(float speedX) {
this.speedX=speedX;
}
public void setCoinDimensions(int coinDimensions) {
this.coinDimensions=coinDimensions;
}
public void setCoinColor(float coinColor) {
this.coinColor=coinColor;
}
public void setCurrency(char currency) {
this.currency=currency;
}
//------Private Helper Method-------//
//Only called wihin this class
//Is called to set initial coordinates and reset coin coordinates
private void resetCoin() {
this.yCoord = random(200, 350);
this.xCoord = width+coinDimensions/2;
}
}