-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgui.js
85 lines (70 loc) · 1.73 KB
/
gui.js
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
const gui_elements = [];
class Button {
constructor(msg, x, y, onClick) {
this.msg = msg;
this.x = x;
this.y = y;
this.z = 1;
this.down = false;
this.onClick = onClick;
gui_elements.push(this);
}
display() {
rectMode(CENTER);
textAlign(CENTER, CENTER);
textSize(35);
this.height = textAscent()+textDescent()+20;
this.width = textWidth(this.msg)+40;
if(this.mouseDown()) {
this.z = 0;
this.down = true;
} else this.z = 1;
if(this.mouseUp()) {
this.onClick();
}
if(!mouseIsPressed) this.down = false;
push();
translate(this.x, this.y);
noStroke();
fill(0, min(Screen.textA, 160));
rect(0, 0, this.width, this.height);
fill(31, 75, 163, min(Screen.textA, 255));
translate(-this.z*4, -this.z*4);
rect(0, 0, this.width, this.height);
fill(255, Screen.textA);
text(this.msg, 0, 2);
pop();
}
mouseOver() {
return abs(mouseX-this.x) <= this.width/2+20 && abs(mouseY-this.y) <= this.height/2+20;
}
mouseDown() {
return mouseIsPressed && this.mouseOver()
}
mouseUp() {
return this.mouseOver() && this.down && !mouseIsPressed;
}
}
class Screen {
static alpha = 0;
static textA = 0;
static fade() {
textAlign(CENTER, CENTER);
rectMode(CORNER);
fill(31, 75, 163, min(Screen.alpha, 140));
rect(0, 0, width, height);
noStroke();
textSize(65);
fill(0, min(0.2*Screen.textA, 80) );
text("Game Over", width/2+2, 180+2);
fill(255, Screen.textA);
text("Game Over", width/2, 180);
Screen.alpha += 1;
Screen.textA = max(130, 3*Screen.alpha-130)-130;
restartButton.display();
}
static reset() {
Screen.alpha = 0;
Screen.textA = 0;
}
}