Cambiada la variable section por un puntero

This commit is contained in:
2022-12-16 09:32:33 +01:00
parent 2abde36a5e
commit 4d8bb46a52
22 changed files with 191 additions and 216 deletions

View File

@@ -1,7 +1,7 @@
#include "game_over.h"
// Constructor
GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options)
GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, options_t *options, section_t *section)
{
// Copia los punteros
this->renderer = renderer;
@@ -9,6 +9,7 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
this->resource = resource;
this->asset = asset;
this->options = options;
this->section = section;
// Reserva memoria para los punteros a objetos
eventHandler = new SDL_Event();
@@ -20,8 +21,8 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
// Inicializa variables
preCounter = 0;
counter = 0;
section.name = SECTION_PROG_GAME_OVER;
section.subsection = 0;
section->name = SECTION_PROG_GAME_OVER;
section->subsection = 0;
ticks = 0;
ticksSpeed = 15;
endSection = 400;
@@ -83,7 +84,7 @@ void GameOver::update()
void GameOver::render()
{
const int y = 32;
// Prepara para empezar a dibujar en la textura de juego
screen->start();
@@ -121,8 +122,8 @@ void GameOver::checkEventHandler()
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section.name = SECTION_PROG_QUIT;
section.subsection = 0;
section->name = SECTION_PROG_QUIT;
section->subsection = 0;
break;
}
@@ -132,7 +133,7 @@ void GameOver::checkEventHandler()
switch (eventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_ESCAPE:
section.name = SECTION_PROG_QUIT;
section->name = SECTION_PROG_QUIT;
break;
case SDL_SCANCODE_B:
@@ -177,15 +178,13 @@ void GameOver::checkEventHandler()
}
// Bucle principal
section_t GameOver::run()
void GameOver::run()
{
while (section.name == SECTION_PROG_GAME_OVER)
while (section->name == SECTION_PROG_GAME_OVER)
{
update();
render();
}
return section;
}
// Actualiza el color usado para renderizar los textos e imagenes
@@ -195,7 +194,6 @@ void GameOver::updateColor()
if (counter < half)
{
// const float step = std::min(std::max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght;
const float step = std::min(counter, fadeLenght) / (float)fadeLenght;
const int index = (colors.size() - 1) - int((colors.size() - 1) * step);
color = colors[index];
@@ -240,8 +238,8 @@ void GameOver::updateCounters()
// Comprueba si ha terminado la sección
else if (counter == endSection)
{
section.name = SECTION_PROG_LOGO;
section.subsection = SUBSECTION_LOGO_TO_TITLE;
section->name = SECTION_PROG_LOGO;
section->subsection = SUBSECTION_LOGO_TO_TITLE;
}
}