}
Level::Level()
+ : img_bkgd(0), level_song(0), level_song_fast(0)
{
}
Level::Level(const std::string& subset, int level)
+ : img_bkgd(0), level_song(0), level_song_fast(0)
{
load(subset, level);
}
Level::Level(const std::string& filename)
+ : img_bkgd(0), level_song(0), level_song_fast(0)
{
load(filename);
}
+Level::~Level()
+{
+ free_gfx();
+ free_song();
+}
+
void
Level::init_defaults()
{
LispReader reader(lisp_cdr(data));
reader.read_int("x", &bg_data.x);
reader.read_int("y", &bg_data.y);
+ reader.read_bool("stay-on-platform", &bg_data.stay_on_platform);
badguy_data.push_back(bg_data);
// Mark the end position of this level!
// FIXME: -10 is a rather random value, we still need some kind of
// real levelend gola
- endpos = 32*(width-10);
+ endpos = 32*(width-20);
fclose(fi);
return 0;
for(std::vector<BadGuyData>::iterator it = badguy_data.begin();
it != badguy_data.end();
++it)
- fprintf( fi,"(%s (x %d) (y %d))\n",badguykind_to_string((*it).kind).c_str(),(*it).x,(*it).y);
+ fprintf( fi,"(%s (x %d) (y %d) (stay-on-platform %s))\n",
+ badguykind_to_string((*it).kind).c_str(),(*it).x,(*it).y,
+ it->stay_on_platform ? "#t" : "#f");
fprintf( fi,")\n");
void
Level::free_song(void)
{
+ if(level_song_fast != level_song) {
+ free_music(level_song_fast);
+ level_song_fast = 0;
+ }
+
free_music(level_song);
- free_music(level_song_fast);
+ level_song = 0;
}
void
Level::load_song()
{
+ free_song();
+
char* song_path;
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);
}
+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)
{