Menudo puto lio de renamar coses, a vore si tot va quedant al lloc que els structs i els enums estan revolant i duplicats per tots llocs

This commit is contained in:
2024-10-11 20:12:50 +02:00
parent a9ca23138d
commit 3a6950f3a4
28 changed files with 445 additions and 454 deletions

View File

@@ -12,38 +12,36 @@
#include "options.h" // for options
#include "param.h" // for param
#include "screen.h" // for Screen
#include "section.h" // for options_e, options, name_e, name
#include "section.h" // for SectionOptions, options, SectionName, name
struct JA_Music_t;
// Constructor
Title::Title(JA_Music_t *music)
: music(music)
: music_(music)
{
// Copia las direcciones de los punteros y objetos
input = Input::get();
asset = Asset::get();
screen = Screen::get();
SDL_Renderer *renderer = screen->getRenderer();
input_ = Input::get();
screen_ = Screen::get();
SDL_Renderer *renderer = screen_->getRenderer();
// Reserva memoria y crea los objetos
eventHandler = std::make_unique<SDL_Event>();
fade = std::make_unique<Fade>(renderer);
fade_ = std::make_unique<Fade>(renderer);
text1 = std::make_unique<Text>(asset->get("smb2.gif"), asset->get("smb2.txt"), renderer);
text1->addPalette(asset->get("smb2_pal1.gif"));
text1->setPalette(1);
text2 = std::make_unique<Text>(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer);
text1_ = std::make_unique<Text>(Asset::get()->get("smb2.gif"), Asset::get()->get("smb2.txt"), renderer);
text1_->addPalette(Asset::get()->get("smb2_pal1.gif"));
text1_->setPalette(1);
text2_ = std::make_unique<Text>(Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), renderer);
miniLogoTexture = std::make_shared<Texture>(renderer, asset->get("logo_jailgames_mini.png"));
miniLogoSprite = std::make_unique<Sprite>(param.game.game_area.center_x - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture);
mini_logo_texture_ = std::make_shared<Texture>(renderer, Asset::get()->get("logo_jailgames_mini.png"));
mini_logo_sprite_ = std::make_unique<Sprite>(param.game.game_area.center_x - mini_logo_texture_->getWidth() / 2, 0, mini_logo_texture_->getWidth(), mini_logo_texture_->getHeight(), mini_logo_texture_);
tiledbg = std::make_unique<Tiledbg>(asset->get("title_bg_tile.png"), (SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_RANDOM);
tiled_bg_ = std::make_unique<Tiledbg>(Asset::get()->get("title_bg_tile.png"), (SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_RANDOM);
gameLogo = std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position);
gameLogo->enable();
game_logo_ = std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position);
game_logo_->enable();
defineButtons = std::make_unique<DefineButtons>(std::move(text2));
define_buttons_ = std::make_unique<DefineButtons>(std::move(text2_));
// Inicializa los valores
init();
@@ -53,79 +51,79 @@ Title::Title(JA_Music_t *music)
void Title::init()
{
// Inicializa variables
section::options = section::OPTIONS_TITLE_1;
counter = 0;
nextSection.name = section::NAME_GAME;
postFade = 0;
ticks = 0;
ticksSpeed = 15;
fade->setColor(fade_color.r, fade_color.g, fade_color.b);
fade->setType(FadeType::RANDOM_SQUARE);
fade->setPost(param.fade.post_duration);
demo = true;
numControllers = input->getNumControllers();
section::options = section::Options::TITLE_1;
counter_ = 0;
next_section_ = section::Name::GAME;
post_fade_ = 0;
ticks_ = 0;
ticks_speed_ = 15;
fade_->setColor(fade_color.r, fade_color.g, fade_color.b);
fade_->setType(FadeType::RANDOM_SQUARE);
fade_->setPost(param.fade.post_duration);
demo_ = true;
num_controllers_ = input_->getNumControllers();
}
// Actualiza las variables del objeto
void Title::update()
{
// Calcula la lógica de los objetos
if (SDL_GetTicks() - ticks > ticksSpeed)
if (SDL_GetTicks() - ticks_ > ticks_speed_)
{
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
// Actualiza el contador de ticks_
ticks_ = SDL_GetTicks();
// Actualiza el objeto screen
screen->update();
screen_->update();
// Comprueba el fade y si se ha acabado
fade->update();
if (fade->hasEnded())
// Comprueba el fade_ y si se ha acabado
fade_->update();
if (fade_->hasEnded())
{
if (postFade == -1)
if (post_fade_ == -1)
{
section::name = section::NAME_GAME_DEMO;
section::name = section::Name::GAME_DEMO;
}
else
{
section::name = section::NAME_GAME;
section::options = postFade == 1 ? section::OPTIONS_GAME_PLAY_1P : section::OPTIONS_GAME_PLAY_2P;
section::name = section::Name::GAME;
section::options = post_fade_ == 1 ? section::Options::GAME_PLAY_1P : section::Options::GAME_PLAY_2P;
JA_StopMusic();
}
}
// Sección 1 - Titulo animandose
if (section::options == section::OPTIONS_TITLE_1)
if (section::options == section::Options::TITLE_1)
{
gameLogo->update();
if (gameLogo->hasFinished())
game_logo_->update();
if (game_logo_->hasFinished())
{
section::options = section::OPTIONS_TITLE_2;
section::options = section::Options::TITLE_2;
}
}
// Sección 2 - La pantalla con el titulo, el fondo animado y la música
else if (section::options == section::OPTIONS_TITLE_2)
else if (section::options == section::Options::TITLE_2)
{
// El contador solo sube si no estamos definiendo botones
counter = defineButtons->isEnabled() ? 0 : counter + 1;
counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1;
// Reproduce la música
if ((JA_GetMusicState() == JA_MUSIC_INVALID) || (JA_GetMusicState() == JA_MUSIC_STOPPED))
{
JA_PlayMusic(music);
JA_PlayMusic(music_);
}
// Actualiza el logo con el título del juego
gameLogo->update();
game_logo_->update();
// Actualiza el mosaico de fondo
tiledbg->update();
tiled_bg_->update();
if (counter == param.title.title_duration)
if (counter_ == param.title.title_duration)
{
fade->activate();
postFade = -1;
fade_->activate();
post_fade_ = -1;
}
}
}
@@ -135,83 +133,84 @@ void Title::update()
void Title::render()
{
// Prepara para empezar a dibujar en la textura de juego
screen->start();
screen_->start();
// Limpia la pantalla
screen->clean(bg_color);
screen_->clean(bg_color);
// Dibuja el mosacico de fondo
tiledbg->render();
tiled_bg_->render();
// Dibuja el logo con el título del juego
gameLogo->render();
game_logo_->render();
if (section::options == section::OPTIONS_TITLE_2)
if (section::options == section::Options::TITLE_2)
{
constexpr Color shadow = {0x14, 0x87, 0xc4};
// 'PRESS TO PLAY'
if (counter % 50 > 14 && !defineButtons->isEnabled())
if (counter_ % 50 > 14 && !define_buttons_->isEnabled())
{
text1->writeDX(TXT_CENTER | TXT_SHADOW, param.game.game_area.center_x, param.title.press_start_position, lang::getText(23), 1, no_color, 1, shadow);
text1_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, param.title.press_start_position, lang::getText(23), 1, no_color, 1, shadow);
}
// Mini logo
const int pos1 = (param.game.height / 5 * 4) + BLOCK;
const int pos2 = pos1 + miniLogoSprite->getHeight() + 3;
miniLogoSprite->setPosY(pos1);
miniLogoSprite->render();
const int pos2 = pos1 + mini_logo_sprite_->getHeight() + 3;
mini_logo_sprite_->setPosY(pos1);
mini_logo_sprite_->render();
// Texto con el copyright
text1->writeDX(TXT_CENTER | TXT_SHADOW, param.game.game_area.center_x, pos2, TEXT_COPYRIGHT, 1, no_color, 1, shadow);
text1_->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, pos2, TEXT_COPYRIGHT, 1, no_color, 1, shadow);
}
// Define Buttons
defineButtons->render();
define_buttons_->render();
// Fade
fade->render();
fade_->render();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
screen_->blit();
}
// Comprueba los eventos
void Title::checkEvents()
{
// Si defineButtons está habilitado, es él quien gestiona los eventos
if (!defineButtons->isEnabled())
// Si define_buttons_ está habilitado, es él quien gestiona los eventos
if (!define_buttons_->isEnabled())
{
SDL_Event event;
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(eventHandler.get()) != 0)
while (SDL_PollEvent(&event))
{
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
if (event.type == SDL_QUIT)
{
section::name = section::NAME_QUIT;
section::name = section::Name::QUIT;
break;
}
// Recarga las texturas
else if (eventHandler->type == SDL_RENDER_DEVICE_RESET || eventHandler->type == SDL_RENDER_TARGETS_RESET)
else if (event.type == SDL_RENDER_DEVICE_RESET || event.type == SDL_RENDER_TARGETS_RESET)
{
reLoadTextures();
}
else if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0)
else if (event.type == SDL_KEYDOWN && event.key.repeat == 0)
{
switch (eventHandler->key.keysym.sym)
switch (event.key.keysym.sym)
{
case SDLK_1:
{
if (defineButtons->enable(0))
if (define_buttons_->enable(0))
resetCounter();
break;
}
case SDLK_2:
{
if (defineButtons->enable(1))
if (define_buttons_->enable(1))
resetCounter();
break;
}
@@ -234,45 +233,45 @@ void Title::checkEvents()
void Title::checkInput()
{
// Comprueba los controladores solo si no se estan definiendo los botones
if (!defineButtons->isEnabled())
if (!define_buttons_->isEnabled())
{
// Comprueba el teclado para empezar a jugar
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
if (input_->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{
if (section::options == section::OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
{
fade->activate();
postFade = options.controller[0].player_id;
fade_->activate();
post_fade_ = options.controller[0].player_id;
}
}
// Comprueba los mandos
for (int i = 0; i < input->getNumControllers(); ++i)
for (int i = 0; i < input_->getNumControllers(); ++i)
{
// Comprueba si se va a intercambiar la asignación de mandos a jugadores
if (input->checkModInput(input_service, input_swap_controllers, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
if (input_->checkModInput(input_service, input_swap_controllers, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
swapControllers();
return;
}
// Comprueba si algun mando quiere ser configurado
if (input->checkModInput(input_service, input_config, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
if (input_->checkModInput(input_service, input_config, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
defineButtons->enable(i);
define_buttons_->enable(i);
return;
}
// Comprueba el botón de START de los mandos
if (input->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
if (input_->checkInput(input_start, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
// Si no está el botón de servicio activo
if (!input->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
if (!input_->checkInput(input_service, INPUT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{
if (section::options == section::OPTIONS_TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
if (section::options == section::Options::TITLE_2 || ALLOW_TITLE_ANIMATION_SKIP)
{
fade->activate();
postFade = options.controller[i].player_id;
fade_->activate();
post_fade_ = options.controller[i].player_id;
return;
}
}
@@ -281,8 +280,8 @@ void Title::checkInput()
}
// Comprueba el input para el resto de objetos
screen->checkInput();
defineButtons->checkInput();
screen_->checkInput();
define_buttons_->checkInput();
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
globalInputs::check();
@@ -291,7 +290,7 @@ void Title::checkInput()
// Bucle para el titulo del juego
void Title::run()
{
while (section::name == section::NAME_TITLE)
while (section::name == section::Name::TITLE)
{
checkInput();
update();
@@ -303,27 +302,27 @@ void Title::run()
// Recarga las texturas
void Title::reLoadTextures()
{
gameLogo->reLoad();
tiledbg->reLoad();
game_logo_->reLoad();
tiled_bg_->reLoad();
}
// Reinicia el contador interno
void Title::resetCounter()
{
counter = 0;
counter_ = 0;
}
// Intercambia la asignación de mandos a los jugadores
void Title::swapControllers()
{
const int numControllers = input->getNumControllers();
const int num_controllers_ = input_->getNumControllers();
if (numControllers == 0)
if (num_controllers_ == 0)
{
return;
}
defineButtons->swapControllers();
define_buttons_->swapControllers();
// Crea cadenas de texto vacias para un numero máximo de mandos
constexpr int MAX_CONTROLLERS = 2;
@@ -351,7 +350,7 @@ void Title::swapControllers()
}
}
screen->showNotification(text[0], text[1]);
screen_->showNotification(text[0], text[1]);
resetCounter();
}