Added music
This commit is contained in:
parent
9c10c76266
commit
2a24c6528e
3
TODO.txt
3
TODO.txt
|
@ -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.
|
@ -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
|
||||
|
|
24
src/mixer.c
24
src/mixer.c
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue