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
|
- Make things less difficult and more interesting
|
||||||
- Interesting items
|
- Interesting items
|
||||||
- A different license perhaps?
|
- 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 )
|
Legend: ( '-' = future) ( 'x' = completed ) ( 'o' = begun )
|
||||||
|
|
Binary file not shown.
|
@ -167,6 +167,7 @@ startGame(void *unused)
|
||||||
if (gPlayer)
|
if (gPlayer)
|
||||||
player_destroy(gPlayer);
|
player_destroy(gPlayer);
|
||||||
gPlayer = player_create(WARRIOR, gRenderer);
|
gPlayer = player_create(WARRIOR, gRenderer);
|
||||||
|
mixer_stop_music();
|
||||||
resetGame();
|
resetGame();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,6 +259,7 @@ initMainMenu(void)
|
||||||
gMap = map_lua_generator_single_room__run(cLevel, gRenderer);
|
gMap = map_lua_generator_single_room__run(cLevel, gRenderer);
|
||||||
|
|
||||||
createMenu(&mainMenu, menu_items, 2);
|
createMenu(&mainMenu, menu_items, 2);
|
||||||
|
mixer_play_music();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
24
src/mixer.c
24
src/mixer.c
|
@ -10,7 +10,7 @@ load_effect(char *path)
|
||||||
{
|
{
|
||||||
Mix_Chunk *effect = Mix_LoadWAV(path);
|
Mix_Chunk *effect = Mix_LoadWAV(path);
|
||||||
if (effect == NULL)
|
if (effect == NULL)
|
||||||
fatal("Failed to load effect: %s", path);
|
fatal("Failed to load effect: %s", Mix_GetError());
|
||||||
return effect;
|
return effect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +24,12 @@ void
|
||||||
mixer_init(void)
|
mixer_init(void)
|
||||||
{
|
{
|
||||||
if (Mix_OpenAudio( 44100, MIX_DEFAULT_FORMAT, 2, 2048 ) == -1) {
|
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();
|
load_effects();
|
||||||
|
music = Mix_LoadMUS("assets/Sounds/Music/fantasy-forest-battle.ogg");
|
||||||
|
if (music == NULL)
|
||||||
|
fatal("Failed to load music: %s", Mix_GetError());
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -36,6 +39,23 @@ mixer_play_effect(Fx fx)
|
||||||
error("Unable to play sound: %u", (unsigned int) 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
|
void
|
||||||
mixer_close(void)
|
mixer_close(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,12 @@ mixer_init(void);
|
||||||
void
|
void
|
||||||
mixer_play_effect(Fx fx);
|
mixer_play_effect(Fx fx);
|
||||||
|
|
||||||
|
void
|
||||||
|
mixer_play_music(void);
|
||||||
|
|
||||||
|
void
|
||||||
|
mixer_stop_music(void);
|
||||||
|
|
||||||
void
|
void
|
||||||
mixer_close(void);
|
mixer_close(void);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue