41 lines
822 B
HTML
41 lines
822 B
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8"/>
|
|
<title>Rust WASM Game Window</title>
|
|
</head>
|
|
<body style="margin:0; background:#222; display:flex; justify-content:center; align-items:center; height:100vh;">
|
|
<canvas id="game-canvas"></canvas>
|
|
<script type="module">
|
|
import init, { Game } from "./pkg/hyperbolic_asteroids.js";
|
|
async function run() {
|
|
await init();
|
|
let game = new Game("game-canvas");
|
|
let last = performance.now();
|
|
|
|
window.addEventListener("keydown", e => {
|
|
game.key_down(e.key);
|
|
});
|
|
window.addEventListener("keyup", e => {
|
|
game.key_up(e.key);
|
|
});
|
|
|
|
function loop(now) {
|
|
const dt = (now - last);
|
|
last = now;
|
|
game.update(dt);
|
|
game.draw();
|
|
|
|
requestAnimationFrame(loop);
|
|
}
|
|
|
|
//game.update(1);
|
|
requestAnimationFrame(loop);
|
|
}
|
|
|
|
run();
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|