Añadida pantalla de game over funcional

This commit is contained in:
2022-11-06 14:48:02 +01:00
parent ec5da9ae3e
commit 0cb83657be
4 changed files with 28 additions and 15 deletions

View File

@@ -443,10 +443,15 @@ void Director::loadResources(section_t section)
else if (section.name == SECTION_PROG_GAME_OVER)
{
std::vector<std::string> textureList;
textureList.push_back("jailgames.png");
textureList.push_back("since_1998.png");
textureList.push_back("smb2.png");
resource->loadTextures(textureList);
// Offsets
std::vector<std::string> offsetsList;
offsetsList.push_back("smb2.txt");
resource->loadOffsets(offsetsList);
}
else if (section.name == SECTION_PROG_GAME || section.name == SECTION_PROG_DEMO)

View File

@@ -40,7 +40,7 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as
// Inicializa el resto de variables
ticks = 0;
ticksSpeed = 15;
board.lives = 9;
board.lives = 2;
board.items = 0;
board.rooms = 1;
board.music = true;
@@ -372,7 +372,7 @@ void Game::checkGameOver()
{
if (board.lives < 0)
{
section.name = SECTION_PROG_TITLE;
section.name = SECTION_PROG_GAME_OVER;
}
}
@@ -410,7 +410,7 @@ void Game::killPlayer()
this->player->pause();
// Deshabilita las entradas hasta que no haya ninguna activa
input->disableUntil(d_keyPressed);
//input->disableUntil(d_keyPressed);
}
// Recarga todas las texturas
@@ -458,7 +458,7 @@ void Game::updateBlackScreen()
if (blackScreen)
{
blackScreenCounter++;
if (blackScreenCounter > 10)
if (blackScreenCounter > 20)
{
blackScreen = false;
blackScreenCounter = 0;
@@ -498,10 +498,9 @@ void Game::setScoreBoardColor()
// Comprueba si ha finalizado el juego
bool Game::checkEndGame()
{
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)
const bool b = board.items >= int(totalItems * 0.9f); // Con mas del 90% de los items recogidos
const bool c = player->getRect().x <= 128; // Y en la ubicación que toca (En la puerta)
if (b)
{

View File

@@ -12,6 +12,7 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
// Reserva memoria para los punteros a objetos
eventHandler = new SDL_Event();
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
// Inicializa variables
counter = 0;
@@ -26,6 +27,7 @@ GameOver::~GameOver()
{
// Libera la memoria de los objetos
delete eventHandler;
delete text;
}
// Actualiza el objeto
@@ -39,6 +41,13 @@ void GameOver::update()
// Comprueba el manejador de eventos
checkEventHandler();
counter++;
if (counter == 400)
{
section.name = SECTION_PROG_TITLE;
}
}
}
@@ -51,6 +60,8 @@ void GameOver::render()
// Limpia la pantalla
screen->clean();
text->writeCentered(GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y, "G A M E O V E R");
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
@@ -65,6 +76,7 @@ void GameOver::checkEventHandler()
if (eventHandler->type == SDL_QUIT)
{
section.name = SECTION_PROG_QUIT;
section.subsection = 0;
break;
}

View File

@@ -26,9 +26,6 @@ private:
options_t *options; // Puntero a las opciones del juego
SDL_Event *eventHandler; // Manejador de eventos
Text *text; // Objeto para escribir texto en pantalla
SDL_Texture *textTexture; // Textura para dibujar el texto
SDL_Texture *coverTexture; // Textura para cubrir el texto
AnimatedSprite *sprite; // Sprite para el brillo del corazón
// Variables
int counter; // Contador