-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.pde
77 lines (68 loc) · 1.9 KB
/
Button.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
// https://hadamlenz.wordpress.com/2014/07/16/building-a-button-in-processing/
class Button {
float myX, myY, myW, myH;
int levelNum, permission;
String myLabel;
color myColour;
boolean down, unlocked;
Level levelType;
// "permission" is the required number of highest_level in the data.csv (the player must complete lower levels to be able to use this button)
Button (float x, float y, float w, float h, String label, color colour, int num, int perm, Level l) {
myX = x;
myY = y;
myW = w;
myH = h;
myLabel = label;
myColour = colour;
levelNum = num;
permission = perm;
levelType = l;
}
boolean getDown () {
return down;
}
void setDown (boolean d) {
down = d;
}
void pressed() {
down = false; // If the mouse is over the button and clicked, sets the level to one, adds a new level one instance, and sets it up.
level = levelNum;
levels.clear();
levels.add(levelType);
for (Level l : levels) {
l.setupLevel();
}
}
void update() {
// checks if the level required to use this button is unlocked in the data file
if (data.getInt(0, "highest_level") >= permission) {
unlocked = true;
}
// if this level is unlocked, allows button to be used
if (unlocked) {
if (mouseX > myX - myW/2 && mouseX < myX + myW/2 && mouseY > myY - myH/2 && mouseY < myY + myH/2) {
down = true;
} else {
down = false;
}
}
pushMatrix();
// changes colour of button when hovered over
if (down) {
fill (myColour + color(10, 50, 100));
} else {
if (unlocked) {
fill(myColour);
} else {
fill(100);
}
}
rectMode(CENTER);
rect(myX, myY, myW, myH);
fill(255);
textAlign(CENTER);
textSize(20);
text(myLabel, myX, myY);
popMatrix();
}
}