Back to shtanton's homepage
summaryrefslogtreecommitdiff
path: root/src/index.html.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.html.in')
-rw-r--r--src/index.html.in16
1 files changed, 13 insertions, 3 deletions
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) {