add variants and link executable to toplevel
[supertux.git] / src / tilemap.cpp
index a50bee3..818ba31 100644 (file)
@@ -84,8 +84,11 @@ TileMap::TileMap(LispReader& reader)
 }
 
 TileMap::TileMap(int layer_, bool solid_, size_t width_, size_t height_)
-  : solid(solid_), speed(1), width(width_), height(height_), layer(layer_), vertical_flip(false)
+  : solid(solid_), speed(1), width(0), height(0), layer(layer_), vertical_flip(false)
 {
+  tilemanager = TileManager::instance();
+  
+  resize(width_, height_);
 }
 
 TileMap::~TileMap()
@@ -155,6 +158,8 @@ TileMap::draw(DrawingContext& context)
       int tx, ty;
       for(pos.x = start_x, tx = tsx; pos.x < end_x; pos.x += 32, ++tx) {
         for(pos.y = start_y, ty = tsy; pos.y < end_y; pos.y += 32, ++ty) {
+          if(tx < 0 || tx > width || ty < 0 || ty > height)
+            continue;  // outside tilemap
           if (!tiles[ty*width + tx].hidden)
             tilemanager->draw_tile(context, tiles[ty*width + tx].id, pos, layer);
         }
@@ -186,6 +191,8 @@ TileMap::draw(DrawingContext& context)
       int tx, ty;
       for(pos.x = start_x, tx = tsx; pos.x < end_x; pos.x += 32, ++tx) {
         for(pos.y = start_y, ty = tsy; pos.y < end_y; pos.y += 32, ++ty) {
+          if(tx < 0 || tx > width || ty < 0 || ty > height)
+            continue;  // outside tilemap
           if (!tiles[ty*width + tx].hidden)
             tilemanager->draw_tile(context, tiles[ty*width + tx].id, pos, layer);
         }