diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2025-04-05 13:27:26 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2025-04-05 13:27:26 +0100 |
commit | 87392b4465ff2aa2f988b07365bf6b0fa5ea3d09 (patch) | |
tree | 74f852af2b7da8e473174bbaf1b4ab632a11f9a7 /src/index.html.in | |
parent | b851d1dee56a191b3eabee957af4bb35f0a3e2cb (diff) | |
download | ldjam57-87392b4465ff2aa2f988b07365bf6b0fa5ea3d09.tar |
red
Diffstat (limited to 'src/index.html.in')
-rw-r--r-- | src/index.html.in | 29 |
1 files changed, 10 insertions, 19 deletions
diff --git a/src/index.html.in b/src/index.html.in index bd4343d..07bd618 100644 --- a/src/index.html.in +++ b/src/index.html.in @@ -29,10 +29,7 @@ button { <script> // Mirror these in src/all.c const INPUT_NONE = 0; -const INPUT_UP = 1; -const INPUT_DOWN = 2; -const INPUT_LEFT = 3; -const INPUT_RIGHT = 4; +const INPUT_CLICK = 1; const WASM = #include "../build/main.wasm.b64" @@ -65,12 +62,10 @@ async function main() { let len = dl[0]; let ops = dl.subarray(1); - console.log(new Uint32Array(ops.subarray(6, 12))); for (let i = 0; i < len; i++) { let op = ops.subarray(6*i, 6*i+6); - const color = new Uint8Array(new Uint32Array(ops.subarray(4, 6)).buffer); + 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")}`; - // console.log(color); 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.strokeRect(op[0], op[1], op[2], op[3]); @@ -81,22 +76,18 @@ async function main() { window.addEventListener("resize", onresize); onresize(); - document.addEventListener("keydown", function(e) { - if (e.key == "w") { - exports.game_update(INPUT_UP); - } else if (e.key == "a") { - exports.game_update(INPUT_LEFT); - } else if (e.key == "s") { - exports.game_update(INPUT_DOWN); - } else if (e.key == "d") { - exports.game_update(INPUT_RIGHT); - } - }) + canvas.addEventListener("mousedown", function(e) { + const mousex = e.clientX; + const mousey = e.clientY; + if (e.button == 0) { + exports.game_update(INPUT_CLICK, mousex, mousey); + } + }); function animate() { // TODO: stop requesting frames when state is static requestAnimationFrame(animate); - exports.game_update(INPUT_NONE); + exports.game_update(INPUT_NONE, 0, 0); render(); } requestAnimationFrame(animate); |