Browse Source

Factorize mountain and water lines

Create common function putHorizonLine.
DricomDragon 4 years ago
parent
commit
cafd8c9cea
1 changed files with 10 additions and 9 deletions
  1. 10 9
      main.cpp

+ 10 - 9
main.cpp

@@ -38,25 +38,26 @@ void putSeed(Seed s, float world[HEIGHT][WIDTH][BLOC_TOTAL]) {
 		}
 }
 
+void putHorizonLine(int y, BlocType bloc, float world[HEIGHT][WIDTH][BLOC_TOTAL], float level = 1.0f) {
+	for (int j(0); j < HEIGHT; j++)
+		for (int i(0); i < WIDTH; i++)
+			world[j][i][(int) bloc] = level / (abs(y - j) + 1);
+}
+
 void clearWorld(float world[HEIGHT][WIDTH][BLOC_TOTAL]) {
 	// Erase everything
 	for (int j(0); j < HEIGHT; j++)
-		for (int i(0); i < WIDTH; i++) {
+		for (int i(0); i < WIDTH; i++)
 			for (int bloc(0); bloc < BLOC_TOTAL; bloc++)
 				world[j][i][bloc] = 0.0f;
-		}
 
 	// Bottom water line
 	const float waterLevel = 1.0f;
-	for (int j(0); j < HEIGHT; j++)
-		for (int i(0); i < WIDTH; i++)
-			world[j][i][WATER] = waterLevel / (HEIGHT - j);
+	putHorizonLine(HEIGHT - 1, WATER, world, waterLevel);
 
 	// Top mountain line
-	const float mountainLevel = 10.0f;
-	for (int j(0); j < HEIGHT; j++)
-		for (int i(0); i < WIDTH; i++)
-			world[j][i][MOUNTAIN] = mountainLevel / (1 + j) / (1 + j);
+	const float mountainLevel = 1.0f;
+	putHorizonLine(0, MOUNTAIN, world, mountainLevel);
 }
 
 void drawWorld(float world[HEIGHT][WIDTH][BLOC_TOTAL], SDL_Surface* tileSet[], SDL_Surface* out) {