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

@@ -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<res_room_t> *Resource::getAllRooms()
{
return &rooms;
}

View File

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