-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpremenu.js
40 lines (35 loc) · 888 Bytes
/
premenu.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
import { drawButton } from "./utils.js";
const canvas = document.getElementById("screen");
const ctx = canvas.getContext("2d");
export function preMenuLoop(start) {
ctx.font = `40px slkscr`;
ctx.fillStyle = "White";
ctx.textBaseline = "middle";
ctx.fillText(
start ? 'Noisy Gamer' : `Final score: ${score}`,
canvas.width / 2,
canvas.height / 2 - 80
);
drawButton(ctx, getContinueButton(start));
}
export function preMenuClickHandler({ x, y }) {
const btn = getContinueButton();
if (
btn.x - btn.width / 2 <= x &&
btn.x + btn.width / 2 >= x &&
btn.y - btn.height / 2 <= y &&
btn.y + btn.height / 2 >= y
) {
state = "menu";
}
}
function getContinueButton(start) {
return {
x: canvas.width / 2,
y: canvas.height / 2 - 20,
width: 120,
height: 40,
color: "grey",
text: start ? "enter" : "continue",
};
}