Trabajando en la pantalla de game over

This commit is contained in:
2022-11-06 19:28:12 +01:00
parent 6dfc7e135c
commit 6fe596bf48
4 changed files with 52 additions and 19 deletions

View File

@@ -12,7 +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);
text = new Text(resource->getOffset("smb2.txt"), resource->getTexture("smb2.png"), renderer);
// Inicializa variables
counter = 0;
@@ -20,6 +20,17 @@ GameOver::GameOver(SDL_Renderer *renderer, Screen *screen, Resource *resource, A
section.subsection = 0;
ticks = 0;
ticksSpeed = 15;
endSection = 300;
iniFade = 210;
fadeLenght = 30;
// Inicializa el vector de colores
const std::vector<std::string> colorList = {"white", "yellow", "cyan", "green", "magenta", "red", "blue", "black"};
for (auto cl : colorList)
{
colors.push_back(stringToColor(options->palette, cl));
}
color = colors.at(0);
}
// Destructor
@@ -42,9 +53,12 @@ void GameOver::update()
// Comprueba el manejador de eventos
checkEventHandler();
// Actualiza el color usado para renderizar los textos e imagenes
updateColor();
counter++;
if (counter == 400)
if (counter == endSection)
{
section.name = SECTION_PROG_TITLE;
}
@@ -60,7 +74,10 @@ void GameOver::render()
// Limpia la pantalla
screen->clean();
text->writeCentered(GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y, "G A M E O V E R");
// Escribe el texto de GAME OVER
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, GAMECANVAS_CENTER_Y, "G A M E O V E R", 1, color);
text->write(0, 0, std::to_string(counter));
// Vuelca el contenido del renderizador en pantalla
screen->blit();
@@ -124,8 +141,8 @@ void GameOver::checkEventHandler()
break;
default:
//section.name = SECTION_PROG_TITLE;
//section.subsection = 0;
// section.name = SECTION_PROG_TITLE;
// section.subsection = 0;
break;
}
}
@@ -142,4 +159,12 @@ section_t GameOver::run()
}
return section;
}
// Actualiza el color usado para renderizar los textos e imagenes
void GameOver::updateColor()
{
const float step = std::min(std::max(counter, iniFade) - iniFade, fadeLenght) / (float)fadeLenght;
const int index = (colors.size() - 1) * step;
color = colors.at(index);
}