From afdfefd352f5b2ce4f3248f3581067e6496d0c38 Mon Sep 17 00:00:00 2001 From: rodri Date: Mon, 2 Oct 2023 12:56:47 +0000 Subject: add more sfx and do some of their orchestration. --- assets/sfx/cannon.mp3 | Bin 0 -> 37440 bytes assets/sfx/water.mp3 | Bin 0 -> 49536 bytes bts.c | 57 ++++++++++++++++++++++++++++++++++++++++---------- credits | 4 ++++ dat.h | 4 ++++ 5 files changed, 54 insertions(+), 11 deletions(-) create mode 100644 assets/sfx/cannon.mp3 create mode 100644 assets/sfx/water.mp3 diff --git a/assets/sfx/cannon.mp3 b/assets/sfx/cannon.mp3 new file mode 100644 index 0000000..07cbb6b Binary files /dev/null and b/assets/sfx/cannon.mp3 differ diff --git a/assets/sfx/water.mp3 b/assets/sfx/water.mp3 new file mode 100644 index 0000000..d4bfb43 Binary files /dev/null and b/assets/sfx/water.mp3 differ diff --git a/bts.c b/bts.c index d54d83c..767dd50 100644 --- a/bts.c +++ b/bts.c @@ -155,6 +155,7 @@ struct { struct { Image *c; /* color */ char *s; /* banner text */ + AudioSource *snd; /* victory or defeat bg sfx */ } conclusion; @@ -242,6 +243,9 @@ resetgame(void) game.state = Waiting0; conclusion.s = nil; csetcursor(mctl, nil); + audio_stop(conclusion.snd); + conclusion.snd = nil; + audio_play(playlist[SBG0]); } Point @@ -544,21 +548,33 @@ initarmada(void) void initsound(void) { + struct { + char *path; + double gain; + int loops; + } sndtab[NSOUNDS] = { + [SBG0] {"assets/sfx/bg0.mp3", 1.0, 1}, + [SBG1] {"assets/sfx/bg1.mp3", 1.0, 1}, + [SBG2] {"assets/sfx/bg2.mp3", 1.0, 1}, + [SCANNON] {"assets/sfx/cannon.mp3", 5.0, 0}, + [SWATER] {"assets/sfx/water.mp3", 3.0, 0}, + [SVICTORY] {"assets/sfx/victory.mp3", 1.0, 1}, + [SDEFEAT] {"assets/sfx/defeat.mp3", 1.0, 1}, + }; + int i; + audio_init(44100); audio_set_master_gain(0.5); - playlist[SBG0] = audio_new_source_from_mp3file("assets/sfx/bg0.mp3"); - if(playlist[SBG0] == nil) - sysfatal("audio_new_source_from_mp3file: %r"); - playlist[SBG1] = audio_new_source_from_mp3file("assets/sfx/bg1.mp3"); - if(playlist[SBG1] == nil) - sysfatal("audio_new_source_from_mp3file: %r"); - playlist[SBG2] = audio_new_source_from_mp3file("assets/sfx/bg2.mp3"); - if(playlist[SBG2] == nil) - sysfatal("audio_new_source_from_mp3file: %r"); + for(i = 0; i < NSOUNDS; i++){ + playlist[i] = audio_new_source_from_file(sndtab[i].path); + if(playlist[i] == nil) + sysfatal("audio_new_source_from_file: %r"); + audio_set_gain(playlist[i], sndtab[i].gain); + audio_set_loop(playlist[i], sndtab[i].loops); + } audio_play(playlist[SBG0]); - audio_set_loop(playlist[SBG0], 1); } int @@ -621,6 +637,7 @@ lmb(Mousectl *mc) if(!ptinrect(mc->xy, alienboard.bbox)) break; + audio_play(playlist[SCANNON]); cell = toboard(&alienboard, mc->xy); chanprint(egress, "shoot %s\n", cell2coords(cell)); lastshot = cell; @@ -797,6 +814,10 @@ celebrate(void) conclusion.c = pal[PCGreen]; conclusion.s = s; + conclusion.snd = playlist[SVICTORY]; + + audio_stop(playlist[SBG2]); + audio_play(conclusion.snd); } void @@ -806,6 +827,10 @@ keelhaul(void) conclusion.c = pal[PCRed]; conclusion.s = s; + conclusion.snd = playlist[SDEFEAT]; + + audio_stop(playlist[SBG2]); + audio_play(conclusion.snd); } void @@ -819,6 +844,10 @@ announcewinner(char *winner) snprint(s, sizeof s, "%s WON", winner); conclusion.c = pal[PCGreen]; conclusion.s = s; + conclusion.snd = playlist[SVICTORY]; + + audio_stop(playlist[SBG2]); + audio_play(conclusion.snd); } void @@ -868,12 +897,16 @@ processcmd(char *cmd) match.bl[0] = &localboard; match.bl[1] = &alienboard; game.state = Watching; + audio_stop(playlist[SBG0]); + audio_play(playlist[SBG2]); } break; case Ready: if(ct->index == CMlayout){ game.state = Outlaying; curship = &armada[0]; + audio_stop(playlist[SBG0]); + audio_play(playlist[SBG2]); }else if(ct->index == CMoid) snprint(oid, sizeof oid, "%s", cb->f[1]); break; @@ -914,8 +947,10 @@ processcmd(char *cmd) csetcursor(mctl, &waitcursor); }else if(ct->index == CMwehit) settile(&alienboard, lastshot, Thit); - else if(ct->index == CMwemiss) + else if(ct->index == CMwemiss){ + audio_play(playlist[SWATER]); settile(&alienboard, lastshot, Tmiss); + } break; case Waiting: if(ct->index == CMplay){ diff --git a/credits b/credits index ae48a53..8545c75 100644 --- a/credits +++ b/credits @@ -6,6 +6,10 @@ assets/sfx/bg1.mp3 “Creepy Ambient (107 bpm).wav”, by SoundFlakes, 2017 assets/sfx/bg2.mp3 “Space Emergency.mp3”, by SoundFlakes, 2019 +assets/sfx/cannon.mp3 + “Ship artillery blast classic.wav”, by CGEffex, 2010 +assets/sfx/water.mp3 + “Water Explosion”, by Sheyvan, 2020 assets/sfx/victory.mp3 “Epic Action Theme”, by BloodPixelHero, 2022 assets/sfx/defeat.mp3 diff --git a/dat.h b/dat.h index 174f806..46a3c12 100644 --- a/dat.h +++ b/dat.h @@ -40,6 +40,10 @@ enum { SBG0 = 0, SBG1, SBG2, + SCANNON, + SWATER, + SVICTORY, + SDEFEAT, NSOUNDS, KB = 1024, -- cgit v1.2.3