added update loop and game state.
This commit is contained in:
41
index.html
41
index.html
@@ -1,14 +1,33 @@
|
||||
<!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 from "./pkg/hyperbolic_asteroids.js";
|
||||
init();
|
||||
</script>
|
||||
</body>
|
||||
<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();
|
||||
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user