canvi de pc

This commit is contained in:
2025-02-21 19:45:29 +01:00
parent 5f68c6256f
commit 7a0bc5c9ae
18 changed files with 918 additions and 889 deletions

View File

@@ -12,78 +12,70 @@
#include "utils.h" // for options_t, section_t, color_t, stringToC...
// Constructor
LoadingScreen::LoadingScreen(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *asset, Input *input, options_t *options, section_t *section)
{
// Copia la dirección de los objetos
this->resource = resource;
this->renderer = renderer;
this->screen = screen;
this->asset = asset;
this->input = input;
this->options = options;
this->section = section;
LoadingScreen::LoadingScreen(Resource *resource, options_t *options, section_t *section)
: resource_(resource),
screen_(Screen::get()),
renderer_(Screen::get()->getRenderer()),
asset_(Asset::get()),
input_(Input::get()),
options_(options),
section_(section)
{
// Reserva memoria para los punteros
eventHandler = new SDL_Event();
if (options->palette == p_zxspectrum)
{
loadingScreenTexture1 = resource->getTexture("loading_screen_bn.png");
loadingScreenTexture2 = resource->getTexture("loading_screen_color.png");
mono_loading_screen_texture_ = resource->getTexture("loading_screen_bn.png");
color_loading_screen_texture_ = resource->getTexture("loading_screen_color.png");
}
else if (options->palette == p_zxarne)
{
loadingScreenTexture1 = resource->getTexture("loading_screen_bn_zxarne.png");
loadingScreenTexture2 = resource->getTexture("loading_screen_color_zxarne.png");
mono_loading_screen_texture_ = resource->getTexture("loading_screen_bn_zxarne.png");
color_loading_screen_texture_ = resource->getTexture("loading_screen_color_zxarne.png");
}
sprite1 = new Sprite(0, 0, loadingScreenTexture1->getWidth(), loadingScreenTexture1->getHeight(), loadingScreenTexture1, renderer);
sprite2 = new Sprite(0, 0, loadingScreenTexture2->getWidth(), loadingScreenTexture2->getHeight(), loadingScreenTexture2, renderer);
loadingSound1 = JA_LoadMusic(asset->get("loading_sound1.ogg").c_str());
loadingSound2 = JA_LoadMusic(asset->get("loading_sound2.ogg").c_str());
loadingSound3 = JA_LoadMusic(asset->get("loading_sound3.ogg").c_str());
mono_loading_screen_sprite_ = new Sprite(0, 0, mono_loading_screen_texture_->getWidth(), mono_loading_screen_texture_->getHeight(), mono_loading_screen_texture_, renderer_);
color_loading_screen_sprite_ = new Sprite(0, 0, color_loading_screen_texture_->getWidth(), color_loading_screen_texture_->getHeight(), color_loading_screen_texture_, renderer_);
loading_sound1_ = JA_LoadMusic(asset_->get("loading_sound1.ogg").c_str());
loading_sound2_ = JA_LoadMusic(asset_->get("loading_sound2.ogg").c_str());
loading_sound3_ = JA_LoadMusic(asset_->get("loading_sound3.ogg").c_str());
// Inicializa variables
preCounter = 0;
counter = 0;
section->name = SECTION_LOADING_SCREEN;
section->subsection = 0;
ticks = 0;
ticksSpeed = 15;
loadCounter = 0;
loadingFirstPart = true;
loadRect = {0, 0, 51, 1};
// Establece el orden de las lineas para imitar el direccionamiento de memoria del spectrum
for (int i = 0; i < 192; ++i)
{
if (i < 64)
{ // Primer bloque de 2K
lineIndex[i] = ((i % 8) * 8) + (i / 8);
line_index_[i] = ((i % 8) * 8) + (i / 8);
}
else if (i >= 64 && i < 128)
{ // Segundo bloque de 2K
lineIndex[i] = 64 + ((i % 8) * 8) + ((i - 64) / 8);
line_index_[i] = 64 + ((i % 8) * 8) + ((i - 64) / 8);
}
else if (i >= 128 && i < 192)
{ // tercer bloque de 2K
lineIndex[i] = 128 + ((i % 8) * 8) + ((i - 128) / 8);
line_index_[i] = 128 + ((i % 8) * 8) + ((i - 128) / 8);
}
}
// Cambia el color del borde
screen->setBorderColor(stringToColor(options->palette, "black"));
screen_->setBorderColor(stringToColor(options->palette, "black"));
}
// Destructor
LoadingScreen::~LoadingScreen()
{
delete sprite1;
delete sprite2;
delete mono_loading_screen_sprite_;
delete color_loading_screen_sprite_;
delete eventHandler;
JA_DeleteMusic(loadingSound1);
JA_DeleteMusic(loadingSound2);
JA_DeleteMusic(loadingSound3);
JA_DeleteMusic(loading_sound1_);
JA_DeleteMusic(loading_sound2_);
JA_DeleteMusic(loading_sound3_);
}
// Comprueba el manejador de eventos
@@ -95,7 +87,7 @@ void LoadingScreen::checkEvents()
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section->name = SECTION_QUIT;
section_->name = SECTION_QUIT;
break;
}
}
@@ -105,40 +97,40 @@ void LoadingScreen::checkEvents()
void LoadingScreen::checkInput()
{
if (input->checkInput(input_exit, REPEAT_FALSE))
if (input_->checkInput(input_exit, REPEAT_FALSE))
{
section->name = SECTION_QUIT;
section_->name = SECTION_QUIT;
}
else if (input->checkInput(input_toggle_border, REPEAT_FALSE))
else if (input_->checkInput(input_toggle_border, REPEAT_FALSE))
{
screen->toggleBorder();
screen_->toggleBorder();
}
else if (input->checkInput(input_toggle_videomode, REPEAT_FALSE))
else if (input_->checkInput(input_toggle_videomode, REPEAT_FALSE))
{
screen->toggleVideoMode();
screen_->toggleVideoMode();
}
else if (input->checkInput(input_window_dec_size, REPEAT_FALSE))
else if (input_->checkInput(input_window_dec_size, REPEAT_FALSE))
{
screen->decWindowSize();
screen_->decWindowSize();
}
else if (input->checkInput(input_window_inc_size, REPEAT_FALSE))
else if (input_->checkInput(input_window_inc_size, REPEAT_FALSE))
{
screen->incWindowSize();
screen_->incWindowSize();
}
else if (input->checkInput(input_toggle_palette, REPEAT_FALSE))
else if (input_->checkInput(input_toggle_palette, REPEAT_FALSE))
{
switchPalette();
}
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_jump, REPEAT_FALSE))
else if (input_->checkInput(input_pause, REPEAT_FALSE) || input_->checkInput(input_accept, REPEAT_FALSE) || input_->checkInput(input_jump, REPEAT_FALSE))
{
section->name = SECTION_TITLE;
section->subsection = 0;
section_->name = SECTION_TITLE;
section_->subsection = 0;
}
}
@@ -146,45 +138,45 @@ void LoadingScreen::checkInput()
void LoadingScreen::updateLoad()
{
// Primera parte de la carga, la parte en blanco y negro
if (loadingFirstPart)
if (loading_first_part_)
{
// Cada 5 pasos el loadCounter se incrementa en uno
const int numSteps = 5;
const int step = 51;
loadCounter = counter / numSteps;
load_counter_ = counter_ / numSteps;
if (loadCounter < 192)
if (load_counter_ < 192)
{
loadRect.x = step * (counter % numSteps);
loadRect.y = lineIndex[loadCounter];
sprite1->setSpriteClip(loadRect);
sprite1->setRect(loadRect);
load_rect_.x = step * (counter_ % numSteps);
load_rect_.y = line_index_[load_counter_];
mono_loading_screen_sprite_->setSpriteClip(load_rect_);
mono_loading_screen_sprite_->setRect(load_rect_);
}
// Una vez actualizadas las 192 lineas, pasa a la segunda fase de la carga
else if (loadCounter == 192)
else if (load_counter_ == 192)
{
loadingFirstPart = false;
loadCounter = 0;
loadRect = {0, 0, 16, 8};
sprite2->setRect(loadRect);
sprite2->setSpriteClip(loadRect);
JA_PlayMusic(loadingSound3);
loading_first_part_ = false;
load_counter_ = 0;
load_rect_ = {0, 0, 16, 8};
color_loading_screen_sprite_->setRect(load_rect_);
color_loading_screen_sprite_->setSpriteClip(load_rect_);
JA_PlayMusic(loading_sound3_);
}
}
// Segunda parte de la carga, la parte de los bloques en color
else
{
loadCounter += 2;
loadRect.x = (loadCounter * 8) % 256;
loadRect.y = (loadCounter / 32) * 8;
sprite2->setSpriteClip(loadRect);
sprite2->setRect(loadRect);
load_counter_ += 2;
load_rect_.x = (load_counter_ * 8) % 256;
load_rect_.y = (load_counter_ / 32) * 8;
color_loading_screen_sprite_->setSpriteClip(load_rect_);
color_loading_screen_sprite_->setRect(load_rect_);
// Comprueba si ha terminado la intro
if (loadCounter >= 768)
if (load_counter_ >= 768)
{
section->name = SECTION_TITLE;
section->subsection = SUBSECTION_TITLE_WITH_LOADING_SCREEN;
section_->name = SECTION_TITLE;
section_->subsection = SUBSECTION_TITLE_WITH_LOADING_SCREEN;
JA_StopMusic();
}
}
@@ -193,33 +185,33 @@ void LoadingScreen::updateLoad()
// Gestiona el contador interno
void LoadingScreen::updateCounter()
{
(preCounter >= 50) ? counter++ : preCounter++;
(pre_counter_ >= 50) ? counter_++ : pre_counter_++;
if (counter == 1)
if (counter_ == 1)
{
JA_PlayMusic(loadingSound2);
JA_PlayMusic(loading_sound2_);
}
}
// Dibuja la pantalla de carga
void LoadingScreen::renderLoad()
{
loadingFirstPart ? sprite1->render() : sprite2->render();
loading_first_part_ ? mono_loading_screen_sprite_->render() : color_loading_screen_sprite_->render();
}
// Dibuja el efecto de carga en el borde
void LoadingScreen::renderBorder()
{
// Pinta el borde de colro azul
color_t color = stringToColor(options->palette, "blue");
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer);
color_t color = stringToColor(options_->palette, "blue");
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
SDL_RenderClear(renderer_);
// Añade lineas amarillas
color = stringToColor(options->palette, "yellow");
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF);
const int width = GAMECANVAS_WIDTH + (options->borderWidth * 2);
const int height = GAMECANVAS_HEIGHT + (options->borderHeight * 2);
color = stringToColor(options_->palette, "yellow");
SDL_SetRenderDrawColor(renderer_, color.r, color.g, color.b, 0xFF);
const int width = GAMECANVAS_WIDTH + (options_->borderWidth * 2);
const int height = GAMECANVAS_HEIGHT + (options_->borderHeight * 2);
bool drawEnabled = rand() % 2 == 0 ? true : false;
// Para (int i = 0; i < height; ++i)
//{
@@ -236,7 +228,7 @@ void LoadingScreen::renderBorder()
if (drawEnabled)
for (int i = row; i < row + rowSize; ++i)
{
SDL_RenderDrawLine(renderer, 0, i, width, i);
SDL_RenderDrawLine(renderer_, 0, i, width, i);
}
row += rowSize;
drawEnabled = !drawEnabled;
@@ -247,10 +239,10 @@ void LoadingScreen::renderBorder()
void LoadingScreen::update()
{
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - ticks > ticksSpeed)
if (SDL_GetTicks() - ticks_ > ticks_speed_)
{
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
ticks_ = SDL_GetTicks();
// Comprueba las entradas
checkInput();
@@ -262,30 +254,30 @@ void LoadingScreen::update()
updateLoad();
// Actualiza las notificaciones
screen->updateNotifier();
screen_->updateNotifier();
}
}
// Dibuja en pantalla
void LoadingScreen::render()
{
if (options->borderEnabled)
if (options_->borderEnabled)
{
// Prepara para empezar a dibujar en la textura del borde
screen->startDrawOnBorder();
screen_->startDrawOnBorder();
// Dibuja el efecto de carga en el borde
renderBorder();
}
// Prepara para empezar a dibujar en la textura de juego
screen->start();
screen_->start();
// Dibuja la pantalla de carga
renderLoad();
// Vuelca el contenido del renderizador en pantalla
screen->render();
screen_->render();
}
// Bucle para el logo del juego
@@ -293,14 +285,14 @@ void LoadingScreen::run()
{
// Inicia el sonido de carga
JA_SetVolume(64);
JA_PlayMusic(loadingSound1);
JA_PlayMusic(loading_sound1_);
// Limpia la pantalla
screen->start();
screen->clean();
screen->render();
screen_->start();
screen_->clean();
screen_->render();
while (section->name == SECTION_LOADING_SCREEN)
while (section_->name == SECTION_LOADING_SCREEN)
{
update();
checkEvents();
@@ -313,17 +305,17 @@ void LoadingScreen::run()
// Cambia la paleta
void LoadingScreen::switchPalette()
{
if (options->palette == p_zxspectrum)
if (options_->palette == p_zxspectrum)
{
options->palette = p_zxarne;
sprite1->setTexture(resource->getTexture("loading_screen_bn_zxarne.png"));
sprite2->setTexture(resource->getTexture("loading_screen_color_zxarne.png"));
options_->palette = p_zxarne;
mono_loading_screen_sprite_->setTexture(resource_->getTexture("loading_screen_bn_zxarne.png"));
color_loading_screen_sprite_->setTexture(resource_->getTexture("loading_screen_color_zxarne.png"));
}
else
{
options->palette = p_zxspectrum;
sprite1->setTexture(resource->getTexture("loading_screen_bn.png"));
sprite2->setTexture(resource->getTexture("loading_screen_color.png"));
options_->palette = p_zxspectrum;
mono_loading_screen_sprite_->setTexture(resource_->getTexture("loading_screen_bn.png"));
color_loading_screen_sprite_->setTexture(resource_->getTexture("loading_screen_color.png"));
}
recreateLoadingScreen();
@@ -333,37 +325,37 @@ void LoadingScreen::switchPalette()
void LoadingScreen::recreateLoadingScreen()
{
// Prepara para empezar a dibujar en la textura de juego
screen->start();
screen_->start();
// Primera parte de la carga, la parte en blanco y negro
if (loadingFirstPart)
if (loading_first_part_)
{
const int numSteps = 5;
const int step = 51;
for (int i = 0; i <= counter; i++)
for (int i = 0; i <= counter_; i++)
{
loadCounter = i / numSteps;
loadRect.x = step * (i % numSteps);
loadRect.y = lineIndex[loadCounter];
sprite1->setSpriteClip(loadRect);
sprite1->setRect(loadRect);
sprite1->render();
load_counter_ = i / numSteps;
load_rect_.x = step * (i % numSteps);
load_rect_.y = line_index_[load_counter_];
mono_loading_screen_sprite_->setSpriteClip(load_rect_);
mono_loading_screen_sprite_->setRect(load_rect_);
mono_loading_screen_sprite_->render();
}
}
// Segunda parte de la carga, la parte de los bloques en color
else
{
for (int i = 0; i <= loadCounter; i++)
for (int i = 0; i <= load_counter_; i++)
{
loadRect.x = (i * 8) % 256;
loadRect.y = (i / 32) * 8;
sprite2->setSpriteClip(loadRect);
sprite2->setRect(loadRect);
sprite2->render();
load_rect_.x = (i * 8) % 256;
load_rect_.y = (i / 32) * 8;
color_loading_screen_sprite_->setSpriteClip(load_rect_);
color_loading_screen_sprite_->setRect(load_rect_);
color_loading_screen_sprite_->render();
}
}
// Vuelca el contenido del renderizador en pantalla
screen->render();
screen_->render();
}