Added music

This commit is contained in:
Linus Probert 2018-02-15 00:02:23 +01:00
parent 9c10c76266
commit 2a24c6528e
5 changed files with 33 additions and 2 deletions

View File

@ -35,5 +35,8 @@ x Fix crash when clicking menu items with pointer
- Make things less difficult and more interesting
- Interesting items
- A different license perhaps?
- Credit screen showing music and graphics guys:
- Music: http://soundimage.org/ (Eric Matyas)
- Graphics: (see README)
Legend: ( '-' = future) ( 'x' = completed ) ( 'o' = begun )

Binary file not shown.

View File

@ -167,6 +167,7 @@ startGame(void *unused)
if (gPlayer)
player_destroy(gPlayer);
gPlayer = player_create(WARRIOR, gRenderer);
mixer_stop_music();
resetGame();
}
@ -258,6 +259,7 @@ initMainMenu(void)
gMap = map_lua_generator_single_room__run(cLevel, gRenderer);
createMenu(&mainMenu, menu_items, 2);
mixer_play_music();
}
static void

View File

@ -10,7 +10,7 @@ load_effect(char *path)
{
Mix_Chunk *effect = Mix_LoadWAV(path);
if (effect == NULL)
fatal("Failed to load effect: %s", path);
fatal("Failed to load effect: %s", Mix_GetError());
return effect;
}
@ -24,9 +24,12 @@ void
mixer_init(void)
{
if (Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) == -1) {
fatal("Failed to load SDL2_mixer");
fatal("Failed to load sound: %s", Mix_GetError());
}
load_effects();
music = Mix_LoadMUS("assets/Sounds/Music/fantasy-forest-battle.ogg");
if (music == NULL)
fatal("Failed to load music: %s", Mix_GetError());
}
void
@ -36,6 +39,23 @@ mixer_play_effect(Fx fx)
error("Unable to play sound: %u", (unsigned int) fx);
}
void
mixer_play_music(void)
{
if (Mix_PlayingMusic())
return;
if (Mix_PlayMusic(music, -1) == -1)
fatal("Failed to play music");
}
void
mixer_stop_music(void)
{
if (Mix_PlayingMusic())
Mix_HaltMusic();
}
void
mixer_close(void)
{

View File

@ -14,6 +14,12 @@ mixer_init(void);
void
mixer_play_effect(Fx fx);
void
mixer_play_music(void);
void
mixer_stop_music(void);
void
mixer_close(void);