Преглед на файлове

Repeat grass to cover all the map

DricomDragon преди 4 години
родител
ревизия
861f57d4fe
променени са 1 файла, в които са добавени 4 реда и са изтрити 1 реда
  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);