Added support for gradients :)
[supertux.git] / src / level.cpp
index a33080f..1e8e644 100644 (file)
@@ -26,8 +26,6 @@
 
 using namespace std;
 
-texture_type img_bkgd, img_bkgd_tile[2][4], img_solid[4], img_brick[2];
-
 st_subset::st_subset()
 {
   levels = 0;
@@ -202,9 +200,13 @@ Level::init_defaults()
   width      = 21;
   time_left  = 100;
   gravity    = 10.;
-  bkgd_red   = 0;
-  bkgd_green = 0;
-  bkgd_blue  = 0;
+  bkgd_top_red   = 0;
+  bkgd_top_green = 0;
+  bkgd_top_blue  = 0;
+  bkgd_bottom_red   = 0;
+  bkgd_bottom_green = 0;
+  bkgd_bottom_blue  = 0;
+  endpos     = 0;
 
   for(int i = 0; i < 15; ++i)
     {
@@ -228,18 +230,15 @@ Level::init_defaults()
     }
 }
 
-/* Load data for this level: */
-/* Returns -1, if the loading of the level failed. */
 int
-Level::load(const  char *subset, int level)
+Level::load(const std::string& subset, int level)
 {
   char filename[1024];
 
-  /* Load data file: */
-
-  snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset, level);
+  // Load data file:
+  snprintf(filename, 1024, "%s/levels/%s/level%d.stl", st_dir, subset.c_str(), level);
   if(!faccessible(filename))
-    snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(), subset, level);
+    snprintf(filename, 1024, "%s/levels/%s/level%d.stl", datadir.c_str(), subset.c_str(), level);
 
   return load(filename);
 }
@@ -277,9 +276,12 @@ Level::load(const std::string& filename)
       reader.read_int("version",  &version);
       reader.read_int("width",  &width);
       reader.read_int("time",  &time_left);
-      reader.read_int("bkgd_red",  &bkgd_red);
-      reader.read_int("bkgd_green",  &bkgd_green);
-      reader.read_int("bkgd_blue",  &bkgd_blue);
+      reader.read_int("bkgd_top_red",  &bkgd_top_red);
+      reader.read_int("bkgd_top_green",  &bkgd_top_green);
+      reader.read_int("bkgd_top_blue",  &bkgd_top_blue);
+      reader.read_int("bkgd_bottom_red",  &bkgd_bottom_red);
+      reader.read_int("bkgd_bottom_green",  &bkgd_bottom_green);
+      reader.read_int("bkgd_bottom_blue",  &bkgd_bottom_blue);
       reader.read_float("gravity",  &gravity);
       reader.read_string("name",  &name);
       reader.read_string("theme",  &theme);
@@ -428,9 +430,6 @@ Level::load(const std::string& filename)
         }
     }
 
-  // FIXME: Set the global gravity to the latest loaded level's gravity
-  ::gravity = gravity;
-
   //  Mark the end position of this level!
   // FIXME: -10 is a rather random value, we still need some kind of
   // real levelend gola
@@ -474,9 +473,12 @@ Level::save(const  char * subset, int level)
   fprintf(fi,"  (music \"%s\")\n", song_title.c_str());
   fprintf(fi,"  (background \"%s\")\n", bkgd_image.c_str());
   fprintf(fi,"  (particle_system \"%s\")\n", particle_system.c_str());
-  fprintf(fi,"  (bkgd_red %d)\n", bkgd_red);
-  fprintf(fi,"  (bkgd_green %d)\n", bkgd_green);
-  fprintf(fi,"  (bkgd_blue %d)\n", bkgd_blue);
+  fprintf(fi,"  (bkgd_top_red %d)\n", bkgd_top_red);
+  fprintf(fi,"  (bkgd_top_green %d)\n", bkgd_top_green);
+  fprintf(fi,"  (bkgd_top_blue %d)\n", bkgd_top_blue);
+  fprintf(fi,"  (bkgd_bottom_red %d)\n", bkgd_bottom_red);
+  fprintf(fi,"  (bkgd_bottom_green %d)\n", bkgd_bottom_green);
+  fprintf(fi,"  (bkgd_bottom_blue %d)\n", bkgd_bottom_blue);
   fprintf(fi,"  (time %d)\n", time_left);
   fprintf(fi,"  (width %d)\n", width);
   fprintf(fi,"  (gravity %2.1f)\n", gravity);
@@ -542,29 +544,9 @@ Level::cleanup()
   badguy_data.clear();
 }
 
-/* Load graphics: */
-
 void 
 Level::load_gfx()
 {
-  level_load_image(&img_brick[0],theme,"brick0.png", IGNORE_ALPHA);
-  level_load_image(&img_brick[1],theme,"brick1.png", IGNORE_ALPHA);
-
-  level_load_image(&img_solid[0],theme,"solid0.png", USE_ALPHA);
-  level_load_image(&img_solid[1],theme,"solid1.png", USE_ALPHA);
-  level_load_image(&img_solid[2],theme,"solid2.png", USE_ALPHA);
-  level_load_image(&img_solid[3],theme,"solid3.png", USE_ALPHA);
-
-  level_load_image(&img_bkgd_tile[0][0],theme,"bkgd-00.png", USE_ALPHA);
-  level_load_image(&img_bkgd_tile[0][1],theme,"bkgd-01.png", USE_ALPHA);
-  level_load_image(&img_bkgd_tile[0][2],theme,"bkgd-02.png", USE_ALPHA);
-  level_load_image(&img_bkgd_tile[0][3],theme,"bkgd-03.png", USE_ALPHA);
-
-  level_load_image(&img_bkgd_tile[1][0],theme,"bkgd-10.png", USE_ALPHA);
-  level_load_image(&img_bkgd_tile[1][1],theme,"bkgd-11.png", USE_ALPHA);
-  level_load_image(&img_bkgd_tile[1][2],theme,"bkgd-12.png", USE_ALPHA);
-  level_load_image(&img_bkgd_tile[1][3],theme,"bkgd-13.png", USE_ALPHA);
-
   if(!bkgd_image.empty())
     {
       char fname[1024];
@@ -575,33 +557,20 @@ Level::load_gfx()
     }
   else
     {
-      /* Quick hack to make sure an image is loaded, when we are freeing it afterwards. */#
-      level_load_image(&img_bkgd, theme,"solid0.png", IGNORE_ALPHA);
+      /* Quick hack to make sure an image is loaded, when we are freeing it afterwards. */
+      load_image(&img_bkgd, theme,"solid0.png", IGNORE_ALPHA);
     }
 }
 
-/* Free graphics data for this level: */
-void level_free_gfx(void)
+void
+Level::free_gfx()
 {
-  int i;
-
-  for (i = 0; i < 2; i++)
-    {
-      texture_free(&img_brick[i]);
-    }
-  for (i = 0; i < 4; i++)
-    {
-      texture_free(&img_solid[i]);
-      texture_free(&img_bkgd_tile[0][i]);
-      texture_free(&img_bkgd_tile[1][i]);
-    }
-
   texture_free(&img_bkgd);
 }
 
 /* Load a level-specific graphic... */
-
-void level_load_image(texture_type* ptexture, string theme,const  char * file, int use_alpha)
+void
+Level::load_image(texture_type* ptexture, string theme,const  char * file, int use_alpha)
 {
   char fname[1024];
 
@@ -662,16 +631,13 @@ Level::change(float x, float y, int tm, unsigned int c)
     }
 }
 
-/* Free music data for this level: */
-
-void level_free_song(void)
+void 
+Level::free_song(void)
 {
   free_music(level_song);
   free_music(level_song_fast);
 }
 
-/* Load music: */
-
 void
 Level::load_song()
 {
@@ -684,7 +650,8 @@ Level::load_song()
                               strlen(song_title.c_str()) + 8 + 5);
   song_subtitle = strdup(song_title.c_str());
   strcpy(strstr(song_subtitle, "."), "\0");
-  sprintf(song_path, "%s/music/%s-fast%s", datadir.c_str(), song_subtitle, strstr(song_title.c_str(), "."));
+  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);
   free(song_subtitle);
   free(song_path);
@@ -708,39 +675,4 @@ Level::gettileid(float x, float y)
   return c;
 }
 
-Tile* gettile(float x, float y)
-{
-  return TileManager::instance()->get(GameSession::current()->get_level()->gettileid(x, y));
-}
-
-bool issolid(float x, float y)
-{
-  Tile* tile = gettile(x,y);
-  return tile && tile->solid;
-}
-
-bool isbrick(float x, float y)
-{
-  Tile* tile = gettile(x,y);
-  return tile && tile->brick;
-}
-
-bool isice(float x, float y)
-{
-  Tile* tile = gettile(x,y);
-  return tile && tile->ice;
-}
-
-bool isfullbox(float x, float y)
-{
-  Tile* tile = gettile(x,y);
-  return tile && tile->fullbox;
-}
-
-bool isdistro(float x, float y)
-{
-  Tile* tile = gettile(x,y);
-  return tile && tile->distro;
-}
-
 /* EOF */