Back to shtanton's homepage
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/all.c21
-rw-r--r--src/index.html.in17
2 files changed, 35 insertions, 3 deletions
diff --git a/src/all.c b/src/all.c
index 7955b90..15f2558 100644
--- a/src/all.c
+++ b/src/all.c
@@ -139,7 +139,7 @@ static DrawList *render(State *state, UI *ui, Arena *a) {
.h = cellHeight,
.fill = {255, 0, 0, 63},
.border = {255, 0, 0, 255},
- .image = 5,
+ .image = 1,
};
drawList->els[drawList->len++] = (DrawElement) {
@@ -229,6 +229,10 @@ typedef struct {
SDL_Texture *textures[sizeof(images) / sizeof(images[0])];
+#include "../build/music.c"
+
+SDL_AudioStream *stream;
+
int main(int argc, char **argv) {
(void) argc;
(void) argv;
@@ -252,7 +256,7 @@ int main(int argc, char **argv) {
game->state.buttonStates[i] = BUTTON_STATE_IDLE;
}
- SDL_Init(SDL_INIT_VIDEO);
+ SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
SDL_Window *w = SDL_CreateWindow(
"LDJam 57",
game->ui.width,
@@ -282,6 +286,15 @@ int main(int argc, char **argv) {
}
SDL_UpdateTexture(textures[j], NULL, pixels, images[j].width * 4);
}
+
+ SDL_AudioSpec audioSpec = {
+ .format = SDL_AUDIO_S16LE,
+ .channels = 2,
+ .freq = 48000,
+ };
+ stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &audioSpec, NULL, NULL);
+ SDL_PutAudioStreamData(stream, musicBytes, sizeof(musicBytes));
+ SDL_ResumeAudioStreamDevice(stream);
for (;;) {
uint64_t now = SDL_GetTicks();
@@ -351,6 +364,10 @@ int main(int argc, char **argv) {
update(game, now, a);
+ if (SDL_GetAudioStreamQueued(stream) < (int) sizeof(musicBytes) / 8) {
+ SDL_PutAudioStreamData(stream, musicBytes, sizeof(musicBytes));
+ }
+
SDL_RenderPresent(r);
}
diff --git a/src/index.html.in b/src/index.html.in
index aca8b6d..c239f6e 100644
--- a/src/index.html.in
+++ b/src/index.html.in
@@ -39,6 +39,11 @@ const WASM =
const MUSIC =
#include "../build/music.mp3.b64"
+const IMAGES = [
+#include "../build/continue.png.b64"
+,
+];
+
async function main() {
let bytes = Uint8Array.from(atob(WASM), function(c) {
return c.charCodeAt(0);
@@ -57,6 +62,13 @@ async function main() {
audio.loop = true;
let musicPlaying = false;
+ let images = [null];
+ for (let i = 0; i < IMAGES.length; i++) {
+ const image = new Image();
+ image.src = IMAGES[i];
+ images.push(image);
+ }
+
const start = Date.now();
function now() {
return Date.now() - start;
@@ -79,7 +91,7 @@ async function main() {
let ops = dl.subarray(1);
for (let i = 0; i < len; i++) {
- let op = ops.subarray(6*i, 6*i+6);
+ let op = ops.subarray(7*i, 7*i+7);
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;
@@ -87,6 +99,9 @@ async function main() {
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]);
+ if (op[6] !== 0) {
+ ctx.drawImage(images[op[6]], op[0], op[1], op[2], op[3]);
+ }
}
}