Two leveleditor related bug fixes:
[supertux.git] / src / tilemap.cpp
index 2165178..2bf445d 100644 (file)
 #include <cmath>
 
 #include "tilemap.h"
-#include "screen/drawing_context.h"
+#include "video/drawing_context.h"
 #include "level.h"
 #include "tile.h"
 #include "tile_manager.h"
-#include "globals.h"
-#include "lispreader.h"
-#include "lispwriter.h"
+#include "app/globals.h"
+#include "utils/lispreader.h"
+#include "utils/lispwriter.h"
 
 TileMap::TileMap()
   : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES), vertical_flip(false)
@@ -155,6 +155,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 +188,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);
         }
@@ -263,9 +267,9 @@ Tile*
 TileMap::get_tile(int x, int y) const
 {
   if(x < 0 || x >= width || y < 0 || y >= height)
-    return &tilemanager->get(0);
+    return tilemanager->get(0);
 
-  return &tilemanager->get(tiles[y*width + x].id);
+  return tilemanager->get(tiles[y*width + x].id);
 }
 
 Tile*