add sound
This commit is contained in:
parent
99d9c43ea3
commit
01d6e09a91
22 changed files with 1825 additions and 39 deletions
|
|
@ -1,5 +1,6 @@
|
|||
(local pxl8 (require :pxl8))
|
||||
(local menu (require :mod.menu))
|
||||
(local music (require :mod.music))
|
||||
(local worldgen (require :mod.worldgen))
|
||||
|
||||
(var time 0)
|
||||
|
|
@ -29,6 +30,8 @@
|
|||
(pxl8.load_palette "res/sprites/pxl8_logo.ase")
|
||||
(set logo-sprite (pxl8.load_sprite "res/sprites/pxl8_logo.ase"))
|
||||
(set particles (pxl8.particles_new 1000))
|
||||
(music.init)
|
||||
(music.start)
|
||||
(worldgen.init)))
|
||||
|
||||
(global update (fn [dt]
|
||||
|
|
@ -79,6 +82,8 @@
|
|||
(set logo-dy (- logo-dy))))
|
||||
:worldgen (worldgen.update dt))
|
||||
|
||||
(music.update dt)
|
||||
|
||||
(when particles
|
||||
(pxl8.particles_update particles dt)))
|
||||
|
||||
|
|
|
|||
68
demo/mod/music.fnl
Normal file
68
demo/mod/music.fnl
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
(local pxl8 (require :pxl8))
|
||||
|
||||
(var time 0)
|
||||
(var step 0)
|
||||
(var ctx nil)
|
||||
(var params nil)
|
||||
(var bass-params nil)
|
||||
(var playing false)
|
||||
|
||||
(local melody [60 64 67 72 67 64 60 64 67 72 76 72 67 64 62 66 69 74 69 66 62 66 69 74 78 74 69 66])
|
||||
(local bass [36 50 40 36 38 38 50 38])
|
||||
(local step-duration 0.15)
|
||||
|
||||
(fn init []
|
||||
(set ctx (pxl8.sfx_context_create))
|
||||
|
||||
(local delay (pxl8.sfx_delay_create {:time_l 350 :time_r 500 :feedback 0.4 :mix 0.25}))
|
||||
(local reverb (pxl8.sfx_reverb_create {:room 0.5 :damping 0.5 :mix 0.3}))
|
||||
(local compressor (pxl8.sfx_compressor_create {:threshold -12 :ratio 4 :attack 10 :release 100}))
|
||||
|
||||
(pxl8.sfx_context_append_node ctx delay)
|
||||
(pxl8.sfx_context_append_node ctx reverb)
|
||||
(pxl8.sfx_context_append_node ctx compressor)
|
||||
|
||||
(pxl8.sfx_mixer_attach ctx)
|
||||
|
||||
(set params (pxl8.sfx_voice_params
|
||||
{:waveform pxl8.SFX_WAVE_TRIANGLE
|
||||
:attack 0.005 :decay 0.08 :sustain 0.0 :release 0.05
|
||||
:filter_type pxl8.SFX_FILTER_LOWPASS
|
||||
:filter_cutoff 2500 :filter_resonance 0.15
|
||||
:filter_attack 0.005 :filter_decay 0.1 :filter_sustain 0.1 :filter_release 0.05
|
||||
:filter_env_depth 1500
|
||||
:fx_send 0.3}))
|
||||
|
||||
(set bass-params (pxl8.sfx_voice_params
|
||||
{:waveform pxl8.SFX_WAVE_SQUARE
|
||||
:attack 0.005 :decay 0.1 :sustain 0.0 :release 0.05
|
||||
:filter_type pxl8.SFX_FILTER_LOWPASS
|
||||
:filter_cutoff 600 :filter_resonance 0.2
|
||||
:fx_send 0.2})))
|
||||
|
||||
(fn start []
|
||||
(set playing true)
|
||||
(set time 0)
|
||||
(set step 0))
|
||||
|
||||
(fn stop []
|
||||
(set playing false)
|
||||
(pxl8.sfx_stop_all ctx))
|
||||
|
||||
(fn update [dt]
|
||||
(when playing
|
||||
(set time (+ time dt))
|
||||
(when (>= time step-duration)
|
||||
(set time (- time step-duration))
|
||||
(local note (. melody (+ 1 (% step (length melody)))))
|
||||
(pxl8.sfx_play_note ctx note params 0.4)
|
||||
(when (= (% step 4) 0)
|
||||
(local bass-note (. bass (+ 1 (% (math.floor (/ step 4)) (length bass)))))
|
||||
(pxl8.sfx_play_note ctx bass-note bass-params 0.35))
|
||||
(set step (+ step 1)))))
|
||||
|
||||
{:init init
|
||||
:start start
|
||||
:stop stop
|
||||
:update update
|
||||
:is-playing (fn [] playing)}
|
||||
BIN
demo/res/tiles/tilesheet-dungeon.ase
Normal file
BIN
demo/res/tiles/tilesheet-dungeon.ase
Normal file
Binary file not shown.
BIN
demo/res/tiles/tilesheet-world.ase
Normal file
BIN
demo/res/tiles/tilesheet-world.ase
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue