diff --git a/TODO.txt b/TODO.txt index ffdddd6..7fd83a1 100644 --- a/TODO.txt +++ b/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 ) diff --git a/assets/Sounds/Music/fantasy-forest-battle.ogg b/assets/Sounds/Music/fantasy-forest-battle.ogg new file mode 100644 index 0000000..c93729b Binary files /dev/null and b/assets/Sounds/Music/fantasy-forest-battle.ogg differ diff --git a/src/main.c b/src/main.c index d4611b5..758bd3f 100644 --- a/src/main.c +++ b/src/main.c @@ -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 diff --git a/src/mixer.c b/src/mixer.c index cf773d3..4529832 100644 --- a/src/mixer.c +++ b/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) { diff --git a/src/mixer.h b/src/mixer.h index 0b40e1f..da2139e 100644 --- a/src/mixer.h +++ b/src/mixer.h @@ -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);