-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
128 lines (110 loc) · 4.1 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!DOCTYPE html>
<html>
<head>
<style>
html, body {
margin: 0;
width: 100%;
height: 100%;
overflow: hidden;
background-color: black;
font-family: sans-serif;
}
body {
display: flex;
}
#overlay {
position: fixed;
background-color: transparent;
color: white;
}
#scores-div {
display: flex;
flex-direction: column;
}
#scores-container {
padding-top: 40px;
width: 100%;
box-sizing: border-box;
display: flex;
flex-direction: column;
}
.player-container {
display: flex;
justify-content: space-between;
font: 40px sans-serif;
color: white;
width: 100%;
padding: 10px 40px;
box-sizing: border-box;
}
.player-name {
color: transparent;
}
.dead-player {
background-image: linear-gradient(to right, blue, red);
background-repeat: no-repeat;
background-size: 100% 3px;
background-position: 0 55%;
}
</style>
<link rel="stylesheet" href="./state/overlay.css">
</head>
<body>
<canvas id="game-canvas"></canvas>
<div id="overlay"></div>
<div id="scores-container"></div>
</body>
<script src="./colour.js"></script>
<script src="./config.js"></script>
<script src="./powerup/powerup.js"></script>
<script src="./powerup/speed.js"></script>
<script src="./powerup/width.js"></script>
<script src="./powerup/border.js"></script>
<script src="./powerup/invincibility.js"></script>
<script src="./powerup/key_change.js"></script>
<script src="./powerup/clear_board.js"></script>
<script src="./game.js"></script>
<script src="./player.js"></script>
<script src="./obstacle.js"></script>
<script src="./scoreboard.js"></script>
<script src="./button.js"></script>
<script src="./state/state.js"></script>
<script src="./state/start_screen.js"></script>
<script src="./state/pre_round.js"></script>
<script src="./state/in_round.js"></script>
<script src="./state/end_round.js"></script>
<script src="./state/end_screen.js"></script>
<script>
/** @type {HTMLCanvasElement}*/
const canvas = document.querySelector("#game-canvas")
/** @type {HTMLDivElement}*/
const overlay = document.querySelector("#overlay")
const scores = document.querySelector("#scores-container")
const ctx = canvas.getContext("2d")
ctx.imageSmoothingEnabled = false
resizeHandler()
function resizeHandler() {
// TODO: bug when the window is very narrow
const scoresWidth = Math.round(window.innerWidth / 5)
const canvasWidth = window.innerWidth - scoresWidth
canvas.width = canvas.height = Math.min(canvasWidth, window.innerHeight)
scores.width = window.innerWidth - canvas.width
overlay.style.width = canvas.width + "px"
overlay.style.height = canvas.height + "px"
ctx.setTransform(canvas.width, 0, 0, canvas.height, 0, 0)
}
window.addEventListener("resize", resizeHandler)
const scoreboard = new Scoreboard(document.querySelector("#scores-container"))
/** @type {Game} */
const game = new Game(ctx, overlay, scoreboard)
window.addEventListener("keydown", event => game.keyHandler(event))
window.addEventListener("keyup", event => game.keyHandler(event))
window.addEventListener("resize", () => game.resizeHandler())
function requestRepaint() {
game.render()
window.requestAnimationFrame(requestRepaint)
}
requestRepaint()
</script>
</html>