Mercurial > molko
changeset 208:c0e0d4accae8
rpg: add music support in battle
author | David Demelier <markand@malikania.fr> |
---|---|
date | Wed, 11 Nov 2020 16:31:55 +0100 |
parents | 133926e08d6e |
children | 23a844fdc911 |
files | librpg/rpg/battle-state-closing.c librpg/rpg/battle-state-lost.c librpg/rpg/battle-state-victory.c librpg/rpg/battle.c librpg/rpg/battle.h |
diffstat | 5 files changed, 25 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/librpg/rpg/battle-state-closing.c Wed Nov 11 16:09:43 2020 +0100 +++ b/librpg/rpg/battle-state-closing.c Wed Nov 11 16:31:55 2020 +0100 @@ -20,6 +20,7 @@ #include <stdlib.h> #include <core/alloc.h> +#include <core/music.h> #include <core/painter.h> #include <core/panic.h> #include <core/texture.h> @@ -35,7 +36,6 @@ unsigned int elapsed; }; - static bool update(struct battle_state *st, struct battle *bt, unsigned int ticks) { @@ -48,8 +48,10 @@ if (closing->elapsed > 8) { closing->elapsed = 0; - if (closing->alpha == 255) + if (closing->alpha == 255) { + music_stop(0); return true; + } closing->alpha += 5; texture_set_alpha_mod(&closing->texture, closing->alpha);
--- a/librpg/rpg/battle-state-lost.c Wed Nov 11 16:09:43 2020 +0100 +++ b/librpg/rpg/battle-state-lost.c Wed Nov 11 16:31:55 2020 +0100 @@ -19,6 +19,7 @@ #include <assert.h> #include <core/alloc.h> +#include <core/music.h> #include <core/panic.h> #include <core/window.h> @@ -99,4 +100,7 @@ bt->status = BATTLE_STATUS_LOST; battle_switch(bt, &lost->self); + + if (bt->music[2]) + music_play(bt->music[2], MUSIC_NONE, 0); }
--- a/librpg/rpg/battle-state-victory.c Wed Nov 11 16:09:43 2020 +0100 +++ b/librpg/rpg/battle-state-victory.c Wed Nov 11 16:31:55 2020 +0100 @@ -19,6 +19,7 @@ #include <assert.h> #include <core/alloc.h> +#include <core/music.h> #include <core/panic.h> #include <core/window.h> @@ -100,4 +101,7 @@ bt->status = BATTLE_STATUS_WON; battle_switch(bt, &vic->self); + + if (bt->music[1]) + music_play(bt->music[1], MUSIC_NONE, 0); }
--- a/librpg/rpg/battle.c Wed Nov 11 16:09:43 2020 +0100 +++ b/librpg/rpg/battle.c Wed Nov 11 16:31:55 2020 +0100 @@ -24,6 +24,7 @@ #include <core/alloc.h> #include <core/event.h> #include <core/font.h> +#include <core/music.h> #include <core/painter.h> #include <core/sprite.h> #include <core/texture.h> @@ -252,6 +253,10 @@ /* Start the state "opening" animation. */ battle_state_opening(bt); + + /* Play music if present. */ + if (bt->music[0]) + music_play(bt->music[0], MUSIC_LOOP, 0); } void
--- a/librpg/rpg/battle.h Wed Nov 11 16:09:43 2020 +0100 +++ b/librpg/rpg/battle.h Wed Nov 11 16:31:55 2020 +0100 @@ -36,7 +36,7 @@ union event; struct character; -struct sound; +struct music; struct spell; struct theme; @@ -121,8 +121,14 @@ /** * (+&?) A music to play. + * + * Music to play in the battle: + * + * - [0]: while the battle is running, + * - [1]: in case of victory, + * - [2]: in case of lost. */ - struct sound *music; + struct music *music[3]; /** * (+&?) Theme to use.