From 775d80fe2ea7c541eb3f1180e02a48ae5498743e Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sun, 6 Apr 2025 16:42:26 +0100 Subject: Improves how click creates stuff --- src/index.html.in | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/index.html.in') diff --git a/src/index.html.in b/src/index.html.in index c239f6e..6147475 100644 --- a/src/index.html.in +++ b/src/index.html.in @@ -32,6 +32,7 @@ const INPUT_NONE = 0; const INPUT_CLICK = 1; const INPUT_RCLICK = 2; const INPUT_PAUSE_PLAY = 3; +const INPUT_MOVE = 4; const WASM = #include "../build/main.wasm.b64" @@ -56,6 +57,9 @@ async function main() { let ctx = canvas.getContext("2d"); let memory = exports.memory; + let mousex = 0; + let mousey = 0; + const audio = new Audio(); audio.src = MUSIC; audio.volume = 0.2; @@ -85,7 +89,7 @@ async function main() { function render() { let width = canvas.width = min(html.clientWidth, max_width()); let height = canvas.height = width; - let ptr = exports.game_render(width, height); + let ptr = exports.game_render(width, height, mousex, mousey); let dl = new Int32Array(memory.buffer, ptr); let len = dl[0]; let ops = dl.subarray(1); @@ -109,9 +113,15 @@ async function main() { window.addEventListener("resize", onresize); onresize(); + canvas.addEventListener("mousemove", function(e) { + mousex = e.clientX; + mousey = e.clientY; + exports.game_update(INPUT_MOVE, mousex, mousey, now()); + }); + canvas.addEventListener("mousedown", function(e) { - const mousex = e.clientX; - const mousey = e.clientY; + mousex = e.clientX; + mousey = e.clientY; if (e.button == 0) { exports.game_update(INPUT_CLICK, mousex, mousey, now()); } else if (e.button == 2) { -- cgit v1.2.3