|
@@ -18,6 +18,27 @@ void putBloc(blocType bloc, float world[HEIGHT][WIDTH][BLOC_TOTAL], int y, int x
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+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 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);
|
|
|
+
|
|
|
+ // 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);
|
|
|
+}
|
|
|
+
|
|
|
void drawWorld(float world[HEIGHT][WIDTH][BLOC_TOTAL], SDL_Surface* tileSet[], SDL_Surface* out) {
|
|
|
SDL_Rect pos({0, 0, 0, 0});
|
|
|
int indexOfMax;
|
|
@@ -76,24 +97,7 @@ int main()
|
|
|
|
|
|
// [2.4] Create world
|
|
|
float world[HEIGHT][WIDTH][BLOC_TOTAL];
|
|
|
-
|
|
|
- // Clear world
|
|
|
- for (int j(0); j < HEIGHT; j++)
|
|
|
- for (int i(0); i < WIDTH; i++)
|
|
|
- for (int t(0); t < BLOC_TOTAL; t++)
|
|
|
- world[j][i][t] = 0.0f;
|
|
|
-
|
|
|
- // Basic water
|
|
|
- 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);
|
|
|
-
|
|
|
- // 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);
|
|
|
+ clearWorld(world);
|
|
|
|
|
|
// [2.5] Surface containers
|
|
|
SDL_Surface* tileSet[BLOC_TOTAL] = {water, mountain, grass, desert};
|
|
@@ -117,9 +121,16 @@ int main()
|
|
|
done = true;
|
|
|
break;
|
|
|
case SDL_KEYDOWN:
|
|
|
- if (event.key.keysym.sym == SDLK_ESCAPE)
|
|
|
- done = true;
|
|
|
- break;
|
|
|
+ switch(event.key.keysym.sym)
|
|
|
+ {
|
|
|
+ case SDLK_ESCAPE:
|
|
|
+ done = true;
|
|
|
+ break;
|
|
|
+ case SDLK_BACKSPACE:
|
|
|
+ clearWorld(world);
|
|
|
+ drawWorld(world, tileSet, map);
|
|
|
+ break;
|
|
|
+ }
|
|
|
case SDL_MOUSEMOTION:
|
|
|
cursorPos.x = event.motion.x / BLOC_SIZE;
|
|
|
cursorPos.y = event.motion.y / BLOC_SIZE;
|