#include "setup.h"
/*global variable*/
-bool use_sound; /* handle sound on/off menu and command-line option */
-bool use_music; /* handle music on/off menu and command-line option */
-bool audio_device; /* != 0: available and initialized */
-int current_music;
+bool use_sound = true; /* handle sound on/off menu and command-line option */
+bool use_music = true; /* handle music on/off menu and command-line option */
+bool audio_device = true; /* != 0: available and initialized */
char * soundfilenames[NUM_SOUNDS] = {
"/sounds/jump.wav",
"/sounds/shoot.wav",
"/sounds/lifeup.wav",
"/sounds/stomp.wav",
- "/sounds/kick.wav"
+ "/sounds/kick.wav",
+ "/sounds/explode.wav"
};
#include <SDL_mixer.h>
Mix_Chunk * sounds[NUM_SOUNDS];
-Mix_Music * level_song, * level_song_fast, * herring_song;
/* --- OPEN THE AUDIO DEVICE --- */
snd = Mix_LoadWAV(file.c_str());
- /* printf message and abort if there is an initialized audio device */
if ((snd == NULL) && audio_device)
st_abort("Can't load", file);
Mix_Music * load_song(const std::string& file)
{
- Mix_Music * sng;
-
- sng = Mix_LoadMUS(file.c_str());
-
- /* printf message and abort if there is an initialized audio device */
- if ((sng == NULL) && audio_device)
- st_abort("Can't load", file);
- return (sng);
+ if(!audio_device)
+ return (Mix_Music*) ~0;
+
+ Mix_Music* song = Mix_LoadMUS(file.c_str());
+ return song;
}
{
if (chunk != NULL)
{
- DEBUG_MSG( __PRETTY_FUNCTION__ );
Mix_FreeChunk( chunk );
chunk = NULL;
}
}
-
-int playing_music(void)
-{
- if (use_music)
- {
- return Mix_PlayingMusic();
- }
- else
- {
- /* we are in --disable-music we can't be playing music */
- return 0;
- }
-}
-
-
-int halt_music(void)
-{
- if (use_music && audio_device)
- {
- return Mix_HaltMusic();
- }
- else
- {
- return 0;
- }
-}
-
-
-int play_music(Mix_Music *music, int loops)
-{
- if (use_music && audio_device)
- {
- DEBUG_MSG(__PRETTY_FUNCTION__);
- return Mix_PlayMusic(music, loops);
- }
- else
- {
- /* return error since you're trying to play music in --disable-sound mode */
- return -1;
- }
-}
-
-
-void free_music(Mix_Music *music)
-{
- if ( music != NULL )
- {
- DEBUG_MSG(__PRETTY_FUNCTION__);
- Mix_FreeMusic( music );
- music = NULL;
- }
-}
- int get_current_music()
- {
- return current_music;
- }
-
- void set_current_music(int music)
- {
- current_music = music;
- }
-
- void play_current_music()
- {
- if(playing_music())
- halt_music();
-
- switch(current_music)
- {
- case LEVEL_MUSIC:
- play_music(level_song, -1); // -1 to play forever
- break;
- case HERRING_MUSIC:
- play_music(herring_song, -1);
- break;
- case HURRYUP_MUSIC:
- play_music(level_song_fast, -1);
- break;
- case NO_MUSIC: // keep the compiler happy for the moment :-)
- {}
- /*default:*/
- }
- /* use halt_music whenever you want to stop it */
-}
-