JA VA! Nomes s'havia de fer les coses be i no ser un ansias

This commit is contained in:
2025-02-22 00:30:32 +01:00
parent f6098a479b
commit e361d295c1
39 changed files with 1053 additions and 1098 deletions

View File

@@ -11,9 +11,10 @@
#include "screen.h" // Para Screen
#include "text.h" // Para Text, TXT_CENTER, TXT_COLOR
#include "texture.h" // Para Texture
#include "options.h"
// Constructor
GameOver::GameOver(Resource *resource, options_t *options, section_t *section)
GameOver::GameOver(Resource *resource)
{
// Copia los punteros
this->screen = Screen::get();
@@ -21,8 +22,6 @@ GameOver::GameOver(Resource *resource, options_t *options, section_t *section)
this->resource = resource;
this->asset = Asset::get();
this->input = Input::get();
this->options = options;
this->section = section;
// Reserva memoria para los punteros a objetos
eventHandler = new SDL_Event();
@@ -34,8 +33,8 @@ GameOver::GameOver(Resource *resource, options_t *options, section_t *section)
// Inicializa variables
preCounter = 0;
counter = 0;
section->name = SECTION_GAME_OVER;
section->subsection = 0;
options.section.name = SECTION_GAME_OVER;
options.section.subsection = 0;
ticks = 0;
ticksSpeed = 15;
endSection = 400;
@@ -50,7 +49,7 @@ GameOver::GameOver(Resource *resource, options_t *options, section_t *section)
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));
colors.push_back(stringToColor(options.palette, cl));
}
color = colors.back();
}
@@ -113,14 +112,14 @@ void GameOver::render()
renderSprites();
// Escribe el texto con las habitaciones y los items
const std::string itemsTxt = std::to_string(options->stats.items / 100) + std::to_string((options->stats.items % 100) / 10) + std::to_string(options->stats.items % 10);
const std::string roomsTxt = std::to_string(options->stats.rooms / 100) + std::to_string((options->stats.rooms % 100) / 10) + std::to_string(options->stats.rooms % 10);
const std::string itemsTxt = std::to_string(options.stats.items / 100) + std::to_string((options.stats.items % 100) / 10) + std::to_string(options.stats.items % 10);
const std::string roomsTxt = std::to_string(options.stats.rooms / 100) + std::to_string((options.stats.rooms % 100) / 10) + std::to_string(options.stats.rooms % 10);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 80, "ITEMS: " + itemsTxt, 1, color);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 90, "ROOMS: " + roomsTxt, 1, color);
// Escribe el texto con "Tu peor pesadilla"
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 110, "YOUR WORST NIGHTMARE IS", 1, color);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 120, options->stats.worstNightmare, 1, color);
text->writeDX(TXT_CENTER | TXT_COLOR, GAMECANVAS_CENTER_X, y + 120, options.stats.worstNightmare, 1, color);
// Vuelca el contenido del renderizador en pantalla
screen->render();
@@ -135,8 +134,8 @@ void GameOver::checkEvents()
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section->name = SECTION_QUIT;
section->subsection = 0;
options.section.name = SECTION_QUIT;
options.section.subsection = 0;
break;
}
}
@@ -148,7 +147,7 @@ void GameOver::checkInput()
if (input->checkInput(input_exit, REPEAT_FALSE))
{
section->name = SECTION_QUIT;
options.section.name = SECTION_QUIT;
}
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
@@ -180,7 +179,7 @@ void GameOver::checkInput()
// Bucle principal
void GameOver::run()
{
while (section->name == SECTION_GAME_OVER)
while (options.section.name == SECTION_GAME_OVER)
{
update();
checkEvents();
@@ -239,13 +238,13 @@ void GameOver::updateCounters()
// Comprueba si ha terminado la sección
else if (counter == endSection)
{
section->name = SECTION_LOGO;
section->subsection = SUBSECTION_LOGO_TO_TITLE;
options.section.name = SECTION_LOGO;
options.section.subsection = SUBSECTION_LOGO_TO_TITLE;
}
}
// Cambia la paleta
void GameOver::switchPalette()
{
options->palette = (options->palette == p_zxspectrum) ? p_zxarne : p_zxspectrum;
options.palette = (options.palette == p_zxspectrum) ? p_zxarne : p_zxspectrum;
}