From 7bb8b8c7670728b0dcd510d8a8205bb3776368dd Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sat, 5 Apr 2025 22:16:15 +0100 Subject: Add audio to web and images to SDL --- src/index.html.in | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/index.html.in') diff --git a/src/index.html.in b/src/index.html.in index 8d0ccea..aca8b6d 100644 --- a/src/index.html.in +++ b/src/index.html.in @@ -36,6 +36,9 @@ const INPUT_PAUSE_PLAY = 3; const WASM = #include "../build/main.wasm.b64" +const MUSIC = +#include "../build/music.mp3.b64" + async function main() { let bytes = Uint8Array.from(atob(WASM), function(c) { return c.charCodeAt(0); @@ -48,6 +51,12 @@ async function main() { let ctx = canvas.getContext("2d"); let memory = exports.memory; + const audio = new Audio(); + audio.src = MUSIC; + audio.volume = 0.2; + audio.loop = true; + let musicPlaying = false; + const start = Date.now(); function now() { return Date.now() - start; @@ -94,6 +103,10 @@ async function main() { e.preventDefault(); exports.game_update(INPUT_RCLICK, mousex, mousey, now()); } + if (!musicPlaying) { + musicPlaying = true; + audio.play(); + } }); canvas.addEventListener("contextmenu", function (e) { -- cgit v1.2.3