Browse Source

Fix max level detection at draw time

DricomDragon 4 years ago
parent
commit
f92aad3315
1 changed files with 6 additions and 5 deletions
  1. 6 5
      main.cpp

+ 6 - 5
main.cpp

@@ -17,20 +17,21 @@ void putBloc(blocType bloc, float world[HEIGHT][WIDTH][BLOC_TOTAL], int y, int x
 
 void drawWorld(float world[HEIGHT][WIDTH][BLOC_TOTAL], SDL_Surface* tileSet[], SDL_Surface* out) {
 	SDL_Rect pos({0, 0, 0, 0});
-	SDL_Surface* select; // Current surface selected ! DO NOT FREE !
+	int indexOfMax;
 
 	for (int y(0); y < HEIGHT; y++)
 		for (int x(0); x < WIDTH; x++) {
-			select = tileSet[0];
+			indexOfMax = 0;
 			pos.x = x * BLOC_SIZE;
 			pos.y = y * BLOC_SIZE;
 
 			// Select the tile with highest level
 			for (int k(1); k < BLOC_TOTAL; k++)
-				if (world[y][x][k] > world[y][x][k - 1])
-					select = tileSet[k];
+				if (world[y][x][k] > world[y][x][indexOfMax]) {
+					indexOfMax = k;
+				}
 
-			SDL_BlitSurface(select, NULL, out, &pos);
+			SDL_BlitSurface(tileSet[indexOfMax], NULL, out, &pos);
 		}
 
 }