GameSession::run()
{
Menu::set_current(0);
- Player* tux = world->get_tux();
current_ = this;
int fps_cnt = 0;
}
/* Handle events: */
- tux->input.old_fire = tux->input.fire;
+ world->get_tux()->input.old_fire = world->get_tux()->input.fire;
process_events();
process_menu();
}
/* Handle time: */
- if (!time_left.check() && tux->dying == DYING_NOT)
- tux->kill(KILL);
+ if (!time_left.check() && world->get_tux()->dying == DYING_NOT)
+ world->get_tux()->kill(KILL);
/* Handle music: */
- if(tux->invincible_timer.check())
+ if(world->get_tux()->invincible_timer.check())
{
if(world->get_music_type() != HERRING_MUSIC)
world->play_music(HERRING_MUSIC);
}
Level::Level()
- : level_song(0), level_song_fast(0)
+ : img_bkgd(0), level_song(0), level_song_fast(0)
{
}
Level::Level(const std::string& subset, int level)
- : level_song(0), level_song_fast(0)
+ : img_bkgd(0), level_song(0), level_song_fast(0)
{
load(subset, level);
}
Level::Level(const std::string& filename)
- : level_song(0), level_song_fast(0)
+ : img_bkgd(0), level_song(0), level_song_fast(0)
{
load(filename);
}
void
Level::free_song(void)
{
+ if(level_song_fast != level_song) {
+ free_music(level_song_fast);
+ level_song_fast = 0;
+ }
+
free_music(level_song);
level_song = 0;
- free_music(level_song_fast);
- level_song_fast = 0;
}
void
char* song_subtitle;
level_song = ::load_song(datadir + "/music/" + song_title);
+ if(!level_song)
+ st_abort("Couldn't load song: " , song_title.c_str());
song_path = (char *) malloc(sizeof(char) * datadir.length() +
strlen(song_title.c_str()) + 8 + 5);
sprintf(song_path, "%s/music/%s-fast%s", datadir.c_str(),
song_subtitle, strstr(song_title.c_str(), "."));
level_song_fast = ::load_song(song_path);
+ if(!level_song_fast) {
+ level_song_fast = level_song;
+ }
free(song_subtitle);
free(song_path);
}
#include "special.h"
#include "resources.h"
#include "sprite_manager.h"
+#include "setup.h"
Surface* img_waves[3];
Surface* img_water;
/* Herring song */
herring_song = load_song(datadir + "/music/SALCON.MOD");
+ if(!herring_song)
+ st_abort("Couldn't load song ", "/music/SALCON.MOD");
}
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)
{
if(!audio_device)
- return 0;
+ return (Mix_Music*) ~0;
- Mix_Music * sng;
-
- sng = Mix_LoadMUS(file.c_str());
-
- /* printf message and abort if there is an initialized audio device */
- if (sng == NULL)
- st_abort("Can't load", file);
-
- return (sng);
+ Mix_Music* song = Mix_LoadMUS(file.c_str());
+ return song;
}
{
if (chunk != NULL)
{
- DEBUG_MSG( __PRETTY_FUNCTION__ );
Mix_FreeChunk( chunk );
chunk = NULL;
}
{
if (!audio_device)
return;
+ if(music == current_song)
+ return;
if (use_music && Mix_PlayMusic(music, -1) < 0)
st_abort("Couldn't play music: ", Mix_GetError());
void free_music(Mix_Music *music)
{
+ if(!audio_device)
+ return;
+
Mix_FreeMusic( music );
}
{
index -= 1; // FIXME: Hack
std::cout << "Sarting level: " << index << std::endl;
+ halt_music();
GameSession session(current_contrib_subset, index, ST_GL_PLAY);
session.run();
Menu::set_current(main_menu);
//World* world = session->get_world();
Level* plevel = session->get_level();
Player* tux = session->get_world()->get_tux();
+
+ session->get_world()->play_music(LEVEL_MUSIC);
/* FIXME:
// update particle systems
update_time = st_get_ticks();
random_timer.start(rand() % 2000 + 2000);
- Mix_Music* music = load_song(datadir + "/music/theme.mod");
- play_music(music);
-
Menu::set_current(main_menu);
while (Menu::current())
{
/* Pause: */
frame++;
SDL_Delay(25);
-
- play_music(music);
}
/* Free surfaces: */
delete bkg_title;
delete logo;
- free_music(music);
}
#define MAX_VEL 10
activate_bad_guys();
activate_particle_systems();
get_level()->load_song();
-
- play_music(LEVEL_MUSIC);
}
World::~World()
quit = false;
song = load_song(datadir + "/music/" + music);
+ if(!song)
+ st_abort("Couldn't load song ", music.c_str());
+
play_music(song);
while(!quit) {