Back to shtanton's homepage
summaryrefslogtreecommitdiff
path: root/src/index.html.in
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2025-04-05 15:05:34 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2025-04-05 15:05:34 +0100
commitf836fce772695c4cd5913dd46f49f071efbea63d (patch)
tree0bd24ada0191653d9730f0175826e80d88a1c0bf /src/index.html.in
parent721f08c3dbd88575253540206355b9eb8ee55f45 (diff)
downloadldjam57-f836fce772695c4cd5913dd46f49f071efbea63d.tar
Add vertical reds and port to webasm again
Diffstat (limited to 'src/index.html.in')
-rw-r--r--src/index.html.in18
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);