Browse Source

Split the world in blocs

DricomDragon 4 years ago
parent
commit
804e3896cc
1 changed files with 8 additions and 4 deletions
  1. 8 4
      main.cpp

+ 8 - 4
main.cpp

@@ -20,8 +20,9 @@ int main()
 
 	/// [2] Create components
 	// [2.1] Create window
-	const int width(640), height(480);
-	SDL_Surface* screen = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
+	const int blocSize(16);
+	const int width(100), height(50);
+	SDL_Surface* screen = SDL_SetVideoMode(width * blocSize, height * blocSize, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
 	if ( !screen )
 	{
 		std::cout << "Unable to set " << width << "x" << height << " video: " << SDL_GetError() << std::endl;
@@ -67,9 +68,12 @@ int main()
 		// [3.3] Draw phase
 		SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 255, 255));
 
-		for (pos.y = 0; pos.y < height; pos.y += water->h)
-			for (pos.x = 0; pos.x < width; pos.x += water->w)
+		for (int y(0); y < height; y++)
+			for (int x(0); x < width; x++) {
+				pos.x = x * blocSize;
+				pos.y = y * blocSize;
 				SDL_BlitSurface(water, NULL, screen, &pos);
+			}
 
 		SDL_BlitSurface(pawn, NULL, screen, &pawnPos);