Parcourir la source

Repeat grass to cover all the map

DricomDragon il y a 4 ans
Parent
commit
861f57d4fe
1 fichiers modifiés avec 4 ajouts et 1 suppressions
  1. 4 1
      main.cpp

+ 4 - 1
main.cpp

@@ -30,6 +30,7 @@ int main()
 
 	// [2.2] Other components
 	SDL_Surface* grass = SDL_LoadBMP("textures/grass.bmp");
+	SDL_Rect pos({0, 0, 0, 0});
 
 	/// [3] Main loop
 	bool done(false);
@@ -57,7 +58,9 @@ int main()
 		// [3.3] Draw phase
 		SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 255, 255));
 
-		SDL_BlitSurface(grass, NULL, screen, NULL);
+		for (pos.y = 0; pos.y < height; pos.y += grass->h)
+			for (pos.x = 0; pos.x < width; pos.x += grass->w)
+				SDL_BlitSurface(grass, NULL, screen, &pos);
 
 		SDL_Flip(screen);