|
@@ -68,11 +68,11 @@ int main()
|
|
|
SDL_Surface* water = SDL_LoadBMP("textures/water.bmp");
|
|
|
SDL_Surface* desert = SDL_LoadBMP("textures/desert.bmp");
|
|
|
SDL_Surface* mountain = SDL_LoadBMP("textures/mountain.bmp");
|
|
|
- SDL_Surface* pawn = SDL_LoadBMP("textures/pawn.bmp");
|
|
|
|
|
|
// [2.3] Create variables
|
|
|
SDL_Rect pawnPos({0, 0, 0, 0});
|
|
|
SDL_Rect cursorPos({0, 0, 0, 0}); // Bloc coordinates
|
|
|
+ int indexCurrent(0);
|
|
|
|
|
|
// [2.4] Create world
|
|
|
float world[HEIGHT][WIDTH][BLOC_TOTAL];
|
|
@@ -98,6 +98,7 @@ int main()
|
|
|
// [2.5] Surface containers
|
|
|
SDL_Surface* tileSet[BLOC_TOTAL] = {water, mountain, grass, desert};
|
|
|
SDL_Surface* map = SDL_CreateRGBSurface(SDL_HWSURFACE, WIDTH * BLOC_SIZE, HEIGHT * BLOC_SIZE, 32, 0x0, 0x0, 0x0, 0x0);
|
|
|
+ SDL_Surface* tileCurrent = tileSet[0];
|
|
|
|
|
|
// [2.6] First map render
|
|
|
drawWorld(world, tileSet, map);
|
|
@@ -127,12 +128,12 @@ int main()
|
|
|
break;
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
|
|
if (event.button.button == 1) {
|
|
|
- putBloc(DESERT, world, cursorPos.y, cursorPos.x);
|
|
|
+ putBloc((blocType)indexCurrent, world, cursorPos.y, cursorPos.x);
|
|
|
drawWorld(world, tileSet, map);
|
|
|
}
|
|
|
if (event.button.button == 3) {
|
|
|
- putBloc(GRASS, world, cursorPos.y, cursorPos.x);
|
|
|
- drawWorld(world, tileSet, map);
|
|
|
+ indexCurrent++;
|
|
|
+ if (indexCurrent >= BLOC_TOTAL) indexCurrent = 0;
|
|
|
}
|
|
|
break;
|
|
|
} // end switch event type
|
|
@@ -146,7 +147,7 @@ int main()
|
|
|
|
|
|
SDL_BlitSurface(map, NULL, screen, NULL);
|
|
|
|
|
|
- SDL_BlitSurface(pawn, NULL, screen, &pawnPos);
|
|
|
+ SDL_BlitSurface(tileSet[indexCurrent], NULL, screen, &pawnPos);
|
|
|
|
|
|
SDL_Flip(screen);
|
|
|
|
|
@@ -158,7 +159,6 @@ int main()
|
|
|
SDL_FreeSurface(water);
|
|
|
SDL_FreeSurface(desert);
|
|
|
SDL_FreeSurface(mountain);
|
|
|
- SDL_FreeSurface(pawn);
|
|
|
|
|
|
SDL_FreeSurface(screen);
|
|
|
|