-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
113 lines (105 loc) · 4.07 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
<html>
<head>
<meta charset="utf-8"/>
<style>
body {
background: rgb(38, 38, 38);
text-align: center;
}
div.controls {
position: absolute;
width: 99%;
bottom: 10px;
left: auto;
right: auto;
color: white;
font-family: 'Montserrat', sans-serif;
}
canvas:focus {
outline: 4px solid rgb(65 139 117);
}
canvas:focus-visible {
outline: 4px solid rgb(65 139 117);
}
span.keys {
color: rgb(111, 188, 165);
}
</style>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Montserrat&display=swap" rel="stylesheet">
</head>
<script>
// From: https://github.com/NiklasEi/bevy_kira_audio
// Insert hack to make sound autoplay on Chrome as soon as the user interacts with the tab:
// https://developers.google.com/web/updates/2018/11/web-audio-autoplay#moving-forward
// the following function keeps track of all AudioContexts and resumes them on the first user
// interaction with the page. If the function is called and all contexts are already running,
// it will remove itself from all event listeners.
(function () {
// An array of all contexts to resume on the page
const audioContextList = [];
// An array of various user interaction events we should listen for
const userInputEventNames = [
"click",
"contextmenu",
"auxclick",
"dblclick",
"mousedown",
"mouseup",
"pointerup",
"touchend",
"keydown",
"keyup",
];
// A proxy object to intercept AudioContexts and
// add them to the array for tracking and resuming later
self.AudioContext = new Proxy(self.AudioContext, {
construct(target, args) {
const result = new target(...args);
audioContextList.push(result);
return result;
},
});
// To resume all AudioContexts being tracked
function resumeAllContexts(_event) {
let count = 0;
audioContextList.forEach((context) => {
if (context.state !== "running") {
context.resume();
} else {
count++;
}
});
// If all the AudioContexts have now resumed then we unbind all
// the event listeners from the page to prevent unnecessary resume attempts
// Checking count > 0 ensures that the user interaction happens AFTER the game started up
if (count > 0 && count === audioContextList.length) {
userInputEventNames.forEach((eventName) => {
document.removeEventListener(eventName, resumeAllContexts);
});
}
}
// We bind the resume function for each user interaction
// event on the page
userInputEventNames.forEach((eventName) => {
document.addEventListener(eventName, resumeAllContexts);
});
})();
</script>
<script type="module">
import init from './target/wasm.js'
init()
</script>
<body>
<div class="controls">
<h1>Controls</h1>
<p><i>Ensure keyboard has focus by clicking on the game canvas above once it loaded; this shows a green border.</i></p>
<p><span class="keys">W/A/S/D</span> or <span class="keys"></span>arrow keys</span> to move cursor (the dark grey cube)</p>
<p><span class="keys">Q/E</span> or <span class="keys">TAB</span> to change current inventory slot</p>
<p><span class="keys">SPACE</span> to place a building</p>
<p><span class="keys">R</span> to reset a level and retry</p>
<p><span class="keys">ESC</span> to exit game at any time</p>
</div>
</body>
</html>