diff --git a/source/game.cpp b/source/game.cpp index 97f007b..d26b9be 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -400,6 +400,7 @@ void Game::killPlayer() // Recarga todas las texturas void Game::reLoadTextures() { + std::cout << "** RELOAD REQUESTED" << std::endl; player->reLoadTexture(); room->reLoadTexture(); scoreboard->reLoadTexture(); diff --git a/source/room.cpp b/source/room.cpp index 0da797b..3b451d9 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -15,7 +15,7 @@ std::vector loadRoomTileFile(std::string file_path) if (file.good()) { // Procesa el fichero linea a linea - //printf("Reading file %s\n", filename.c_str()); + // printf("Reading file %s\n", filename.c_str()); while (std::getline(file, line)) { // Lee el fichero linea a linea @@ -55,6 +55,10 @@ std::vector loadRoomTileFile(std::string file_path) room_t loadRoomFile(std::string file_path) { room_t room; + room.itemColor1 = "yellow"; + room.itemColor2 = "magenta"; + room.autoSurfaceDirection = 1; + const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1); std::string line; std::ifstream file(file_path); @@ -63,14 +67,12 @@ room_t loadRoomFile(std::string file_path) if (file.good()) { // Procesa el fichero linea a linea - //printf("Reading file %s\n\n", filename.c_str()); while (std::getline(file, line)) { // Si la linea contiene el texto [enemy] se realiza el proceso de carga de un enemigo if (line == "[enemy]") { enemy_t enemy; - // enemy.renderer = renderer; enemy.flip = false; enemy.palette = p_zxspectrum; @@ -96,7 +98,6 @@ room_t loadRoomFile(std::string file_path) else if (line == "[item]") { item_t item; - // item.renderer = renderer; item.counter = 0; item.color1 = stringToColor(p_zxspectrum, "yellow"); item.color2 = stringToColor(p_zxspectrum, "magenta"); @@ -116,12 +117,6 @@ room_t loadRoomFile(std::string file_path) } while (line != "[/item]"); - // Añade el item al vector de items - // const SDL_Point itemPos = {item.x, item.y}; - // if (!itemTracker->hasBeenPicked(room.name, itemPos)) - //{ - // room.items.push_back(new Item(item)); - // } room.items.push_back(item); } @@ -130,6 +125,7 @@ room_t loadRoomFile(std::string file_path) { // Encuentra la posición del caracter '=' int pos = line.find("="); + // Procesa las dos subcadenas if (!setVars(&room, line.substr(0, pos), line.substr(pos + 1, line.length()))) { @@ -190,14 +186,6 @@ bool setVars(room_t *room, std::string var, std::string value) else if (var == "tileSetFile") { room->tileSetFile = value; - /*if (options->palette == p_zxspectrum) - { - tileSetFile = "standard.png"; - } - else if (options->palette == p_zxarne) - { - tileSetFile = "standard_zxarne.png"; - }*/ } else if (var == "roomUp") @@ -385,8 +373,8 @@ Room::Room(room_t *room, SDL_Renderer *renderer, Screen *screen, Asset *asset, o name = room->name; bgColor = room->bgColor; borderColor = room->borderColor; - itemColor1 = room->itemColor1 == ""?"yellow":room->itemColor1; - itemColor2 = room->itemColor2 == ""?"magenta":room->itemColor2; + itemColor1 = room->itemColor1 == "" ? "yellow" : room->itemColor1; + itemColor2 = room->itemColor2 == "" ? "magenta" : room->itemColor2; roomUp = room->roomUp; roomDown = room->roomDown; roomLeft = room->roomLeft; @@ -913,7 +901,8 @@ void Room::setBottomSurfaces() // Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies int i = 0; int lastOne = 0; - while (i < (int)tile.size()) + // while (i < (int)tile.size()) + do { h_line_t line; line.x1 = (tile.at(i) % mapWidth) * tileSize; @@ -924,6 +913,10 @@ void Room::setBottomSurfaces() while (tile.at(i) == tile.at(i - 1) + 1) { lastOne = i; + if (i == (int)tile.size() - 1) + { + break; + } i++; } @@ -933,7 +926,7 @@ void Room::setBottomSurfaces() { // Si el siguiente elemento es un separador, hay que saltarlo i++; } - } + } while (i < (int)tile.size() - 1); } // Calcula las superficies superiores @@ -960,7 +953,8 @@ void Room::setTopSurfaces() // Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies int i = 0; int lastOne = 0; - while (i < (int)tile.size()) + // while (i < (int)tile.size()) + do { h_line_t line; line.x1 = (tile.at(i) % mapWidth) * tileSize; @@ -971,6 +965,10 @@ void Room::setTopSurfaces() while (tile.at(i) == tile.at(i - 1) + 1) { lastOne = i; + if (i == (int)tile.size() - 1) + { + break; + } i++; } @@ -980,7 +978,7 @@ void Room::setTopSurfaces() { // Si el siguiente elemento es un separador, hay que saltarlo i++; } - } + } while (i < (int)tile.size() - 1); } // Calcula las superficies laterales izquierdas @@ -1006,19 +1004,24 @@ void Room::setLeftSurfaces() // (Los tiles de la misma columna, la diferencia entre ellos es de mapWidth) // para localizar las superficies int i = 0; - while (i < (int)tile.size()) + // while (i < (int)tile.size()) + do { v_line_t line; line.x = (tile.at(i) % mapWidth) * tileSize; line.y1 = ((tile.at(i) / mapWidth) * tileSize); while (tile.at(i) + mapWidth == tile[i + 1]) { + if (i == (int)tile.size() - 1) + { + break; + } i++; } line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1; leftSurfaces.push_back(line); i++; - } + } while (i < (int)tile.size() - 1); } // Calcula las superficies laterales derechas @@ -1044,19 +1047,24 @@ void Room::setRightSurfaces() // (Los tiles de la misma columna, la diferencia entre ellos es de mapWidth) // para localizar las superficies int i = 0; - while (i < (int)tile.size()) + // while (i < (int)tile.size()) + do { v_line_t line; line.x = ((tile.at(i) % mapWidth) * tileSize) + tileSize - 1; line.y1 = ((tile.at(i) / mapWidth) * tileSize); while (tile.at(i) + mapWidth == tile[i + 1]) { + if (i == (int)tile.size() - 1) + { + break; + } i++; } line.y2 = ((tile.at(i) / mapWidth) * tileSize) + tileSize - 1; rightSurfaces.push_back(line); i++; - } + } while (i < (int)tile.size() - 1); } // Encuentra todas las rampas que suben hacia la izquierda