diff --git a/Makefile b/Makefile index 309bc8a..3e1848e 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ macos: mkdir -p bin - g++ source/*.cpp -std=c++11 -Wall -O2 -lSDL2 -lSDL2_image -lSDL2_mixer -o bin/volcano_macos + g++ source/*.cpp -std=c++11 -Wall -O2 -lSDL2 -o bin/volcano_macos linux: mkdir -p bin - g++ source/*.cpp -std=c++11 -Wall -O2 -lSDL2 -lSDL2_image -lSDL2_mixer -o bin/volcano_macos \ No newline at end of file + g++ source/*.cpp -std=c++11 -Wall -O2 -lSDL2 -o bin/volcano_macos \ No newline at end of file diff --git a/source/volcano.cpp b/source/volcano.cpp index 724cd59..07d5b36 100644 --- a/source/volcano.cpp +++ b/source/volcano.cpp @@ -8,8 +8,14 @@ #include "volcano.h" #include -#define CLOSE_SOUND(a) if (a != nullptr) JA_DeleteSound(a); a = nullptr -#define CLOSE_MUSIC(a) if (a != nullptr) JA_DeleteMusic(a); a = nullptr +#define CLOSE_SOUND(a) \ + if (a != nullptr) \ + JA_DeleteSound(a); \ + a = nullptr +#define CLOSE_MUSIC(a) \ + if (a != nullptr) \ + JA_DeleteMusic(a); \ + a = nullptr void allocatePointers() { @@ -259,7 +265,7 @@ void setExecutablePath(std::string path) executablePath = path.substr(0, path.find_last_of("\\/")); } -void LoadMap() +/*void LoadMap_old() { std::string p = executablePath + "/" + FILE_MAP_VOLCANO.c_str(); std::string filename = p.substr(p.find_last_of("\\/") + 1); @@ -291,6 +297,63 @@ void LoadMap() } delete[] buf; +}*/ + +void LoadMap() +{ + std::string p = executablePath + "/" + FILE_MAP_VOLCANO.c_str(); + std::string filename = p.substr(p.find_last_of("\\/") + 1); + + SDL_RWops *file = SDL_RWFromFile(p.c_str(), "r+b"); + Uint8 *w = new Uint8(); + Uint8 *h = new Uint8(); + Uint8 column = 0; + Uint8 line = 0; + Uint8 room = 0; + + if (file == NULL) + { + printf("Warning: Unable to open %s file\n", filename.c_str()); + } + else + { + printf("Reading file %s\n", filename.c_str()); + + SDL_RWread(file, w, sizeof(Uint8), 1); + SDL_RWread(file, h, sizeof(Uint8), 1); + + long size = (*w) * (*h); + + map.tile = new Uint8[size]; + map.actor = new Uint8[size]; + + for (Uint32 i = 0; i < size; i++) + { + SDL_RWread(file, &map.tile[i], sizeof(Uint8), 1); + column++; + //std::cout << std::to_string(map.tile[i]); + printf("%-3s ", std::to_string(map.tile[i]).c_str()); + if (column == ROOM_WIDTH_IN_TILES) + { + column = 0; + line++; + printf("\n"); + } + if (line == ROOM_HEIGHT_IN_TILES) + { + line = 0; + printf("==================== ROOM #%-3s =================================\n", std::to_string(room).c_str()); + room++; + } + } + + for (Uint32 i = 0; i < size; i++) + SDL_RWread(file, &map.actor[i], sizeof(Uint8), 1); + + SDL_RWclose(file); + } + delete w; + delete h; } void LoadRoom(int num) @@ -615,7 +678,7 @@ void IniMenu() void EndMenu() { - + CLOSE_SOUND(menu.sound_logo); CLOSE_SOUND(menu.sound_start); CLOSE_MUSIC(menu.music); @@ -1410,10 +1473,7 @@ void DrawMap() src_rect1.y = (GetTile(i, j) / 16) * MAP_TILE_HEIGHT; dst_rect1.x = i * MAP_TILE_WIDTH; dst_rect1.y = j * MAP_TILE_HEIGHT; - // DES 2021 - map.sprite_tile->render(renderer, dst_rect1.x, dst_rect1.y, &src_rect1); - // END - //map.sprite_tile->render(renderer, dst_rect1.x, dst_rect1.y); + map.sprite_tile->render(renderer, dst_rect1.x, dst_rect1.y, &src_rect1, 45.0); } Uint8 i = 0; @@ -1741,7 +1801,7 @@ void IniProgram() prog.music_enabled = true; prog.filter = true; SetProgSection(SECTION_MENU); - prog.debug = false; + prog.debug = true; /*if (prog.music_enabled) // [TODO] Jail_Audio encara no permet canviar el volum Mix_VolumeMusic(100); @@ -1783,7 +1843,7 @@ int main(int argc, char *args[]) // Inicializa el audio //Mix_OpenAudio(MIX_DEFAULT_FREQUENCY, MIX_DEFAULT_FORMAT, 2, 2048); JA_Init(22050, AUDIO_S16SYS, 2); - + allocatePointers(); // Inicializa el programa IniProgram();