diff options
Diffstat (limited to 'src/index.html.in')
-rw-r--r-- | src/index.html.in | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/index.html.in b/src/index.html.in index 07bd618..a58354a 100644 --- a/src/index.html.in +++ b/src/index.html.in @@ -30,6 +30,7 @@ button { // Mirror these in src/all.c const INPUT_NONE = 0; const INPUT_CLICK = 1; +const INPUT_PAUSE_PLAY = 2; const WASM = #include "../build/main.wasm.b64" @@ -46,6 +47,11 @@ async function main() { let ctx = canvas.getContext("2d"); let memory = exports.memory; + const start = Date.now(); + function now() { + return Date.now() - start; + } + function min(a, b) { return b<a ? b : a; } @@ -66,8 +72,10 @@ async function main() { let op = ops.subarray(6*i, 6*i+6); const color = new Uint8Array(new Uint32Array(op.subarray(4, 6)).buffer); ctx.fillStyle = `#${color[0].toString(16).padStart(2, "0")}${color[1].toString(16).padStart(2, "0")}${color[2].toString(16).padStart(2, "0")}`; + ctx.globalAlpha = color[3] / 255; ctx.fillRect(op[0], op[1], op[2], op[3]); ctx.strokeStyle = `#${color[4].toString(16).padStart(2, "0")}${color[5].toString(16).padStart(2, "0")}${color[6].toString(16).padStart(2, "0")}`; + ctx.globalAlpha = color[7] / 255; ctx.strokeRect(op[0], op[1], op[2], op[3]); } } @@ -80,14 +88,20 @@ async function main() { const mousex = e.clientX; const mousey = e.clientY; if (e.button == 0) { - exports.game_update(INPUT_CLICK, mousex, mousey); + exports.game_update(INPUT_CLICK, mousex, mousey, now()); + } + }); + + document.addEventListener("keydown", function (e) { + if (e.key === " ") { + exports.game_update(INPUT_PAUSE_PLAY, 0, 0, now()); } }); function animate() { // TODO: stop requesting frames when state is static requestAnimationFrame(animate); - exports.game_update(INPUT_NONE, 0, 0); + exports.game_update(INPUT_NONE, 0, 0, now()); render(); } requestAnimationFrame(animate); |