-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
74 lines (67 loc) · 2.63 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Panda Bounce User Interface</title>
<style type="text/css">
body {
margin: 0;
background-color: rgb(53, 48, 48);
display: flex;
align-items: center;
justify-content: center;
height: 100vh;
}
canvas {
border: 0px solid snow;
}
</style>
</head>
<body>
<canvas id="UI" width="1024" height="576"></canvas>
<script>
const canvas = document.getElementById("UI");
const ctx = canvas.getContext("2d");
const image = new Image();
image.src = "./img/UIBackground.jpg";
image.onload = function() {
ctx.drawImage(image, 0, 0); // 绘制图片到 canvas 的坐标 (0, 0)
//Start Button
const startBtnImage = new Image();
startBtnImage.src = "./img/startBtn.png";
startBtnImage.onload = function() {
ctx.drawImage(startBtnImage, 192, 384); // 绘制按钮图片到 canvas 的坐标 (192, 384)
};
//Practice Button
const practiceBtnImage = new Image();
practiceBtnImage.src = "./img/practiceBtn.png";
practiceBtnImage.onload = function() {
ctx.drawImage(practiceBtnImage, 448, 384);
};
//Info Button
const infoBtnImage = new Image();
infoBtnImage.src = "./img/infoBtn.png";
infoBtnImage.onload = function() {
ctx.drawImage(infoBtnImage, 704, 384);
};
// 添加按钮点击事件处理程序
canvas.addEventListener('click', function(e) {
const x = e.clientX - canvas.getBoundingClientRect().left;
const y = e.clientY - canvas.getBoundingClientRect().top;
if (x >= 192 && x <= 192 + startBtnImage.width && y >= 384 && y <= 384 + startBtnImage.height) {
// 跳转到start.html
//window.location.href = "start.html";
window.location.href = "http://localhost:3000/";
} else if (x >= 448 && x <= 448 + practiceBtnImage.width && y >= 384 && y <= 384 + practiceBtnImage.height) {
// 跳转到practice level.html
window.location.href = "http://localhost:3006/";
} else if (x >= 704 && x <= 704 + infoBtnImage.width && y >= 384 && y <= 384 + infoBtnImage.height) {
// 跳转到info.html
window.location.href = "info.html";
}
});
};
</script>
</body>
</html>