Browse Source

Simplified code by removing margin

Florian DORMONT 10 years ago
parent
commit
157f76d735
1 changed files with 4 additions and 6 deletions
  1. 4 6
      src/Map.cpp

+ 4 - 6
src/Map.cpp

@@ -30,8 +30,6 @@ void MAP::render(WalrusRPG::Camera &camera, unsigned dt) const
 	UNUSED(dt);
 	// By Eiyeron : I assumed that the camera's position is the top left pixel.
 	// Margins moves the rendered map if we go outside of the bounds (specially on the left or on the top).
-	signed margin_x = 0, margin_y = 0;
-
 	signed offset_x = camera.get_x() % 24 * -1;
 	signed offset_y = camera.get_y() % 24 * -1;
 	signed start_x = camera.get_x() / 24;
@@ -41,12 +39,12 @@ void MAP::render(WalrusRPG::Camera &camera, unsigned dt) const
 
 	// Bound-checking code. To avoid reading outside of the map.
 	if(start_x < 0){
-		margin_x = -start_x*24;
+		offset_x -= start_x*24;
 		start_x = 0;
 		}
 
 	if(start_y < 0) {
-		margin_y = -start_y*24;
+		offset_y -= start_y*24;
 		start_y = 0;
 	}
 	if((unsigned)end_x > this->width) end_x = this->width;
@@ -68,13 +66,13 @@ void MAP::render(WalrusRPG::Camera &camera, unsigned dt) const
 		{
 			unsigned index = (start_x + i) + (start_y + j) * this->width;
 			sprite.x = this->layer0[index] * 24;
-			draw_sprite_sheet(tiles, margin_x + offset_x + i * 24, margin_y + offset_y + j * 24, &sprite);
+			draw_sprite_sheet(tiles, offset_x + i * 24, offset_y + j * 24, &sprite);
 
 			unsigned tile_over = this->layer1[index];
 			// layer1 : Over-layer
 			if(tile_over != 0) {
 				sprite.x = tile_over * 24;
-				draw_sprite_sheet(tiles, margin_x + offset_x + i * 24, margin_y + offset_y + j * 24, &sprite);
+				draw_sprite_sheet(tiles, offset_x + i * 24, offset_y + j * 24, &sprite);
 			}
 		}
 	}