diff --git a/source/common/resource.cpp b/source/common/resource.cpp index 65cc912..15d7239 100644 --- a/source/common/resource.cpp +++ b/source/common/resource.cpp @@ -285,4 +285,10 @@ room_t *Resource::getRoom(std::string name) std::cout << "NOT FOUND ON CACHE: " << name << std::endl; } return nullptr; +} + +// Obtiene todas las habitaciones +std::vector *Resource::getAllRooms() +{ + return &rooms; } \ No newline at end of file diff --git a/source/common/resource.h b/source/common/resource.h index 00d0f91..691d49e 100644 --- a/source/common/resource.h +++ b/source/common/resource.h @@ -116,6 +116,9 @@ public: // Obtiene una habitacion room_t *getRoom(std::string name); + + // Obtiene todas las habitaciones + std::vector *getAllRooms(); }; #endif diff --git a/source/game.cpp b/source/game.cpp index 91b8d5a..6703671 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -36,7 +36,6 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer); music = JA_LoadMusic(asset->get("game.ogg").c_str()); deathSound = JA_LoadSound(asset->get("death.wav").c_str()); - test = new Test(renderer, screen, asset, debug); // Inicializa el resto de variables ticks = 0; @@ -51,6 +50,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as paused = false; blackScreen = false; blackScreenCounter = 0; + totalItems = getTotalItems(); section.name = SECTION_PROG_GAME; section.subsection = 0; @@ -69,8 +69,6 @@ Game::~Game() JA_DeleteMusic(music); JA_DeleteSound(deathSound); - - delete test; } // Comprueba los eventos de la cola @@ -237,7 +235,7 @@ void Game::render() // Debug info renderDebugInfo(); - screen->renderFX(); + // screen->renderFX(); // Actualiza la pantalla screen->blit(); @@ -501,9 +499,9 @@ void Game::setScoreBoardColor() bool Game::checkEndGame() { - const bool a = room->getName() == "THE JAIL"; - const bool b = board.items >= 5; - const bool c = player->getRect().x <= 128; + const bool a = room->getName() == "THE JAIL"; // Estar en la habitación que toca + const bool b = board.items >= totalItems * 0.9f; // Con mas del 90% de los items recogidos + const bool c = player->getRect().x <= 128; // Estar en la ubicación que toca (En la puerta) if (b) { @@ -517,4 +515,19 @@ bool Game::checkEndGame() } return false; +} + +// Obtiene la cantidad total de items que hay en el mapeado del juego +int Game::getTotalItems() +{ + int items = 0; + std::vector *rooms = new std::vector; + rooms = resource->getAllRooms(); + + for (auto room : *rooms) + { + items += room.room->items.size(); + } + + return items; } \ No newline at end of file diff --git a/source/game.h b/source/game.h index a25b6a6..c048e61 100644 --- a/source/game.h +++ b/source/game.h @@ -17,7 +17,6 @@ #include "room_tracker.h" #include "room.h" #include "scoreboard.h" -#include "test.h" #ifndef GAME_H #define GAME_H @@ -40,7 +39,6 @@ private: Resource *resource; // Objeto con los recursos Debug *debug; // Objeto para gestionar la información de debug options_t *options; // Puntero a las opciones del juego - Test *test; // Variables JA_Music music; // Musica que suena durante el juego @@ -54,6 +52,7 @@ private: bool paused; // Indica si el juego se encuentra en pausa bool blackScreen; // Indica si la pantalla está en negro. Se utiliza para la muerte del jugador int blackScreenCounter; // Contador para temporizar la pantalla en negro + int totalItems; // Cantidad total de items que hay en el mapeado del juego // Actualiza el juego, las variables, comprueba la entrada, etc. void update(); @@ -115,6 +114,9 @@ private: // Comprueba si ha finalizado el juego bool checkEndGame(); + // Obtiene la cantidad total de items que hay en el mapeado del juego + int getTotalItems(); + public: // Constructor Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, Debug *debug);