Just removed spaces from key and joystick setup entries... What were does doing there...
[supertux.git] / src / level.cpp
index 7e6e182..bbd0915 100644 (file)
@@ -199,19 +199,28 @@ void st_subset::free()
 }
 
 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()
 {
@@ -358,6 +367,7 @@ Level::load(const std::string& filename)
                 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);
 
@@ -483,7 +493,7 @@ Level::load(const std::string& filename)
   //  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;
@@ -572,7 +582,9 @@ Level::save(const  char * subset, int level)
   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");
 
@@ -684,17 +696,26 @@ Level::change(float x, float y, int tm, unsigned int c)
 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);
@@ -703,10 +724,25 @@ Level::load_song()
   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)
 {