-renamed ViewPort to Camera
[supertux.git] / src / level.cpp
index 4bdf885..3a55398 100644 (file)
@@ -220,7 +220,7 @@ Level::init_defaults()
   name       = "UnNamed";
   author     = "UnNamed";
   song_title = "Mortimers_chipdisko.mod";
-  bkgd_image = "arctis.png";
+  bkgd_image = "arctis.jpg";
   width      = 0;
   height     = 0;
   start_pos_x = 100;
@@ -498,6 +498,7 @@ Level::save(const std::string& subset, int level, World* world)
     writer.start_list("point");
     writer.write_int("x", i->x);
     writer.write_int("y", i->y);
+    writer.end_list("point");
   }
   writer.end_list("reset-points");
 
@@ -566,27 +567,39 @@ void Level::load_image(Surface** ptexture, string theme,const  char * file, int
 void 
 Level::resize(int new_width, int new_height)
 {
-  // first: resize height
-  ia_tiles.resize(new_height * width, 0);
-  bg_tiles.resize(new_height * width, 0);
-  fg_tiles.resize(new_height * width, 0);
-  height = new_height;
+  if(new_width < width) {
+    // remap tiles for new width
+    for(int y = 0; y < height && y < new_height; ++y) {
+      for(int x = 0; x < new_width; ++x) {
+        ia_tiles[y * new_width + x] = ia_tiles[y * width + x];
+        bg_tiles[y * new_width + x] = bg_tiles[y * width + x];
+        fg_tiles[y * new_width + x] = fg_tiles[y * width + x];
+      }
+    }
+  }
 
-  // remap horizontal tiles for new width
-  int np = 0;
-  for(int y = 0; y < height; ++y) {
-    for(int x = 0; x < new_width && x < width; ++x) {
-      ia_tiles[np] = ia_tiles[y * width + x];
-      bg_tiles[np] = bg_tiles[y * width + x];
-      fg_tiles[np] = fg_tiles[y * width + x];
-      np++;
+  ia_tiles.resize(new_width * new_height);
+  bg_tiles.resize(new_width * new_height);
+  fg_tiles.resize(new_width * new_height); 
+
+  if(new_width > width) {
+    // remap tiles
+    for(int y = std::min(height, new_height)-1; y >= 0; --y) {
+      for(int x = new_width-1; x >= 0; --x) {
+        if(x >= width) {
+          ia_tiles[y * new_width + x] = 0;
+          bg_tiles[y * new_width + x] = 0;
+          fg_tiles[y * new_width + x] = 0;
+        } else {
+          ia_tiles[y * new_width + x] = ia_tiles[y * width + x];
+          bg_tiles[y * new_width + x] = bg_tiles[y * width + x];
+          fg_tiles[y * new_width + x] = fg_tiles[y * width + x];
+        }
+      }
     }
   }
 
-  ia_tiles.resize(new_height * new_width);
-  bg_tiles.resize(new_height * new_width);
-  fg_tiles.resize(new_height * new_width); 
-  
+  height = new_height;
   width = new_width;
 }
 
@@ -613,25 +626,6 @@ Level::change(float x, float y, int tm, unsigned int c)
     }
 }
 
-void Level::draw_bg()
-{
-  if(img_bkgd)
-    {
-    // Tile background horizontally
-    int sx = (int)((float)scroll_x * ((float)bkgd_speed/100.0f)) % img_bkgd->w;
-    int sy = (int)((float)scroll_y * ((float)bkgd_speed/100.0f)) % img_bkgd->h;
-    for (int x = 0; (x-1)*img_bkgd->w <= screen->w; x++)
-      for (int y = 0; (y-1)*img_bkgd->h <= screen->h; y++)
-        img_bkgd->draw_part(x == 0 ? sx : 0, y == 0 ? sy : 0,
-                   x == 0 ? 0 : (img_bkgd->w * x) - sx, y == 0 ? 0 : (img_bkgd->h * y) - sy,
-                   x == 0 ? img_bkgd->w - sx : img_bkgd->w, y == 0 ? img_bkgd->h - sy : img_bkgd->h);
-    }
-  else
-    {
-    drawgradient(bkgd_top, bkgd_bottom);
-    }
-}
-
 void
 Level::load_song()
 {