From 272e0bc6152fc84873aa18879cf3352b174ec072 Mon Sep 17 00:00:00 2001 From: asrael Date: Thu, 8 Jan 2026 14:49:45 -0600 Subject: [PATCH] fix logo bounce, adjust music a bit --- demo/main.fnl | 16 +++++++++---- demo/mod/music.fnl | 54 ++++++++++++++++++++++++------------------- src/lua/pxl8/anim.lua | 4 ++-- src/pxl8_anim.c | 4 ++-- src/pxl8_anim.h | 2 +- src/pxl8_script.c | 2 +- src/pxl8_sfx.h | 4 ++-- 7 files changed, 50 insertions(+), 36 deletions(-) diff --git a/demo/main.fnl b/demo/main.fnl index 216ae6e..47f9ea0 100644 --- a/demo/main.fnl +++ b/demo/main.fnl @@ -76,10 +76,18 @@ :logo (do (set logo-x (+ logo-x (* logo-dx dt))) (set logo-y (+ logo-y (* logo-dy dt))) - (when (or (< logo-x 0) (> logo-x 512)) - (set logo-dx (- logo-dx))) - (when (or (< logo-y 0) (> logo-y 296)) - (set logo-dy (- logo-dy)))) + (when (< logo-x 0) + (set logo-x 0) + (set logo-dx (math.abs logo-dx))) + (when (> logo-x 512) + (set logo-x 512) + (set logo-dx (- (math.abs logo-dx)))) + (when (< logo-y 0) + (set logo-y 0) + (set logo-dy (math.abs logo-dy))) + (when (> logo-y 296) + (set logo-y 296) + (set logo-dy (- (math.abs logo-dy))))) :worldgen (worldgen.update dt)) (music.update dt) diff --git a/demo/mod/music.fnl b/demo/mod/music.fnl index d8ff199..363788b 100644 --- a/demo/mod/music.fnl +++ b/demo/mod/music.fnl @@ -1,10 +1,27 @@ +;; ============================================================================ +;; Theme in A minor +;; Key: Am | Tempo: 95 BPM | Time: 4/4 +;; ============================================================================ +;; +;; Melody (Triangle, A4 range): +;; Bar 1: A4~ .C5 | E5 D5 | C5 A4 | G4 A4 | +;; Bar 2: A4~ .C5 | E5 G5 | F5 E5 | D5~~~~ | +;; Bar 3: D5~ .E5 | F5 D5 | C5 A4 | G4 A4 | +;; Bar 4: C5~ .D5 | E5 C5 | A4 G4 | A4~~~~ | +;; +;; Bass (Triangle, A2 range, octave jumps): +;; | A2 A2 A3 A2 | A2 A3 A2 A3 | C3 C3 C4 C3 | C3 C4 C3 C4 | +;; | D3 D3 D4 D3 | D3 D4 D3 D4 | A2 A2 A3 A2 | A2 A3 E3 A2 | +;; +;; Legend: ~ = held note, . = sixteenth rest before +;; ============================================================================ + (local pxl8 (require :pxl8)) (var time 0) (var step 0) (var ctx nil) (var melody-params nil) -(var harmony-params nil) (var bass-params nil) (var playing false) @@ -13,7 +30,7 @@ (local sixteenth (/ beat 4)) (local eighth (/ beat 2)) (local quarter beat) -(local whole (* 4 beat)) +(local _whole (* 4 beat)) (local melody [[69 eighth] [0 sixteenth] [72 sixteenth] [76 eighth] [74 eighth] @@ -35,11 +52,6 @@ [69 eighth] [67 eighth] [69 quarter]]) -(local harmony [[57 whole] ; A3 - [60 whole] ; C4 - [62 whole] ; D4 - [57 whole]]) ; A3 - (local bass [[45 eighth] [45 eighth] [57 eighth] [45 eighth] [45 eighth] [57 eighth] [45 eighth] [57 eighth] [48 eighth] [48 eighth] [60 eighth] [48 eighth] @@ -53,6 +65,14 @@ (fn init [] (set ctx (pxl8.sfx_context_create)) + + (local reverb (pxl8.sfx_reverb_create + {:room 0.5 :damping 0.4 :mix 0.35})) + (local compressor (pxl8.sfx_compressor_create + {:threshold -18 :ratio 6 :attack 3 :release 100})) + (pxl8.sfx_context_append_node ctx reverb) + (pxl8.sfx_context_append_node ctx compressor) + (pxl8.sfx_mixer_attach ctx) (set melody-params (pxl8.sfx_voice_params @@ -60,21 +80,14 @@ :attack 0.02 :decay 0.15 :sustain 0.5 :release 0.15 :filter_type pxl8.SFX_FILTER_LOWPASS :filter_cutoff 4000 :filter_resonance 0.0 - :fx_send 0.0})) - - (set harmony-params (pxl8.sfx_voice_params - {:waveform pxl8.SFX_WAVE_TRIANGLE - :attack 0.05 :decay 0.2 :sustain 0.3 :release 0.2 - :filter_type pxl8.SFX_FILTER_LOWPASS - :filter_cutoff 2500 :filter_resonance 0.0 - :fx_send 0.0})) + :fx_send 0.4})) (set bass-params (pxl8.sfx_voice_params {:waveform pxl8.SFX_WAVE_TRIANGLE :attack 0.015 :decay 0.1 :sustain 0.7 :release 0.1 :filter_type pxl8.SFX_FILTER_LOWPASS - :filter_cutoff 1200 :filter_resonance 0.0 - :fx_send 0.0}))) + :filter_cutoff 1800 :filter_resonance 0.0 + :fx_send 0.15}))) (fn start [] (set playing true) @@ -98,13 +111,6 @@ (when (> melody-note 0) (pxl8.sfx_play_note ctx melody-note melody-params 0.45 melody-dur)) - (local bar (math.floor (/ step 32))) - (local harmony-idx (+ 1 (% bar (length harmony)))) - (local harmony-entry (. harmony harmony-idx)) - (local harmony-note (. harmony-entry 1)) - (when (= (% step 32) 0) - (pxl8.sfx_play_note ctx harmony-note harmony-params 0.25 whole)) - (local bass-step (math.floor (/ step 2))) (local bass-idx (+ 1 (% bass-step (length bass)))) (local bass-entry (. bass bass-idx)) diff --git a/src/lua/pxl8/anim.lua b/src/lua/pxl8/anim.lua index d15ba5c..2d349cc 100644 --- a/src/lua/pxl8/anim.lua +++ b/src/lua/pxl8/anim.lua @@ -71,8 +71,8 @@ function anim.play(a) C.pxl8_anim_play(a) end -function anim.render_sprite(a, x, y, w, h) - C.pxl8_anim_render_sprite(a, core.gfx, x, y, w, h) +function anim.render_sprite(a, x, y, w, h, flip_x, flip_y) + C.pxl8_anim_render_sprite(a, core.gfx, x, y, w, h, flip_x or false, flip_y or false) end function anim.reset(a) diff --git a/src/pxl8_anim.c b/src/pxl8_anim.c index ab9cd90..6dacfdb 100644 --- a/src/pxl8_anim.c +++ b/src/pxl8_anim.c @@ -284,11 +284,11 @@ void pxl8_anim_play(pxl8_anim* anim) { anim->playing = true; } -void pxl8_anim_render_sprite(const pxl8_anim* anim, pxl8_gfx* gfx, i32 x, i32 y, i32 w, i32 h) { +void pxl8_anim_render_sprite(const pxl8_anim* anim, pxl8_gfx* gfx, i32 x, i32 y, i32 w, i32 h, bool flip_x, bool flip_y) { if (!anim || !gfx) return; u32 sprite_id = pxl8_anim_get_current_frame_id(anim); - pxl8_sprite(gfx, sprite_id, x, y, w, h); + pxl8_sprite(gfx, sprite_id, x, y, w, h, flip_x, flip_y); } void pxl8_anim_reset(pxl8_anim* anim) { diff --git a/src/pxl8_anim.h b/src/pxl8_anim.h index 3cac3bb..26f6532 100644 --- a/src/pxl8_anim.h +++ b/src/pxl8_anim.h @@ -41,7 +41,7 @@ bool pxl8_anim_is_complete(const pxl8_anim* anim); bool pxl8_anim_is_playing(const pxl8_anim* anim); void pxl8_anim_pause(pxl8_anim* anim); void pxl8_anim_play(pxl8_anim* anim); -void pxl8_anim_render_sprite(const pxl8_anim* anim, pxl8_gfx* gfx, i32 x, i32 y, i32 w, i32 h); +void pxl8_anim_render_sprite(const pxl8_anim* anim, pxl8_gfx* gfx, i32 x, i32 y, i32 w, i32 h, bool flip_x, bool flip_y); void pxl8_anim_reset(pxl8_anim* anim); void pxl8_anim_set_frame(pxl8_anim* anim, u16 frame); void pxl8_anim_set_loop(pxl8_anim* anim, bool loop); diff --git a/src/pxl8_script.c b/src/pxl8_script.c index c89d06f..3c18186 100644 --- a/src/pxl8_script.c +++ b/src/pxl8_script.c @@ -319,7 +319,7 @@ static const char* pxl8_ffi_cdefs = "bool pxl8_anim_is_playing(const pxl8_anim* anim);\n" "void pxl8_anim_pause(pxl8_anim* anim);\n" "void pxl8_anim_play(pxl8_anim* anim);\n" -"void pxl8_anim_render_sprite(const pxl8_anim* anim, pxl8_gfx* gfx, i32 x, i32 y, i32 w, i32 h);\n" +"void pxl8_anim_render_sprite(const pxl8_anim* anim, pxl8_gfx* gfx, i32 x, i32 y, i32 w, i32 h, bool flip_x, bool flip_y);\n" "void pxl8_anim_reset(pxl8_anim* anim);\n" "void pxl8_anim_set_frame(pxl8_anim* anim, u16 frame);\n" "void pxl8_anim_set_loop(pxl8_anim* anim, bool loop);\n" diff --git a/src/pxl8_sfx.h b/src/pxl8_sfx.h index 587ade7..58520a0 100644 --- a/src/pxl8_sfx.h +++ b/src/pxl8_sfx.h @@ -5,9 +5,9 @@ #define PXL8_SFX_BUFFER_SIZE 1024 #define PXL8_SFX_MAX_CONTEXTS 8 -#define PXL8_SFX_MAX_DELAY_SAMPLES 44100 +#define PXL8_SFX_MAX_DELAY_SAMPLES 48000 #define PXL8_SFX_MAX_VOICES 16 -#define PXL8_SFX_SAMPLE_RATE 44100 +#define PXL8_SFX_SAMPLE_RATE 48000 typedef struct pxl8_sfx_context pxl8_sfx_context; typedef struct pxl8_sfx_mixer pxl8_sfx_mixer;