}
time_left.init(true);
- start_timers();
+ start_timers();
+ world->play_music(LEVEL_MUSIC);
}
GameSession::~GameSession()
clearscreen(0, 0, 0);
updatescreen();
- /* Play music: */
- play_current_music();
-
// Eat unneeded events
SDL_Event event;
while (SDL_PollEvent(&event)) {}
}
/* Handle time: */
- if (time_left.check())
+ if (!time_left.check() && tux->dying == DYING_NOT)
+ tux->kill(KILL);
+
+ /* Handle music: */
+ if(tux->invincible_timer.check())
{
- /* are we low on time ? */
- if (time_left.get_left() < TIME_WARNING
- && (get_current_music() != HURRYUP_MUSIC)) /* play the fast music */
- {
- set_current_music(HURRYUP_MUSIC);
- play_current_music();
- }
+ if(world->get_music_type() != HERRING_MUSIC)
+ world->play_music(HERRING_MUSIC);
}
- else if(tux->dying == DYING_NOT)
+ /* are we low on time ? */
+ else if (time_left.get_left() < TIME_WARNING
+ && (world->get_music_type() == LEVEL_MUSIC))
{
- tux->kill(KILL);
+ world->play_music(HURRYUP_MUSIC);
+ }
+ /* or just normal music? */
+ else if(world->get_music_type() != LEVEL_MUSIC)
+ {
+ world->play_music(LEVEL_MUSIC);
}
/* Calculate frames per second */
}
}
- halt_music();
-
- world->get_level()->free_gfx();
- world->get_level()->cleanup();
- world->get_level()->free_song();
+ delete world;
+ world = 0;
return exit_status;
}
}
Level::Level()
+ : level_song(0), level_song_fast(0)
{
}
Level::Level(const std::string& subset, int level)
+ : level_song(0), level_song_fast(0)
{
load(subset, level);
}
Level::Level(const std::string& filename)
+ : level_song(0), level_song_fast(0)
{
load(filename);
}
+Level::~Level()
+{
+ free_gfx();
+ free_song();
+}
+
void
Level::init_defaults()
{
Level::free_song(void)
{
free_music(level_song);
+ level_song = 0;
free_music(level_song_fast);
+ level_song_fast = 0;
}
void
Level::load_song()
{
+ free_song();
+
char* song_path;
char* song_subtitle;
free(song_path);
}
+Mix_Music*
+Level::get_level_music()
+{
+ return level_song;
+}
+
+Mix_Music*
+Level::get_level_music_fast()
+{
+ return level_song_fast;
+}
+
unsigned int
Level::gettileid(float x, float y)
{
{
public:
Surface* img_bkgd;
+ Mix_Music* level_song;
+ Mix_Music* level_song_fast;
std::string name;
std::string author;
Level();
Level(const std::string& subset, int level);
Level(const std::string& filename);
+ ~Level();
/** Will the Level structure with default values */
void init_defaults();
void load_song();
void free_song();
+ Mix_Music* get_level_music();
+ Mix_Music* get_level_music_fast();
void save(const char* subset, int level);
}
}
-
/* ---- DONE HANDLING TUX! --- */
- /* Handle invincibility timer: */
- if (get_current_music() == HERRING_MUSIC && !invincible_timer.check())
- {
- /*
- no, we are no more invincible
- or we were not in invincible mode
- but are we in hurry ?
- */
-
- // FIXME: Move this to gamesession
- if (GameSession::current()->time_left.get_left() < TIME_WARNING)
- {
- /* yes, we are in hurry
- stop the herring_song, prepare to play the correct
- fast level_song !
- */
- set_current_music(HURRYUP_MUSIC);
- }
- else
- {
- set_current_music(LEVEL_MUSIC);
- }
-
- /* start playing it */
- play_current_music();
- }
-
// check some timers
skidding_timer.check();
invincible_timer.check();
PlayerStatus::PlayerStatus()
: score(0),
distros(0),
- lives(3)
+ lives(3),
+ score_multiplier(1)
{
}
case 5:
if(use_music != options_menu->item[5].toggled)
{
- if(use_music)
- {
- if(playing_music())
- {
- halt_music();
- }
- use_music = false;
- }
- else
- {
- use_music = true;
- if (!playing_music())
- {
- play_current_music();
- }
- }
+ enable_music(options_menu->item[5].toggled);
}
break;
case 6:
/* Disable the compiled in sound feature */
printf("Sounds disabled \n");
use_sound = false;
+ audio_device = false;
}
else if (strcmp(argv[i], "--disable-music") == 0)
{
#include <SDL_mixer.h>
Mix_Chunk * sounds[NUM_SOUNDS];
-Mix_Music * level_song, * level_song_fast, * herring_song;
+Mix_Music * herring_song = 0;
+Mix_Music * current_song = 0;
/* --- OPEN THE AUDIO DEVICE --- */
Mix_Music * load_song(const std::string& file)
{
+ if(!audio_device)
+ return 0;
+
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)
+ if (sng == NULL)
st_abort("Can't load", file);
+
return (sng);
}
}
}
-
-int playing_music(void)
+void halt_music(void)
{
- if (use_music)
- {
- return Mix_PlayingMusic();
- }
- else
- {
- /* we are in --disable-music we can't be playing music */
- return 0;
- }
+ if (!use_music || !audio_device)
+ return;
+
+ Mix_HaltMusic();
+ current_song = 0;
}
-int halt_music(void)
+void play_music(Mix_Music *music)
{
- if (use_music && audio_device)
- {
- return Mix_HaltMusic();
- }
- else
- {
- return 0;
- }
-}
+ if (!audio_device)
+ return;
+ if (use_music && Mix_PlayMusic(music, -1) < 0)
+ st_abort("Couldn't play music: ", Mix_GetError());
-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;
- }
+ current_song = music;
}
void free_music(Mix_Music *music)
{
- if ( music != NULL )
- {
- DEBUG_MSG(__PRETTY_FUNCTION__);
- Mix_FreeMusic( music );
- music = NULL;
- }
+ Mix_FreeMusic( music );
}
- 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 */
+
+void enable_music(bool enable)
+{
+ if(!audio_device)
+ return;
+
+ use_music = enable;
+ if(!use_music)
+ Mix_HaltMusic();
+ else
+ Mix_PlayMusic(current_song, -1);
}
/* variables for stocking the sound and music */
extern Mix_Chunk* sounds[NUM_SOUNDS];
-extern Mix_Music* level_song;
-extern Mix_Music* level_song_fast;
extern Mix_Music* herring_song;
/* functions handling the sound and music */
void close_audio( void );
Mix_Chunk * load_sound(const std::string& file);
-void play_sound(Mix_Chunk * snd, enum Sound_Speaker whichSpeaker);
-Mix_Music * load_song(const std::string& file);
-
-int playing_music(void);
-int halt_music(void);
-int play_music(Mix_Music*music, int loops);
-void free_music(Mix_Music*music);
void free_chunk(Mix_Chunk*chunk);
+void play_sound(Mix_Chunk * snd, enum Sound_Speaker whichSpeaker);
-int get_current_music();
-void set_current_music(int music);
-void play_current_music();
+Mix_Music* load_song(const std::string& file);
+void free_music(Mix_Music* music);
+void halt_music(void);
+void enable_music(bool enable);
+void play_music(Mix_Music* music);
#endif /*SUPERTUX_SOUND_H*/
{
play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER);
pplayer->invincible_timer.start(TUX_INVINCIBLE_TIME);
- /* play the herring song ^^ */
- if (get_current_music() != HURRYUP_MUSIC)
- {
- set_current_music(HERRING_MUSIC);
- play_current_music();
- }
+ World::current()->play_music(HERRING_MUSIC);
}
else if (kind == UPGRADE_1UP)
{
activate_bad_guys();
activate_particle_systems();
get_level()->load_song();
+
+ play_music(LEVEL_MUSIC);
}
World::~World()
{
+ halt_music(); // just to be sure (because levelmusic is freed now)
delete level;
}
distro_counter = 0;
/* set current song/music */
- set_current_music(LEVEL_MUSIC);
+ currentmusic = LEVEL_MUSIC;
}
void
play_sound(sounds[SND_SHOOT], SOUND_CENTER_SPEAKER);
}
+void
+World::play_music(int musictype)
+{
+ currentmusic = musictype;
+ switch(currentmusic) {
+ case HURRYUP_MUSIC:
+ ::play_music(get_level()->get_level_music_fast());
+ break;
+ case LEVEL_MUSIC:
+ ::play_music(get_level()->get_level_music());
+ break;
+ case HERRING_MUSIC:
+ ::play_music(herring_song);
+ break;
+ default:
+ ::halt_music();
+ break;
+ }
+}
+
+int
+World::get_music_type()
+{
+ return currentmusic;
+}
+
/* Break a brick: */
void
World::trybreakbrick(float x, float y, bool small)
int distro_counter;
bool counting_distros;
+ int currentmusic;
+
static World* current_;
public:
static World* current() { return current_; }
void draw();
void action(double frame_ratio);
+ void play_music(int musictype);
+ int get_music_type();
+
+
/** Checks for all possible collisions. And calls the
collision_handlers, which the collision_objects provide for this
case (or not). */
break;
}
- play_music(song, 1);
+ play_music(song);
Menu::set_current(0);
if (!savegame_file.empty())
savegame(savegame_file);
quit = false;
song = load_song(datadir + "/music/" + music);
- play_music(song, 1);
+ play_music(song);
while(!quit) {
Point tux_pos = tux->get_pos();