Fixed the back_scrolling flag as suggested by Michael George over the mailing list.
[supertux.git] / src / level.cpp
index d5e3e72..ff80737 100644 (file)
@@ -43,7 +43,7 @@ LevelSubset::LevelSubset()
 
 LevelSubset::~LevelSubset()
 {
-    delete image;
+  delete image;
 }
 
 void LevelSubset::create(const std::string& subset_name)
@@ -221,7 +221,7 @@ Level::Level(const std::string& filename)
 
 Level::~Level()
 {
-  free_gfx();
+  delete img_bkgd;
 }
 
 void
@@ -237,6 +237,7 @@ Level::init_defaults()
   start_pos_y = 170;
   time_left  = 100;
   gravity    = 10.;
+  back_scrolling = false;
   bkgd_top.red   = 0;
   bkgd_top.green = 0;
   bkgd_top.blue  = 0;
@@ -311,6 +312,9 @@ Level::load(const std::string& filename)
       if(!reader.read_int("time",  &time_left)) {
         printf("Warning no time specified for level.\n");
       }
+      
+      back_scrolling = false;
+      reader.read_bool("back_scrolling",  &back_scrolling);
 
       bkgd_top.red = bkgd_top.green = bkgd_top.blue = 0;
       reader.read_int("bkgd_red_top",  &bkgd_top.red);
@@ -551,6 +555,10 @@ Level::save(const std::string& subset, int level)
   fprintf(fi,"  (bkgd_blue_bottom %d)\n", bkgd_bottom.blue);
   fprintf(fi,"  (time %d)\n", time_left);
   fprintf(fi,"  (width %d)\n", width);
+  if(back_scrolling)
+    fprintf(fi,"  (back_scrolling #t)\n"); 
+  else
+    fprintf(fi,"  (back_scrolling #f)\n");
   fprintf(fi,"  (gravity %2.1f)\n", gravity);
   fprintf(fi,"  (background-tm ");
 
@@ -634,20 +642,16 @@ Level::load_gfx()
       snprintf(fname, 1024, "%s/background/%s", st_dir, bkgd_image.c_str());
       if(!faccessible(fname))
         snprintf(fname, 1024, "%s/images/background/%s", datadir.c_str(), bkgd_image.c_str());
+      delete img_bkgd;
       img_bkgd = new Surface(fname, IGNORE_ALPHA);
     }
   else
     {
+      delete img_bkgd;
       img_bkgd = 0;
     }
 }
 
-void
-Level::free_gfx()
-{
-  delete img_bkgd;
-}
-
 /* Load a level-specific graphic... */
 void
 Level::load_image(Surface** ptexture, string theme,const  char * file, int use_alpha)