Calculados los items totales del mapeado

This commit is contained in:
2022-11-06 14:04:59 +01:00
parent 3d0400fe88
commit ec5da9ae3e
4 changed files with 33 additions and 9 deletions

View File

@@ -286,3 +286,9 @@ room_t *Resource::getRoom(std::string name)
} }
return nullptr; return nullptr;
} }
// Obtiene todas las habitaciones
std::vector<res_room_t> *Resource::getAllRooms()
{
return &rooms;
}

View File

@@ -116,6 +116,9 @@ public:
// Obtiene una habitacion // Obtiene una habitacion
room_t *getRoom(std::string name); room_t *getRoom(std::string name);
// Obtiene todas las habitaciones
std::vector<res_room_t> *getAllRooms();
}; };
#endif #endif

View File

@@ -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); text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
music = JA_LoadMusic(asset->get("game.ogg").c_str()); music = JA_LoadMusic(asset->get("game.ogg").c_str());
deathSound = JA_LoadSound(asset->get("death.wav").c_str()); deathSound = JA_LoadSound(asset->get("death.wav").c_str());
test = new Test(renderer, screen, asset, debug);
// Inicializa el resto de variables // Inicializa el resto de variables
ticks = 0; ticks = 0;
@@ -51,6 +50,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
paused = false; paused = false;
blackScreen = false; blackScreen = false;
blackScreenCounter = 0; blackScreenCounter = 0;
totalItems = getTotalItems();
section.name = SECTION_PROG_GAME; section.name = SECTION_PROG_GAME;
section.subsection = 0; section.subsection = 0;
@@ -69,8 +69,6 @@ Game::~Game()
JA_DeleteMusic(music); JA_DeleteMusic(music);
JA_DeleteSound(deathSound); JA_DeleteSound(deathSound);
delete test;
} }
// Comprueba los eventos de la cola // Comprueba los eventos de la cola
@@ -237,7 +235,7 @@ void Game::render()
// Debug info // Debug info
renderDebugInfo(); renderDebugInfo();
screen->renderFX(); // screen->renderFX();
// Actualiza la pantalla // Actualiza la pantalla
screen->blit(); screen->blit();
@@ -501,9 +499,9 @@ void Game::setScoreBoardColor()
bool Game::checkEndGame() bool Game::checkEndGame()
{ {
const bool a = room->getName() == "THE JAIL"; const bool a = room->getName() == "THE JAIL"; // Estar en la habitación que toca
const bool b = board.items >= 5; const bool b = board.items >= totalItems * 0.9f; // Con mas del 90% de los items recogidos
const bool c = player->getRect().x <= 128; const bool c = player->getRect().x <= 128; // Estar en la ubicación que toca (En la puerta)
if (b) if (b)
{ {
@@ -518,3 +516,18 @@ bool Game::checkEndGame()
return false; return false;
} }
// Obtiene la cantidad total de items que hay en el mapeado del juego
int Game::getTotalItems()
{
int items = 0;
std::vector<res_room_t> *rooms = new std::vector<res_room_t>;
rooms = resource->getAllRooms();
for (auto room : *rooms)
{
items += room.room->items.size();
}
return items;
}

View File

@@ -17,7 +17,6 @@
#include "room_tracker.h" #include "room_tracker.h"
#include "room.h" #include "room.h"
#include "scoreboard.h" #include "scoreboard.h"
#include "test.h"
#ifndef GAME_H #ifndef GAME_H
#define GAME_H #define GAME_H
@@ -40,7 +39,6 @@ private:
Resource *resource; // Objeto con los recursos Resource *resource; // Objeto con los recursos
Debug *debug; // Objeto para gestionar la información de debug Debug *debug; // Objeto para gestionar la información de debug
options_t *options; // Puntero a las opciones del juego options_t *options; // Puntero a las opciones del juego
Test *test;
// Variables // Variables
JA_Music music; // Musica que suena durante el juego 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 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 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 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. // Actualiza el juego, las variables, comprueba la entrada, etc.
void update(); void update();
@@ -115,6 +114,9 @@ private:
// Comprueba si ha finalizado el juego // Comprueba si ha finalizado el juego
bool checkEndGame(); bool checkEndGame();
// Obtiene la cantidad total de items que hay en el mapeado del juego
int getTotalItems();
public: public:
// Constructor // Constructor
Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, Debug *debug); Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, Input *input, Debug *debug);