pasaeta loca de clang-format (despres m'arrepentiré pero bueno)

This commit is contained in:
2025-07-18 20:01:13 +02:00
parent 734c220fb0
commit dabba41179
112 changed files with 22361 additions and 26474 deletions

View File

@@ -1,7 +1,8 @@
// IWYU pragma: no_include <bits/std_abs.h>
#include "credits.h"
#include <SDL3/SDL.h> // Para SDL_RenderFillRect, SDL_RenderTexture
#include <SDL3/SDL.h> // Para SDL_RenderFillRect, SDL_RenderTexture
#include <algorithm> // Para max, min, clamp
#include <array> // Para array
#include <cmath> // Para abs
@@ -9,24 +10,24 @@
#include <string> // Para basic_string, string
#include <vector> // Para vector
#include "audio.h" // Para Audio
#include "balloon_manager.h" // Para BalloonManager
#include "fade.h" // Para Fade, FadeType, FadeMode
#include "global_events.h" // Para check
#include "global_inputs.h" // Para check
#include "input.h" // Para Input, INPUT_ALLOW_REPEAT
#include "lang.h" // Para getText
#include "param.h" // Para Param, param, ParamGame, ParamFade
#include "player.h" // Para Player, PlayerState
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name
#include "sprite.h" // Para Sprite
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
#include "texture.h" // Para Texture
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
#include "ui/service_menu.h" // Para ServiceMenu
#include "utils.h" // Para Color, Zone, SHADOW_TEXT_COLOR, NO_TEXT...
#include "audio.h" // Para Audio
#include "balloon_manager.h" // Para BalloonManager
#include "fade.h" // Para Fade, FadeType, FadeMode
#include "global_events.h" // Para check
#include "global_inputs.h" // Para check
#include "input.h" // Para Input, INPUT_ALLOW_REPEAT
#include "lang.h" // Para getText
#include "param.h" // Para Param, param, ParamGame, ParamFade
#include "player.h" // Para Player, PlayerState
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name
#include "sprite.h" // Para Sprite
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
#include "texture.h" // Para Texture
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
#include "ui/service_menu.h" // Para ServiceMenu
#include "utils.h" // Para Color, Zone, SHADOW_TEXT_COLOR, NO_TEXT...
// Textos
constexpr const char TEXT_COPYRIGHT[] = "@2020,2025 JailDesigner";
@@ -38,10 +39,8 @@ Credits::Credits()
fade_in_(std::make_unique<Fade>()),
fade_out_(std::make_unique<Fade>()),
text_texture_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
canvas_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height))
{
if (!text_texture_)
{
canvas_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)) {
if (!text_texture_) {
throw std::runtime_error("Failed to create SDL texture for text.");
}
Section::name = Section::Name::CREDITS;
@@ -67,8 +66,7 @@ Credits::Credits()
}
// Destructor
Credits::~Credits()
{
Credits::~Credits() {
SDL_DestroyTexture(text_texture_);
SDL_DestroyTexture(canvas_);
resetVolume();
@@ -76,26 +74,21 @@ Credits::~Credits()
}
// Bucle principal
void Credits::run()
{
while (Section::name == Section::Name::CREDITS)
{
void Credits::run() {
while (Section::name == Section::Name::CREDITS) {
checkInput();
update();
checkEvents(); // Tiene que ir antes del render
checkEvents(); // Tiene que ir antes del render
render();
}
}
// Actualiza las variables
void Credits::update()
{
if (SDL_GetTicks() - ticks_ > param.game.speed)
{
void Credits::update() {
if (SDL_GetTicks() - ticks_ > param.game.speed) {
ticks_ = SDL_GetTicks();
const int REPEAT = want_to_pass_ ? 4 : 1;
for (int i = 0; i < REPEAT; ++i)
{
for (int i = 0; i < REPEAT; ++i) {
tiled_bg_->update();
cycleColors();
balloon_manager_->update();
@@ -113,8 +106,7 @@ void Credits::update()
}
// Dibuja Credits::en patalla
void Credits::render()
{
void Credits::render() {
// Prepara para empezar a dibujar en la textura de juego
Screen::get()->start();
@@ -126,30 +118,23 @@ void Credits::render()
}
// Comprueba el manejador de eventos
void Credits::checkEvents()
{
void Credits::checkEvents() {
SDL_Event event;
while (SDL_PollEvent(&event))
{
while (SDL_PollEvent(&event)) {
GlobalEvents::check(event);
}
}
// Comprueba las entradas
void Credits::checkInput()
{
void Credits::checkInput() {
Input::get()->update();
if (!ServiceMenu::get()->isEnabled())
{
if (!ServiceMenu::get()->isEnabled()) {
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
if (Input::get()->checkAnyButton(INPUT_ALLOW_REPEAT))
{
if (Input::get()->checkAnyButton(INPUT_ALLOW_REPEAT)) {
want_to_pass_ = true;
fading_ = mini_logo_on_position_;
}
else
{
} else {
want_to_pass_ = false;
}
}
@@ -159,8 +144,7 @@ void Credits::checkInput()
}
// Crea la textura con el texto
void Credits::fillTextTexture()
{
void Credits::fillTextTexture() {
auto text = Resource::get()->getText("smb2");
auto text_grad = Resource::get()->getText("smb2_grad");
SDL_SetRenderTarget(Screen::get()->getRenderer(), text_texture_);
@@ -248,8 +232,7 @@ void Credits::fillTextTexture()
}
// Dibuja todos los sprites en la textura
void Credits::fillCanvas()
{
void Credits::fillCanvas() {
// Cambia el destino del renderizador
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
SDL_SetRenderTarget(Screen::get()->getRenderer(), canvas_);
@@ -279,8 +262,7 @@ void Credits::fillCanvas()
SDL_RenderRect(Screen::get()->getRenderer(), &red_rect);
// Si el mini_logo está en su destino, lo dibuja encima de lo anterior
if (mini_logo_on_position_)
{
if (mini_logo_on_position_) {
SDL_RenderTexture(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_);
}
@@ -293,72 +275,57 @@ void Credits::fillCanvas()
}
// Actualiza el destino de los rectangulos de las texturas
void Credits::updateTextureDstRects()
{
if (counter_ % 10 == 0)
{
void Credits::updateTextureDstRects() {
if (counter_ % 10 == 0) {
// Comprueba la posición de la textura con los titulos de credito
if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y)
{
if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y) {
--credits_rect_dst_.y;
}
// Comprueba la posición de la textura con el mini_logo
if (mini_logo_rect_dst_.y == mini_logo_final_pos_)
{
if (mini_logo_rect_dst_.y == mini_logo_final_pos_) {
mini_logo_on_position_ = true;
// Si el jugador quiere pasar los titulos de credito, el fade se inicia solo
if (want_to_pass_)
{
if (want_to_pass_) {
fading_ = true;
}
// Se activa el contador para evitar que la sección sea infinita
if (counter_prevent_endless_ == 1000)
{
if (counter_prevent_endless_ == 1000) {
fading_ = true;
}
else
{
} else {
++counter_prevent_endless_;
}
}
else
{
} else {
--mini_logo_rect_dst_.y;
}
}
}
// Tira globos al escenario
void Credits::throwBalloons()
{
void Credits::throwBalloons() {
constexpr int speed = 200;
const std::vector<int> sets = {0, 63, 25, 67, 17, 75, 13, 50};
if (counter_ > ((sets.size() - 1) * speed) * 3)
{
if (counter_ > ((sets.size() - 1) * speed) * 3) {
return;
}
if (counter_ % speed == 0)
{
if (counter_ % speed == 0) {
const int index = (counter_ / speed) % sets.size();
balloon_manager_->deploySet(sets.at(index), -60);
}
if (counter_ % (speed * 4) == 0 && counter_ > 0)
{
if (counter_ % (speed * 4) == 0 && counter_ > 0) {
balloon_manager_->createPowerBall();
}
}
// Inicializa los jugadores
void Credits::initPlayers()
{
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures; // Vector con todas las texturas de los jugadores;
std::vector<std::vector<std::string>> player_animations; // Vector con las animaciones del jugador
void Credits::initPlayers() {
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures; // Vector con todas las texturas de los jugadores;
std::vector<std::vector<std::string>> player_animations; // Vector con las animaciones del jugador
// Texturas - Player1
{
@@ -397,14 +364,11 @@ void Credits::initPlayers()
}
// Actualiza los rectangulos negros
void Credits::updateBlackRects()
{
void Credits::updateBlackRects() {
static int current_step = steps_;
if (top_black_rect_.h != param.game.game_area.center_y - 1 && bottom_black_rect_.y != param.game.game_area.center_y + 1)
{
if (top_black_rect_.h != param.game.game_area.center_y - 1 && bottom_black_rect_.y != param.game.game_area.center_y + 1) {
// Si los rectangulos superior e inferior no han llegado al centro
if (counter_ % 4 == 0)
{
if (counter_ % 4 == 0) {
// Incrementa la altura del rectangulo superior
top_black_rect_.h = std::min(top_black_rect_.h + 1, param.game.game_area.center_y - 1);
@@ -415,12 +379,9 @@ void Credits::updateBlackRects()
--current_step;
setVolume(static_cast<int>(initial_volume_ * current_step / steps_));
}
}
else
{
} else {
// Si los rectangulos superior e inferior han llegado al centro
if (left_black_rect_.w != param.game.game_area.center_x && right_black_rect_.x != param.game.game_area.center_x)
{
if (left_black_rect_.w != param.game.game_area.center_x && right_black_rect_.x != param.game.game_area.center_x) {
constexpr int SPEED = 2;
// Si los rectangulos izquierdo y derecho no han llegado al centro
// Incrementa la anchura del rectangulo situado a la izquierda
@@ -432,18 +393,13 @@ void Credits::updateBlackRects()
--current_step;
setVolume(static_cast<int>(initial_volume_ * current_step / steps_));
}
else
{
} else {
// Si los rectangulos izquierdo y derecho han llegado al centro
setVolume(0);
Audio::get()->stopMusic();
if (counter_pre_fade_ == 400)
{
if (counter_pre_fade_ == 400) {
fade_out_->activate();
}
else
{
} else {
++counter_pre_fade_;
}
}
@@ -451,8 +407,7 @@ void Credits::updateBlackRects()
}
// Actualiza el rectangulo rojo
void Credits::updateRedRect()
{
void Credits::updateRedRect() {
red_rect.x = left_black_rect_.x + left_black_rect_.w;
red_rect.y = top_black_rect_.y + top_black_rect_.h - 1;
red_rect.w = right_black_rect_.x - red_rect.x;
@@ -460,76 +415,66 @@ void Credits::updateRedRect()
}
// Actualiza el estado de fade
void Credits::updateAllFades()
{
if (fading_)
{
void Credits::updateAllFades() {
if (fading_) {
updateBlackRects();
updateRedRect();
}
fade_in_->update();
if (fade_in_->hasEnded())
{
if (fade_in_->hasEnded()) {
Audio::get()->playMusic("credits.ogg");
}
fade_out_->update();
if (fade_out_->hasEnded())
{
if (fade_out_->hasEnded()) {
Section::name = Section::Name::HI_SCORE_TABLE;
}
}
// Establece el nivel de volumen
void Credits::setVolume(int amount)
{
void Credits::setVolume(int amount) {
Options::audio.music.volume = std::clamp(amount, 0, 100);
Audio::get()->setMusicVolume(Options::audio.music.volume);
}
// Reestablece el nivel de volumen
void Credits::resetVolume()
{
void Credits::resetVolume() {
Options::audio.music.volume = initial_volume_;
Audio::get()->setMusicVolume(Options::audio.music.volume);
}
// Cambia el color del fondo
void Credits::cycleColors()
{
void Credits::cycleColors() {
// constexpr int UPPER_LIMIT = 255; // Límite superior
// constexpr int LOWER_LIMIT = 80; // Límite inferior
constexpr int UPPER_LIMIT = 140; // Límite superior
constexpr int LOWER_LIMIT = 30; // Límite inferior
constexpr int UPPER_LIMIT = 140; // Límite superior
constexpr int LOWER_LIMIT = 30; // Límite inferior
static float r = static_cast<float>(UPPER_LIMIT);
static float g = static_cast<float>(LOWER_LIMIT);
static float b = static_cast<float>(LOWER_LIMIT);
static float stepR = -0.5f; // Paso flotante para transiciones suaves
static float stepR = -0.5f; // Paso flotante para transiciones suaves
static float stepG = 0.3f;
static float stepB = 0.1f;
// Ajustar valores de R
r += stepR;
if (r >= UPPER_LIMIT || r <= LOWER_LIMIT)
{
stepR = -stepR; // Cambia de dirección al alcanzar los límites
if (r >= UPPER_LIMIT || r <= LOWER_LIMIT) {
stepR = -stepR; // Cambia de dirección al alcanzar los límites
}
// Ajustar valores de G
g += stepG;
if (g >= UPPER_LIMIT || g <= LOWER_LIMIT)
{
stepG = -stepG; // Cambia de dirección al alcanzar los límites
if (g >= UPPER_LIMIT || g <= LOWER_LIMIT) {
stepG = -stepG; // Cambia de dirección al alcanzar los límites
}
// Ajustar valores de B
b += stepB;
if (b >= UPPER_LIMIT || b <= LOWER_LIMIT)
{
stepB = -stepB; // Cambia de dirección al alcanzar los límites
if (b >= UPPER_LIMIT || b <= LOWER_LIMIT) {
stepB = -stepB; // Cambia de dirección al alcanzar los límites
}
// Aplicar el color, redondeando a enteros antes de usar
@@ -538,19 +483,15 @@ void Credits::cycleColors()
}
// Actualza los jugadores
void Credits::updatePlayers()
{
for (auto &player : players_)
{
void Credits::updatePlayers() {
for (auto &player : players_) {
player->update();
}
}
// Renderiza los jugadores
void Credits::renderPlayers()
{
for (auto const &player : players_)
{
void Credits::renderPlayers() {
for (auto const &player : players_) {
player->render();
}
}

View File

@@ -1,12 +1,13 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_FRect, Uint32, SDL_Texture, Uint64
#include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector
#include <SDL3/SDL.h> // Para SDL_FRect, Uint32, SDL_Texture, Uint64
#include "options.h" // Para AudioOptions, MusicOptions, audio
#include "param.h" // Para Param, ParamGame, param
#include "utils.h" // Para Zone, Color
#include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector
#include "options.h" // Para AudioOptions, MusicOptions, audio
#include "param.h" // Para Param, ParamGame, param
#include "utils.h" // Para Zone, Color
// Declaraciones adelantadas
class BalloonManager;
@@ -14,9 +15,8 @@ class Fade;
class Player;
class TiledBG;
class Credits
{
public:
class Credits {
public:
// --- Constructores y destructor ---
Credits();
~Credits();
@@ -24,40 +24,40 @@ public:
// --- Bucle principal ---
void run();
private:
private:
// --- Constantes de clase ---
static constexpr int PLAY_AREA_HEIGHT = 200;
// --- Objetos principales ---
std::unique_ptr<BalloonManager> balloon_manager_; // Gestión de globos
std::unique_ptr<TiledBG> tiled_bg_; // Mosaico animado de fondo
std::unique_ptr<Fade> fade_in_; // Fundido de entrada
std::unique_ptr<Fade> fade_out_; // Fundido de salida
std::vector<std::shared_ptr<Player>> players_; // Vector de jugadores
std::unique_ptr<BalloonManager> balloon_manager_; // Gestión de globos
std::unique_ptr<TiledBG> tiled_bg_; // Mosaico animado de fondo
std::unique_ptr<Fade> fade_in_; // Fundido de entrada
std::unique_ptr<Fade> fade_out_; // Fundido de salida
std::vector<std::shared_ptr<Player>> players_; // Vector de jugadores
// --- Gestión de texturas ---
SDL_Texture *text_texture_; // Textura con el texto de créditos
SDL_Texture *canvas_; // Textura donde se dibuja todo
SDL_Texture *text_texture_; // Textura con el texto de créditos
SDL_Texture *canvas_; // Textura donde se dibuja todo
// --- Temporización y contadores ---
Uint64 ticks_ = 0; // Control de velocidad del programa
Uint32 counter_ = 0; // Contador principal de lógica
Uint32 counter_pre_fade_ = 0; // Activación del fundido final
Uint32 counter_prevent_endless_ = 0; // Prevención de bucle infinito
Uint64 ticks_ = 0; // Control de velocidad del programa
Uint32 counter_ = 0; // Contador principal de lógica
Uint32 counter_pre_fade_ = 0; // Activación del fundido final
Uint32 counter_prevent_endless_ = 0; // Prevención de bucle infinito
// --- Variables de estado ---
bool fading_ = false; // Estado del fade final
bool want_to_pass_ = false; // Jugador quiere saltarse créditos
bool mini_logo_on_position_ = false; // Minilogo en posición final
bool fading_ = false; // Estado del fade final
bool want_to_pass_ = false; // Jugador quiere saltarse créditos
bool mini_logo_on_position_ = false; // Minilogo en posición final
// --- Diseño y posicionamiento ---
float black_bars_size_ = (param.game.game_area.rect.h - PLAY_AREA_HEIGHT) / 2; // Tamaño de las barras negras
int mini_logo_final_pos_ = 0; // Posición final del minilogo
Color color_; // Color usado para los efectos
float black_bars_size_ = (param.game.game_area.rect.h - PLAY_AREA_HEIGHT) / 2; // Tamaño de las barras negras
int mini_logo_final_pos_ = 0; // Posición final del minilogo
Color color_; // Color usado para los efectos
// --- Control de audio ---
int initial_volume_ = Options::audio.music.volume; // Volumen inicial
int steps_ = 0; // Pasos para reducir audio
int initial_volume_ = Options::audio.music.volume; // Volumen inicial
int steps_ = 0; // Pasos para reducir audio
// --- Rectángulos de renderizado ---
// Texto de créditos
@@ -98,32 +98,32 @@ private:
2};
// Borde para la ventana
SDL_FRect red_rect = play_area_; // Delimitador de ventana
SDL_FRect red_rect = play_area_; // Delimitador de ventana
// --- Métodos del bucle principal ---
void update(); // Actualización principal de la lógica
void render(); // Renderizado de la escena
void checkEvents(); // Manejo de eventos
void checkInput(); // Procesamiento de entrada
void update(); // Actualización principal de la lógica
void render(); // Renderizado de la escena
void checkEvents(); // Manejo de eventos
void checkInput(); // Procesamiento de entrada
// --- Métodos de renderizado ---
void fillTextTexture(); // Crear textura de texto de créditos
void fillCanvas(); // Renderizar todos los sprites y fondos
void updateTextureDstRects(); // Actualizar destinos de texturas
void renderPlayers(); // Renderiza los jugadores
void fillTextTexture(); // Crear textura de texto de créditos
void fillCanvas(); // Renderizar todos los sprites y fondos
void updateTextureDstRects(); // Actualizar destinos de texturas
void renderPlayers(); // Renderiza los jugadores
// --- Métodos de lógica del juego ---
void throwBalloons(); // Lanzar globos al escenario
void initPlayers(); // Inicializar jugadores
void updateAllFades(); // Actualizar estados de fade
void cycleColors(); // Cambiar colores de fondo
void updatePlayers(); // Actualza los jugadores
void throwBalloons(); // Lanzar globos al escenario
void initPlayers(); // Inicializar jugadores
void updateAllFades(); // Actualizar estados de fade
void cycleColors(); // Cambiar colores de fondo
void updatePlayers(); // Actualza los jugadores
// --- Métodos de interfaz ---
void updateBlackRects(); // Actualizar rectángulos negros (letterbox)
void updateRedRect(); // Actualizar rectángulo rojo (borde)
void updateBlackRects(); // Actualizar rectángulos negros (letterbox)
void updateRedRect(); // Actualizar rectángulo rojo (borde)
// --- Métodos de audio ---
void setVolume(int amount); // Establecer volumen
void resetVolume(); // Restablecer volumen
void setVolume(int amount); // Establecer volumen
void resetVolume(); // Restablecer volumen
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +1,15 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_Event, SDL_Renderer, SDL_Texture, Uint64, Uint8
#include <memory> // Para shared_ptr, unique_ptr
#include <string> // Para string
#include <vector> // Para vector
#include <SDL3/SDL.h> // Para SDL_Event, SDL_Renderer, SDL_Texture, Uint64, Uint8
#include "manage_hiscore_table.h" // Para HiScoreEntry
#include "options.h" // Para SettingsOptions, settings, DifficultyCode (ptr only)
#include "player.h" // Para Player
#include "utils.h" // Para Demo
#include <memory> // Para shared_ptr, unique_ptr
#include <string> // Para string
#include <vector> // Para vector
#include "manage_hiscore_table.h" // Para HiScoreEntry
#include "options.h" // Para SettingsOptions, settings, DifficultyCode (ptr only)
#include "player.h" // Para Player
#include "utils.h" // Para Demo
class Background;
class Balloon;
@@ -35,216 +36,213 @@ constexpr bool GAME_MODE_DEMO_ON = true;
constexpr int TOTAL_SCORE_DATA = 3;
// Clase Game
class Game
{
public:
// Constructor
Game(int playerID, int current_stage, bool demo);
class Game {
public:
// Constructor
Game(int playerID, int current_stage, bool demo);
// Destructor
~Game();
// Destructor
~Game();
// Bucle principal del juego
void run();
// Bucle principal del juego
void run();
private:
// --- Tipos internos ---
enum class GameState
{
FADE_IN,
ENTERING_PLAYER,
SHOWING_GET_READY_MESSAGE,
PLAYING,
COMPLETED,
GAME_OVER,
};
private:
// --- Tipos internos ---
enum class GameState {
FADE_IN,
ENTERING_PLAYER,
SHOWING_GET_READY_MESSAGE,
PLAYING,
COMPLETED,
GAME_OVER,
};
// --- Constantes internas ---
static constexpr int HELP_COUNTER_ = 1000;
static constexpr int GAME_COMPLETED_START_FADE_ = 500;
static constexpr int GAME_COMPLETED_END_ = 700;
static constexpr int GAME_OVER_COUNTER_ = 350;
static constexpr int TIME_STOPPED_COUNTER_ = 360;
static constexpr int ITEM_POINTS_1_DISK_ODDS_ = 10;
static constexpr int ITEM_POINTS_2_GAVINA_ODDS_ = 6;
static constexpr int ITEM_POINTS_3_PACMAR_ODDS_ = 3;
static constexpr int ITEM_CLOCK_ODDS_ = 5;
static constexpr int ITEM_COFFEE_ODDS_ = 5;
static constexpr int ITEM_POWER_BALL_ODDS_ = 0;
static constexpr int ITEM_COFFEE_MACHINE_ODDS_ = 4;
// --- Constantes internas ---
static constexpr int HELP_COUNTER_ = 1000;
static constexpr int GAME_COMPLETED_START_FADE_ = 500;
static constexpr int GAME_COMPLETED_END_ = 700;
static constexpr int GAME_OVER_COUNTER_ = 350;
static constexpr int TIME_STOPPED_COUNTER_ = 360;
static constexpr int ITEM_POINTS_1_DISK_ODDS_ = 10;
static constexpr int ITEM_POINTS_2_GAVINA_ODDS_ = 6;
static constexpr int ITEM_POINTS_3_PACMAR_ODDS_ = 3;
static constexpr int ITEM_CLOCK_ODDS_ = 5;
static constexpr int ITEM_COFFEE_ODDS_ = 5;
static constexpr int ITEM_POWER_BALL_ODDS_ = 0;
static constexpr int ITEM_COFFEE_MACHINE_ODDS_ = 4;
// --- Estructuras ---
struct Helper
{
bool need_coffee; // Indica si se necesitan cafes
bool need_coffee_machine; // Indica si se necesita PowerUp
bool need_power_ball; // Indica si se necesita una PowerBall
int counter; // Contador para no dar ayudas consecutivas
int item_disk_odds; // Probabilidad de aparición del objeto
int item_gavina_odds; // Probabilidad de aparición del objeto
int item_pacmar_odds; // Probabilidad de aparición del objeto
int item_clock_odds; // Probabilidad de aparición del objeto
int item_coffee_odds; // Probabilidad de aparición del objeto
int item_coffee_machine_odds; // Probabilidad de aparición del objeto
// --- Estructuras ---
struct Helper {
bool need_coffee; // Indica si se necesitan cafes
bool need_coffee_machine; // Indica si se necesita PowerUp
bool need_power_ball; // Indica si se necesita una PowerBall
int counter; // Contador para no dar ayudas consecutivas
int item_disk_odds; // Probabilidad de aparición del objeto
int item_gavina_odds; // Probabilidad de aparición del objeto
int item_pacmar_odds; // Probabilidad de aparición del objeto
int item_clock_odds; // Probabilidad de aparición del objeto
int item_coffee_odds; // Probabilidad de aparición del objeto
int item_coffee_machine_odds; // Probabilidad de aparición del objeto
Helper()
: need_coffee(false),
need_coffee_machine(false),
need_power_ball(false),
counter(HELP_COUNTER_),
item_disk_odds(ITEM_POINTS_1_DISK_ODDS_),
item_gavina_odds(ITEM_POINTS_2_GAVINA_ODDS_),
item_pacmar_odds(ITEM_POINTS_3_PACMAR_ODDS_),
item_clock_odds(ITEM_CLOCK_ODDS_),
item_coffee_odds(ITEM_COFFEE_ODDS_),
item_coffee_machine_odds(ITEM_COFFEE_MACHINE_ODDS_) {}
};
Helper()
: need_coffee(false),
need_coffee_machine(false),
need_power_ball(false),
counter(HELP_COUNTER_),
item_disk_odds(ITEM_POINTS_1_DISK_ODDS_),
item_gavina_odds(ITEM_POINTS_2_GAVINA_ODDS_),
item_pacmar_odds(ITEM_POINTS_3_PACMAR_ODDS_),
item_clock_odds(ITEM_CLOCK_ODDS_),
item_coffee_odds(ITEM_COFFEE_ODDS_),
item_coffee_machine_odds(ITEM_COFFEE_MACHINE_ODDS_) {}
};
// --- Objetos y punteros ---
SDL_Renderer *renderer_; // El renderizador de la ventana
Screen *screen_; // Objeto encargado de dibujar en pantalla
Input *input_; // Manejador de entrada
Scoreboard *scoreboard_; // Objeto para dibujar el marcador
// --- Objetos y punteros ---
SDL_Renderer *renderer_; // El renderizador de la ventana
Screen *screen_; // Objeto encargado de dibujar en pantalla
Input *input_; // Manejador de entrada
Scoreboard *scoreboard_; // Objeto para dibujar el marcador
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
SDL_Texture *canvas_; // Textura para dibujar la zona de juego
SDL_Texture *canvas_; // Textura para dibujar la zona de juego
std::vector<std::shared_ptr<Player>> players_; // Vector con los jugadores
std::vector<std::unique_ptr<Bullet>> bullets_; // Vector con las balas
std::vector<std::unique_ptr<Item>> items_; // Vector con los items
std::vector<std::unique_ptr<SmartSprite>> smart_sprites_; // Vector con los smartsprites
std::vector<std::unique_ptr<PathSprite>> path_sprites_; // Vector con los pathsprites
std::vector<std::shared_ptr<Player>> players_; // Vector con los jugadores
std::vector<std::unique_ptr<Bullet>> bullets_; // Vector con las balas
std::vector<std::unique_ptr<Item>> items_; // Vector con los items
std::vector<std::unique_ptr<SmartSprite>> smart_sprites_; // Vector con los smartsprites
std::vector<std::unique_ptr<PathSprite>> path_sprites_; // Vector con los pathsprites
std::vector<std::shared_ptr<Texture>> item_textures_; // Vector con las texturas de los items
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures_; // Vector con todas las texturas de los jugadores
std::vector<std::shared_ptr<Texture>> item_textures_; // Vector con las texturas de los items
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures_; // Vector con todas las texturas de los jugadores
std::vector<std::shared_ptr<Texture>> game_text_textures_; // Vector con las texturas para los sprites con textos
std::vector<std::shared_ptr<Texture>> game_text_textures_; // Vector con las texturas para los sprites con textos
std::vector<std::vector<std::string>> item_animations_; // Vector con las animaciones de los items
std::vector<std::vector<std::string>> player_animations_; // Vector con las animaciones del jugador
std::vector<std::vector<std::string>> item_animations_; // Vector con las animaciones de los items
std::vector<std::vector<std::string>> player_animations_; // Vector con las animaciones del jugador
std::unique_ptr<Fade> fade_in_; // Objeto para renderizar fades
std::unique_ptr<Fade> fade_out_; // Objeto para renderizar fades
std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos
std::unique_ptr<Tabe> tabe_; // Objeto para gestionar el Tabe Volaor
std::vector<Path> paths_; // Vector con los recorridos precalculados almacenados
std::unique_ptr<Fade> fade_in_; // Objeto para renderizar fades
std::unique_ptr<Fade> fade_out_; // Objeto para renderizar fades
std::unique_ptr<BalloonManager> balloon_manager_; // Objeto para gestionar los globos
std::unique_ptr<Tabe> tabe_; // Objeto para gestionar el Tabe Volaor
std::vector<Path> paths_; // Vector con los recorridos precalculados almacenados
// --- Variables de estado ---
HiScoreEntry hi_score_ = HiScoreEntry(
Options::settings.hi_score_table[0].name,
Options::settings.hi_score_table[0].score); // Máxima puntuación y nombre de quien la ostenta
// --- Variables de estado ---
HiScoreEntry hi_score_ = HiScoreEntry(
Options::settings.hi_score_table[0].name,
Options::settings.hi_score_table[0].score); // Máxima puntuación y nombre de quien la ostenta
Demo demo_; // Variable con todas las variables relacionadas con el modo demo
Options::DifficultyCode difficulty_ = Options::settings.difficulty; // Dificultad del juego
Helper helper_; // Variable para gestionar las ayudas
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
bool coffee_machine_enabled_ = false; // Indica si hay una máquina de café en el terreno de juego
bool hi_score_achieved_ = false; // Indica si se ha superado la puntuación máxima
bool paused_ = false; // Indica si el juego está pausado (no se deberia de poder utilizar en el modo arcade)
// bool paused_by_service_menu_ = false;
float difficulty_score_multiplier_; // Multiplicador de puntos en función de la dificultad
int counter_ = 0; // Contador para el juego
int game_completed_counter_ = 0; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos
int game_over_counter_ = GAME_OVER_COUNTER_; // Contador para el estado de fin de partida
int time_stopped_counter_ = 0; // Temporizador para llevar la cuenta del tiempo detenido
int total_power_to_complete_game_; // La suma del poder necesario para completar todas las fases
int menace_current_ = 0; // Nivel de amenaza actual
int menace_threshold_ = 0; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos
GameState state_ = GameState::FADE_IN; // Estado
std::vector<std::shared_ptr<Player>> players_to_reorder;
Demo demo_; // Variable con todas las variables relacionadas con el modo demo
Options::DifficultyCode difficulty_ = Options::settings.difficulty; // Dificultad del juego
Helper helper_; // Variable para gestionar las ayudas
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
bool coffee_machine_enabled_ = false; // Indica si hay una máquina de café en el terreno de juego
bool hi_score_achieved_ = false; // Indica si se ha superado la puntuación máxima
bool paused_ = false; // Indica si el juego está pausado (no se deberia de poder utilizar en el modo arcade)
// bool paused_by_service_menu_ = false;
float difficulty_score_multiplier_; // Multiplicador de puntos en función de la dificultad
int counter_ = 0; // Contador para el juego
int game_completed_counter_ = 0; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos
int game_over_counter_ = GAME_OVER_COUNTER_; // Contador para el estado de fin de partida
int time_stopped_counter_ = 0; // Temporizador para llevar la cuenta del tiempo detenido
int total_power_to_complete_game_; // La suma del poder necesario para completar todas las fases
int menace_current_ = 0; // Nivel de amenaza actual
int menace_threshold_ = 0; // Umbral del nivel de amenaza. Si el nivel de amenaza cae por debajo del umbral, se generan más globos. Si el umbral aumenta, aumenta el número de globos
GameState state_ = GameState::FADE_IN; // Estado
std::vector<std::shared_ptr<Player>> players_to_reorder;
#ifdef DEBUG
bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados
bool auto_pop_balloons_ = false; // Si es true, incrementa automaticamente los globos explotados
// Comprueba los eventos en el modo DEBUG
void checkDebugEvents(const SDL_Event &event);
// Comprueba los eventos en el modo DEBUG
void checkDebugEvents(const SDL_Event &event);
#endif
// --- Métodos internos ---
void update(); // Actualiza el juego
void render(); // Dibuja el juego
void checkEvents(); // Comprueba los eventos que hay en cola
void setResources(); // Asigna texturas y animaciones
void updateHiScore(); // Actualiza el valor de HiScore en caso necesario
void updatePlayers(); // Actualiza las variables del jugador
void renderPlayers(); // Dibuja a los jugadores
void updateStage(); // Comprueba si hay cambio de fase y actualiza las variables
void updateGameStateGameOver(); // Actualiza el estado de fin de la partida
void destroyAllItems(); // Destruye todos los items
std::shared_ptr<Balloon> checkPlayerBalloonCollision(std::shared_ptr<Player> &player); // Comprueba la colisión entre el jugador y los globos activos
void checkPlayerItemCollision(std::shared_ptr<Player> &player); // Comprueba la colisión entre el jugador y los items
void checkBulletCollision(); // Comprueba y procesa la colisión de las balas
void updateBullets(); // Mueve las balas activas
void renderBullets(); // Pinta las balas activas
void createBullet(int x, int y, BulletType kind, bool powered_up, int owner); // Crea un objeto bala
void freeBullets(); // Vacia el vector de balas
void updateItems(); // Actualiza los items
void renderItems(); // Pinta los items activos
ItemType dropItem(); // Devuelve un item en función del azar
void createItem(ItemType type, float x, float y); // Crea un objeto item
void freeItems(); // Vacia el vector de items
void createItemText(int x, std::shared_ptr<Texture> texture); // Crea un objeto PathSprite
void createMessage(const std::vector<Path> &paths, std::shared_ptr<Texture> texture); // Crea un objeto PathSprite
void freeSmartSprites(); // Vacia el vector de smartsprites
void freePathSprites(); // Vacia el vector de pathsprites
void throwCoffee(int x, int y); // Crea un SpriteSmart para arrojar el item café al recibir un impacto
void updateSmartSprites(); // Actualiza los SpriteSmarts
void renderSmartSprites(); // Pinta los SpriteSmarts activos
void updatePathSprites(); // Actualiza los PathSprites
void renderPathSprites(); // Pinta los PathSprites activos
void handlePlayerCollision(std::shared_ptr<Player> &player); // Acciones a realizar cuando el jugador colisiona con un globo
void updateTimeStopped(); // Actualiza y comprueba el valor de la variable
void updateBackground(); // Actualiza el fondo
void initPaths(); // Inicializa las variables que contienen puntos de ruta para mover objetos
void enableTimeStopItem(); // Habilita el efecto del item de detener el tiempo
void disableTimeStopItem(); // Deshabilita el efecto del item de detener el tiempo
void updateHelper(); // Actualiza las variables de ayuda
bool allPlayersAreWaitingOrGameOver(); // Comprueba si todos los jugadores han terminado de jugar
bool allPlayersAreGameOver(); // Comprueba si todos los jugadores han terminado de jugar
bool allPlayersAreNotPlaying(); // Comprueba si todos los jugadores han terminado de jugar
void updateScoreboard(); // Actualiza el marcador
void fillCanvas(); // Dibuja los elementos de la zona de juego en su textura
void pause(bool value); // Pausa el juego
void addScoreToScoreBoard(const std::shared_ptr<Player> &player); // Añade una puntuación a la tabla de records
void checkAndUpdatePlayerStatus(int active_player_index, int inactive_player_index); // Saca del estado de GAME OVER al jugador si el otro está activo
void checkPlayersStatusPlaying(); // Comprueba el estado de juego de los jugadores
std::shared_ptr<Player> getPlayer(int id); // Obtiene un jugador a partir de su "id"
int getController(int playerId); // Obtiene un controlador a partir del "id" del jugador
void checkInput(); // Gestiona la entrada durante el juego
void checkPauseInput(); // Verifica si alguno de los controladores ha solicitado una pausa y actualiza el estado de pausa del juego.
void DEMO_handleInput(); // Gestiona las entradas de los jugadores en el modo demo, incluyendo movimientos y disparos automáticos.
void DEMO_handlePassInput(); // Gestiona las entradas de los jugadores en el modo demo para saltarse la demo.
void DEMO_handlePlayerInput(const std::shared_ptr<Player> &player, int index); // Procesa las entradas para un jugador específico durante el modo demo.
void handleFireInput(const std::shared_ptr<Player> &player, BulletType bulletType); // Maneja el disparo de un jugador, incluyendo la creación de balas y la gestión del tiempo de espera entre disparos.
void handlePlayersInput(); // Gestiona las entradas de todos los jugadores en el modo normal (fuera del modo demo).
void handleNormalPlayerInput(const std::shared_ptr<Player> &player); // Maneja las entradas de movimiento y disparo para un jugador en modo normal.
void handleFireInputs(const std::shared_ptr<Player> &player, bool autofire, int controllerIndex); // Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado.
void handlePlayerContinue(const std::shared_ptr<Player> &player); // Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
void handleNameInput(const std::shared_ptr<Player> &player); // Procesa las entradas para la introducción del nombre del jugador.
void initDemo(int player_id); // Inicializa las variables para el modo DEMO
void setTotalPower(); // Calcula el poder total necesario para completar el juego
void initScoreboard(); // Inicializa el marcador
void initDifficultyVars(); // Inicializa las opciones relacionadas con la dificultad
void initPlayers(int player_id); // Inicializa los jugadores
void playMusic(); // Hace sonar la música
void stopMusic(); // Detiene la música
void playSound(const std::string &name); // Hace sonar un sonido
void updateDemo(); // Actualiza las variables durante el modo demo
void updateGameStateFadeIn(); // Actualiza las variables durante dicho estado
void updateGameStateEnteringPlayer(); // Actualiza las variables durante dicho estado
void updateGameStateShowingGetReadyMessage(); // Actualiza las variables durante dicho estado
void updateGameStatePlaying(); // Actualiza las variables durante el transcurso normal del juego
void updateGameStateCompleted(); // Gestiona eventos para el estado del final del juego
void checkState(); // Comprueba el estado del juego
void cleanVectors(); // Vacía los vectores de elementos deshabilitados
void updateMenace(); // Gestiona el nivel de amenaza
void evaluateAndSetMenace(); // Calcula y establece el valor de amenaza en funcion de los globos activos
void checkAndUpdateBalloonSpeed(); // Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
void setState(GameState state); // Cambia el estado del juego
void movePlayersToFront(); // Organiza los jugadores para que los vivos se pinten sobre los muertos
void checkServiceMenu(); // Comprueba si está activo el menu de servicio para poner el juego en pausa
// --- Métodos internos ---
void update(); // Actualiza el juego
void render(); // Dibuja el juego
void checkEvents(); // Comprueba los eventos que hay en cola
void setResources(); // Asigna texturas y animaciones
void updateHiScore(); // Actualiza el valor de HiScore en caso necesario
void updatePlayers(); // Actualiza las variables del jugador
void renderPlayers(); // Dibuja a los jugadores
void updateStage(); // Comprueba si hay cambio de fase y actualiza las variables
void updateGameStateGameOver(); // Actualiza el estado de fin de la partida
void destroyAllItems(); // Destruye todos los items
std::shared_ptr<Balloon> checkPlayerBalloonCollision(std::shared_ptr<Player> &player); // Comprueba la colisión entre el jugador y los globos activos
void checkPlayerItemCollision(std::shared_ptr<Player> &player); // Comprueba la colisión entre el jugador y los items
void checkBulletCollision(); // Comprueba y procesa la colisión de las balas
void updateBullets(); // Mueve las balas activas
void renderBullets(); // Pinta las balas activas
void createBullet(int x, int y, BulletType kind, bool powered_up, int owner); // Crea un objeto bala
void freeBullets(); // Vacia el vector de balas
void updateItems(); // Actualiza los items
void renderItems(); // Pinta los items activos
ItemType dropItem(); // Devuelve un item en función del azar
void createItem(ItemType type, float x, float y); // Crea un objeto item
void freeItems(); // Vacia el vector de items
void createItemText(int x, std::shared_ptr<Texture> texture); // Crea un objeto PathSprite
void createMessage(const std::vector<Path> &paths, std::shared_ptr<Texture> texture); // Crea un objeto PathSprite
void freeSmartSprites(); // Vacia el vector de smartsprites
void freePathSprites(); // Vacia el vector de pathsprites
void throwCoffee(int x, int y); // Crea un SpriteSmart para arrojar el item café al recibir un impacto
void updateSmartSprites(); // Actualiza los SpriteSmarts
void renderSmartSprites(); // Pinta los SpriteSmarts activos
void updatePathSprites(); // Actualiza los PathSprites
void renderPathSprites(); // Pinta los PathSprites activos
void handlePlayerCollision(std::shared_ptr<Player> &player); // Acciones a realizar cuando el jugador colisiona con un globo
void updateTimeStopped(); // Actualiza y comprueba el valor de la variable
void updateBackground(); // Actualiza el fondo
void initPaths(); // Inicializa las variables que contienen puntos de ruta para mover objetos
void enableTimeStopItem(); // Habilita el efecto del item de detener el tiempo
void disableTimeStopItem(); // Deshabilita el efecto del item de detener el tiempo
void updateHelper(); // Actualiza las variables de ayuda
bool allPlayersAreWaitingOrGameOver(); // Comprueba si todos los jugadores han terminado de jugar
bool allPlayersAreGameOver(); // Comprueba si todos los jugadores han terminado de jugar
bool allPlayersAreNotPlaying(); // Comprueba si todos los jugadores han terminado de jugar
void updateScoreboard(); // Actualiza el marcador
void fillCanvas(); // Dibuja los elementos de la zona de juego en su textura
void pause(bool value); // Pausa el juego
void addScoreToScoreBoard(const std::shared_ptr<Player> &player); // Añade una puntuación a la tabla de records
void checkAndUpdatePlayerStatus(int active_player_index, int inactive_player_index); // Saca del estado de GAME OVER al jugador si el otro está activo
void checkPlayersStatusPlaying(); // Comprueba el estado de juego de los jugadores
std::shared_ptr<Player> getPlayer(int id); // Obtiene un jugador a partir de su "id"
int getController(int playerId); // Obtiene un controlador a partir del "id" del jugador
void checkInput(); // Gestiona la entrada durante el juego
void checkPauseInput(); // Verifica si alguno de los controladores ha solicitado una pausa y actualiza el estado de pausa del juego.
void DEMO_handleInput(); // Gestiona las entradas de los jugadores en el modo demo, incluyendo movimientos y disparos automáticos.
void DEMO_handlePassInput(); // Gestiona las entradas de los jugadores en el modo demo para saltarse la demo.
void DEMO_handlePlayerInput(const std::shared_ptr<Player> &player, int index); // Procesa las entradas para un jugador específico durante el modo demo.
void handleFireInput(const std::shared_ptr<Player> &player, BulletType bulletType); // Maneja el disparo de un jugador, incluyendo la creación de balas y la gestión del tiempo de espera entre disparos.
void handlePlayersInput(); // Gestiona las entradas de todos los jugadores en el modo normal (fuera del modo demo).
void handleNormalPlayerInput(const std::shared_ptr<Player> &player); // Maneja las entradas de movimiento y disparo para un jugador en modo normal.
void handleFireInputs(const std::shared_ptr<Player> &player, bool autofire, int controllerIndex); // Procesa las entradas de disparo del jugador, permitiendo disparos automáticos si está habilitado.
void handlePlayerContinue(const std::shared_ptr<Player> &player); // Maneja la continuación del jugador cuando no está jugando, permitiendo que continúe si se pulsa el botón de inicio.
void handleNameInput(const std::shared_ptr<Player> &player); // Procesa las entradas para la introducción del nombre del jugador.
void initDemo(int player_id); // Inicializa las variables para el modo DEMO
void setTotalPower(); // Calcula el poder total necesario para completar el juego
void initScoreboard(); // Inicializa el marcador
void initDifficultyVars(); // Inicializa las opciones relacionadas con la dificultad
void initPlayers(int player_id); // Inicializa los jugadores
void playMusic(); // Hace sonar la música
void stopMusic(); // Detiene la música
void playSound(const std::string &name); // Hace sonar un sonido
void updateDemo(); // Actualiza las variables durante el modo demo
void updateGameStateFadeIn(); // Actualiza las variables durante dicho estado
void updateGameStateEnteringPlayer(); // Actualiza las variables durante dicho estado
void updateGameStateShowingGetReadyMessage(); // Actualiza las variables durante dicho estado
void updateGameStatePlaying(); // Actualiza las variables durante el transcurso normal del juego
void updateGameStateCompleted(); // Gestiona eventos para el estado del final del juego
void checkState(); // Comprueba el estado del juego
void cleanVectors(); // Vacía los vectores de elementos deshabilitados
void updateMenace(); // Gestiona el nivel de amenaza
void evaluateAndSetMenace(); // Calcula y establece el valor de amenaza en funcion de los globos activos
void checkAndUpdateBalloonSpeed(); // Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
void setState(GameState state); // Cambia el estado del juego
void movePlayersToFront(); // Organiza los jugadores para que los vivos se pinten sobre los muertos
void checkServiceMenu(); // Comprueba si está activo el menu de servicio para poner el juego en pausa
#ifdef RECORDING
void updateRecording(); // Actualiza las variables durante el modo de grabación
void updateRecording(); // Actualiza las variables durante el modo de grabación
#endif
};

View File

@@ -1,432 +1,389 @@
#include "hiscore_table.h"
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget
#include <stdlib.h> // Para rand, size_t
#include <algorithm> // Para max
#include <functional> // Para function
#include <vector> // Para vector
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget
#include <stdlib.h> // Para rand, size_t
#include "audio.h" // Para Audio
#include "background.h" // Para Background
#include "fade.h" // Para Fade, FadeMode, FadeType
#include "global_events.h" // Para check
#include "global_inputs.h" // Para check
#include "input.h" // Para Input
#include "lang.h" // Para getText
#include "manage_hiscore_table.h" // Para HiScoreEntry
#include "options.h" // Para SettingsOptions, settings
#include "param.h" // Para Param, param, ParamGame, ParamFade
#include "path_sprite.h" // Para PathSprite, Path, PathType
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name, Options, options
#include "sprite.h" // Para Sprite
#include "text.h" // Para Text, TEXT_SHADOW, TEXT_COLOR
#include "texture.h" // Para Texture
#include "utils.h" // Para Color, easeOutQuint, NO_TEXT_COLOR
#include <algorithm> // Para max
#include <functional> // Para function
#include <vector> // Para vector
#include "audio.h" // Para Audio
#include "background.h" // Para Background
#include "fade.h" // Para Fade, FadeMode, FadeType
#include "global_events.h" // Para check
#include "global_inputs.h" // Para check
#include "input.h" // Para Input
#include "lang.h" // Para getText
#include "manage_hiscore_table.h" // Para HiScoreEntry
#include "options.h" // Para SettingsOptions, settings
#include "param.h" // Para Param, param, ParamGame, ParamFade
#include "path_sprite.h" // Para PathSprite, Path, PathType
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name, Options, options
#include "sprite.h" // Para Sprite
#include "text.h" // Para Text, TEXT_SHADOW, TEXT_COLOR
#include "texture.h" // Para Texture
#include "utils.h" // Para Color, easeOutQuint, NO_TEXT_COLOR
// Constructor
HiScoreTable::HiScoreTable()
: renderer_(Screen::get()->getRenderer()),
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
fade_(std::make_unique<Fade>()),
background_(std::make_unique<Background>()),
counter_(0),
ticks_(0),
view_area_(SDL_FRect{0, 0, static_cast<float>(param.game.width), static_cast<float>(param.game.height)}),
fade_mode_(FadeMode::IN),
background_fade_color_(Color(0, 0, 0))
{
// Inicializa el resto
Section::name = Section::Name::HI_SCORE_TABLE;
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
initFade();
initBackground();
iniEntryColors();
createSprites();
: renderer_(Screen::get()->getRenderer()),
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
fade_(std::make_unique<Fade>()),
background_(std::make_unique<Background>()),
counter_(0),
ticks_(0),
view_area_(SDL_FRect{0, 0, static_cast<float>(param.game.width), static_cast<float>(param.game.height)}),
fade_mode_(FadeMode::IN),
background_fade_color_(Color(0, 0, 0)) {
// Inicializa el resto
Section::name = Section::Name::HI_SCORE_TABLE;
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
initFade();
initBackground();
iniEntryColors();
createSprites();
}
// Destructor
HiScoreTable::~HiScoreTable()
{
SDL_DestroyTexture(backbuffer_);
Options::settings.clearLastHiScoreEntries();
HiScoreTable::~HiScoreTable() {
SDL_DestroyTexture(backbuffer_);
Options::settings.clearLastHiScoreEntries();
}
// Actualiza las variables
void HiScoreTable::update()
{
if (SDL_GetTicks() - ticks_ > param.game.speed)
{
// Actualiza el contador de ticks
ticks_ = SDL_GetTicks();
void HiScoreTable::update() {
if (SDL_GetTicks() - ticks_ > param.game.speed) {
// Actualiza el contador de ticks
ticks_ = SDL_GetTicks();
// Actualiza las posiciones de los sprites de texto
updateSprites();
// Actualiza las posiciones de los sprites de texto
updateSprites();
// Actualiza el fondo
background_->update();
// Actualiza el fondo
background_->update();
// Gestiona el fade
updateFade();
// Gestiona el fade
updateFade();
// Gestiona el contador y sus eventos
updateCounter();
// Gestiona el contador y sus eventos
updateCounter();
// Dibuja los sprites en la textura
fillTexture();
// Dibuja los sprites en la textura
fillTexture();
// Actualiza el objeto screen
Screen::get()->update();
// Actualiza el objeto screen
Screen::get()->update();
// Actualiza las variables de globalInputs
}
// Actualiza las variables de globalInputs
}
}
// Dibuja los sprites en la textura
void HiScoreTable::fillTexture()
{
// Pinta en el backbuffer el texto y los sprites
auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_);
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
SDL_RenderClear(renderer_);
void HiScoreTable::fillTexture() {
// Pinta en el backbuffer el texto y los sprites
auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_);
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
SDL_RenderClear(renderer_);
// Escribe el texto: Mejores puntuaciones
header_->render();
// Escribe el texto: Mejores puntuaciones
header_->render();
// Escribe los nombres de la tabla de puntuaciones
for (auto const &entry : entry_names_)
{
entry->render();
}
// Escribe los nombres de la tabla de puntuaciones
for (auto const &entry : entry_names_) {
entry->render();
}
// Cambia el destino de renderizado
SDL_SetRenderTarget(renderer_, temp);
// Cambia el destino de renderizado
SDL_SetRenderTarget(renderer_, temp);
}
// Pinta en pantalla
void HiScoreTable::render()
{
// Prepara para empezar a dibujar en la textura de juego
Screen::get()->start();
void HiScoreTable::render() {
// Prepara para empezar a dibujar en la textura de juego
Screen::get()->start();
// Limpia la pantalla
Screen::get()->clean();
// Limpia la pantalla
Screen::get()->clean();
// Pinta el fondo
background_->render();
// Pinta el fondo
background_->render();
// Establece la ventana del backbuffer
view_area_.y = std::max(0.0f, param.game.height - counter_ + 100);
// Establece la ventana del backbuffer
view_area_.y = std::max(0.0f, param.game.height - counter_ + 100);
// Copia el backbuffer al renderizador
SDL_RenderTexture(renderer_, backbuffer_, nullptr, &view_area_);
// Copia el backbuffer al renderizador
SDL_RenderTexture(renderer_, backbuffer_, nullptr, &view_area_);
// Renderiza el fade
fade_->render();
// Renderiza el fade
fade_->render();
// Vuelca el contenido del renderizador en pantalla
Screen::get()->render();
// Vuelca el contenido del renderizador en pantalla
Screen::get()->render();
}
// Comprueba los eventos
void HiScoreTable::checkEvents()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
GlobalEvents::check(event);
}
void HiScoreTable::checkEvents() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
GlobalEvents::check(event);
}
}
// Comprueba las entradas
void HiScoreTable::checkInput()
{
Input::get()->update();
GlobalInputs::check();
void HiScoreTable::checkInput() {
Input::get()->update();
GlobalInputs::check();
}
// Bucle para la pantalla de instrucciones
void HiScoreTable::run()
{
Audio::get()->playMusic("title.ogg");
while (Section::name == Section::Name::HI_SCORE_TABLE)
{
checkInput();
update();
checkEvents(); // Tiene que ir antes del render
render();
}
void HiScoreTable::run() {
Audio::get()->playMusic("title.ogg");
while (Section::name == Section::Name::HI_SCORE_TABLE) {
checkInput();
update();
checkEvents(); // Tiene que ir antes del render
render();
}
}
// Gestiona el fade
void HiScoreTable::updateFade()
{
fade_->update();
void HiScoreTable::updateFade() {
fade_->update();
if (fade_->hasEnded() && fade_mode_ == FadeMode::IN)
{
fade_->reset();
fade_mode_ = FadeMode::OUT;
fade_->setMode(fade_mode_);
}
if (fade_->hasEnded() && fade_mode_ == FadeMode::IN) {
fade_->reset();
fade_mode_ = FadeMode::OUT;
fade_->setMode(fade_mode_);
}
if (fade_->hasEnded() && fade_mode_ == FadeMode::OUT)
{
Section::name = (Section::options == Section::Options::HI_SCORE_AFTER_PLAYING)
? Section::Name::TITLE
: Section::Name::INSTRUCTIONS;
Section::options = Section::Options::NONE;
}
if (fade_->hasEnded() && fade_mode_ == FadeMode::OUT) {
Section::name = (Section::options == Section::Options::HI_SCORE_AFTER_PLAYING)
? Section::Name::TITLE
: Section::Name::INSTRUCTIONS;
Section::options = Section::Options::NONE;
}
}
// Convierte un entero a un string con separadores de miles
std::string HiScoreTable::format(int number)
{
const std::string separator = ".";
const std::string score = std::to_string(number);
std::string HiScoreTable::format(int number) {
const std::string separator = ".";
const std::string score = std::to_string(number);
auto index = (int)score.size() - 1;
std::string result;
auto i = 0;
while (index >= 0)
{
result = score.at(index) + result;
index--;
i++;
if (i == 3)
{
i = 0;
result = separator + result;
}
}
auto index = (int)score.size() - 1;
std::string result;
auto i = 0;
while (index >= 0) {
result = score.at(index) + result;
index--;
i++;
if (i == 3) {
i = 0;
result = separator + result;
}
}
return result;
return result;
}
// Crea los sprites con los textos
void HiScoreTable::createSprites()
{
auto header_text = Resource::get()->getText("04b_25_grey");
auto entry_text = Resource::get()->getText("smb2");
void HiScoreTable::createSprites() {
auto header_text = Resource::get()->getText("04b_25_grey");
auto entry_text = Resource::get()->getText("smb2");
// Obtiene el tamaño de la textura
float backbuffer_width;
float backbuffer_height;
SDL_GetTextureSize(backbuffer_, &backbuffer_width, &backbuffer_height);
// Obtiene el tamaño de la textura
float backbuffer_width;
float backbuffer_height;
SDL_GetTextureSize(backbuffer_, &backbuffer_width, &backbuffer_height);
constexpr int ENTRY_LENGHT = 22;
constexpr int MAX_NAMES = 10;
const int space_between_header = entry_text->getCharacterSize() * 4;
const int space_between_lines = entry_text->getCharacterSize() * 2;
const int size = space_between_header + space_between_lines * (MAX_NAMES - 1) + entry_text->getCharacterSize();
const int first_line = (param.game.height - size) / 2;
constexpr int ENTRY_LENGHT = 22;
constexpr int MAX_NAMES = 10;
const int space_between_header = entry_text->getCharacterSize() * 4;
const int space_between_lines = entry_text->getCharacterSize() * 2;
const int size = space_between_header + space_between_lines * (MAX_NAMES - 1) + entry_text->getCharacterSize();
const int first_line = (param.game.height - size) / 2;
// Crea el sprite para el texto de cabecera
header_ = std::make_unique<Sprite>(header_text->writeDXToTexture(TEXT_COLOR, Lang::getText("[HIGHSCORE_TABLE] CAPTION"), -2, background_fade_color_.inverse().lighten(25)));
header_->setPosition(param.game.game_area.center_x - (header_->getWidth() / 2), first_line);
// Crea el sprite para el texto de cabecera
header_ = std::make_unique<Sprite>(header_text->writeDXToTexture(TEXT_COLOR, Lang::getText("[HIGHSCORE_TABLE] CAPTION"), -2, background_fade_color_.inverse().lighten(25)));
header_->setPosition(param.game.game_area.center_x - (header_->getWidth() / 2), first_line);
// Crea los sprites para las entradas en la tabla de puntuaciones
const int animation = rand() % 4;
const std::string sample_line(ENTRY_LENGHT + 3, ' ');
auto sample_entry = std::make_unique<Sprite>(entry_text->writeDXToTexture(TEXT_SHADOW, sample_line, 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR));
const auto entry_width = sample_entry->getWidth();
for (int i = 0; i < MAX_NAMES; ++i)
{
const auto table_position = format(i + 1) + ". ";
const auto score = format(Options::settings.hi_score_table.at(i).score);
const auto num_dots = ENTRY_LENGHT - Options::settings.hi_score_table.at(i).name.size() - score.size();
const auto one_cc = Options::settings.hi_score_table.at(i).one_credit_complete ? " }" : "";
std::string dots;
for (int j = 0; j < (int)num_dots; ++j)
{
dots = dots + ".";
}
const auto line = table_position + Options::settings.hi_score_table.at(i).name + dots + score + one_cc;
// Crea los sprites para las entradas en la tabla de puntuaciones
const int animation = rand() % 4;
const std::string sample_line(ENTRY_LENGHT + 3, ' ');
auto sample_entry = std::make_unique<Sprite>(entry_text->writeDXToTexture(TEXT_SHADOW, sample_line, 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR));
const auto entry_width = sample_entry->getWidth();
for (int i = 0; i < MAX_NAMES; ++i) {
const auto table_position = format(i + 1) + ". ";
const auto score = format(Options::settings.hi_score_table.at(i).score);
const auto num_dots = ENTRY_LENGHT - Options::settings.hi_score_table.at(i).name.size() - score.size();
const auto one_cc = Options::settings.hi_score_table.at(i).one_credit_complete ? " }" : "";
std::string dots;
for (int j = 0; j < (int)num_dots; ++j) {
dots = dots + ".";
}
const auto line = table_position + Options::settings.hi_score_table.at(i).name + dots + score + one_cc;
entry_names_.emplace_back(std::make_shared<PathSprite>(entry_text->writeDXToTexture(TEXT_SHADOW, line, 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR)));
const int default_pos_x = (backbuffer_width - entry_width) / 2;
const int pos_x = (i < 9) ? default_pos_x : default_pos_x - entry_text->getCharacterSize();
const int pos_y = (i * space_between_lines) + first_line + space_between_header;
constexpr int steps = 80;
switch (animation)
{
case 0: // Ambos lados alternativamente
{
if (i % 2 == 0)
{
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), pos_x, PathType::HORIZONTAL, pos_y, steps, easeOutQuint);
entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0);
}
else
{
entry_names_.back()->addPath(backbuffer_width, pos_x, PathType::HORIZONTAL, pos_y, steps, easeOutQuint);
entry_names_.back()->setPosition(backbuffer_width, 0);
}
break;
}
entry_names_.emplace_back(std::make_shared<PathSprite>(entry_text->writeDXToTexture(TEXT_SHADOW, line, 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR)));
const int default_pos_x = (backbuffer_width - entry_width) / 2;
const int pos_x = (i < 9) ? default_pos_x : default_pos_x - entry_text->getCharacterSize();
const int pos_y = (i * space_between_lines) + first_line + space_between_header;
constexpr int steps = 80;
switch (animation) {
case 0: // Ambos lados alternativamente
{
if (i % 2 == 0) {
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), pos_x, PathType::HORIZONTAL, pos_y, steps, easeOutQuint);
entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0);
} else {
entry_names_.back()->addPath(backbuffer_width, pos_x, PathType::HORIZONTAL, pos_y, steps, easeOutQuint);
entry_names_.back()->setPosition(backbuffer_width, 0);
}
break;
}
case 1: // Entran por la izquierda
{
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), pos_x, PathType::HORIZONTAL, pos_y, steps, easeOutQuint);
entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0);
break;
}
case 1: // Entran por la izquierda
{
entry_names_.back()->addPath(-entry_names_.back()->getWidth(), pos_x, PathType::HORIZONTAL, pos_y, steps, easeOutQuint);
entry_names_.back()->setPosition(-entry_names_.back()->getWidth(), 0);
break;
}
case 2: // Entran por la derecha
{
entry_names_.back()->addPath(backbuffer_width, pos_x, PathType::HORIZONTAL, pos_y, steps, easeOutQuint);
entry_names_.back()->setPosition(backbuffer_width, 0);
break;
}
case 2: // Entran por la derecha
{
entry_names_.back()->addPath(backbuffer_width, pos_x, PathType::HORIZONTAL, pos_y, steps, easeOutQuint);
entry_names_.back()->setPosition(backbuffer_width, 0);
break;
}
case 3: // Entran desde la parte inferior
{
entry_names_.back()->addPath(backbuffer_height, pos_y, PathType::VERTICAL, pos_x, steps, easeOutQuint);
entry_names_.back()->setPosition(0, backbuffer_height);
}
case 3: // Entran desde la parte inferior
{
entry_names_.back()->addPath(backbuffer_height, pos_y, PathType::VERTICAL, pos_x, steps, easeOutQuint);
entry_names_.back()->setPosition(0, backbuffer_height);
}
default:
break;
}
}
default:
break;
}
}
}
// Actualiza las posiciones de los sprites de texto
void HiScoreTable::updateSprites()
{
constexpr int init_counter = 190;
const int counter_between_entries = 16;
if (counter_ >= init_counter)
{
const int counter2 = counter_ - init_counter;
if (counter2 % counter_between_entries == 0)
{
int index = counter2 / counter_between_entries;
if (index < static_cast<int>(entry_names_.size()))
{
entry_names_.at(index)->enable();
}
}
}
for (auto const &entry : entry_names_)
{
entry->update();
}
void HiScoreTable::updateSprites() {
constexpr int init_counter = 190;
const int counter_between_entries = 16;
if (counter_ >= init_counter) {
const int counter2 = counter_ - init_counter;
if (counter2 % counter_between_entries == 0) {
int index = counter2 / counter_between_entries;
if (index < static_cast<int>(entry_names_.size())) {
entry_names_.at(index)->enable();
}
}
}
for (auto const &entry : entry_names_) {
entry->update();
}
glowEntryNames();
glowEntryNames();
}
// Inicializa el fade
void HiScoreTable::initFade()
{
fade_->setColor(param.fade.color);
fade_->setType(FadeType::RANDOM_SQUARE);
fade_->setPostDuration(param.fade.post_duration);
fade_->setMode(fade_mode_);
fade_->activate();
void HiScoreTable::initFade() {
fade_->setColor(param.fade.color);
fade_->setType(FadeType::RANDOM_SQUARE);
fade_->setPostDuration(param.fade.post_duration);
fade_->setMode(fade_mode_);
fade_->activate();
}
// Inicializa el fondo
void HiScoreTable::initBackground()
{
background_->setPos(param.game.game_area.rect);
background_->setCloudsSpeed(-0.1f);
void HiScoreTable::initBackground() {
background_->setPos(param.game.game_area.rect);
background_->setCloudsSpeed(-0.1f);
const int lucky = rand() % 3;
switch (lucky)
{
case 0: // Fondo verde
{
background_->setGradientNumber(2);
background_->setTransition(0.0f);
background_->setSunProgression(1.0f);
background_->setMoonProgression(0.0f);
background_fade_color_ = GREEN_SKY_COLOR;
break;
}
const int lucky = rand() % 3;
switch (lucky) {
case 0: // Fondo verde
{
background_->setGradientNumber(2);
background_->setTransition(0.0f);
background_->setSunProgression(1.0f);
background_->setMoonProgression(0.0f);
background_fade_color_ = GREEN_SKY_COLOR;
break;
}
case 1: // Fondo naranja
{
background_->setGradientNumber(1);
background_->setTransition(0.0f);
background_->setSunProgression(0.65f);
background_->setMoonProgression(0.0f);
background_fade_color_ = PINK_SKY_COLOR;
break;
}
case 1: // Fondo naranja
{
background_->setGradientNumber(1);
background_->setTransition(0.0f);
background_->setSunProgression(0.65f);
background_->setMoonProgression(0.0f);
background_fade_color_ = PINK_SKY_COLOR;
break;
}
case 2: // Fondo azul
{
background_->setGradientNumber(0);
background_->setTransition(0.0f);
background_->setSunProgression(0.0f);
background_->setMoonProgression(0.0f);
background_fade_color_ = BLUE_SKY_COLOR;
break;
}
case 2: // Fondo azul
{
background_->setGradientNumber(0);
background_->setTransition(0.0f);
background_->setSunProgression(0.0f);
background_->setMoonProgression(0.0f);
background_fade_color_ = BLUE_SKY_COLOR;
break;
}
default:
break;
}
default:
break;
}
}
// Obtiene un color del vector de colores de entradas
Color HiScoreTable::getEntryColor(int counter_)
{
int cycle_length = entry_colors_.size() * 2 - 2;
size_t n = counter_ % cycle_length;
Color HiScoreTable::getEntryColor(int counter_) {
int cycle_length = entry_colors_.size() * 2 - 2;
size_t n = counter_ % cycle_length;
size_t index;
if (n < entry_colors_.size())
{
index = n; // Avanza: 0,1,2,3
}
else
{
index = 2 * (entry_colors_.size() - 1) - n; // Retrocede: 2,1
}
size_t index;
if (n < entry_colors_.size()) {
index = n; // Avanza: 0,1,2,3
} else {
index = 2 * (entry_colors_.size() - 1) - n; // Retrocede: 2,1
}
return entry_colors_[index];
return entry_colors_[index];
}
// Inicializa los colores de las entradas
void HiScoreTable::iniEntryColors()
{
entry_colors_.clear();
entry_colors_.emplace_back(background_fade_color_.inverse().lighten(75));
entry_colors_.emplace_back(background_fade_color_.inverse().lighten(50));
entry_colors_.emplace_back(background_fade_color_.inverse().lighten(25));
entry_colors_.emplace_back(background_fade_color_.inverse());
void HiScoreTable::iniEntryColors() {
entry_colors_.clear();
entry_colors_.emplace_back(background_fade_color_.inverse().lighten(75));
entry_colors_.emplace_back(background_fade_color_.inverse().lighten(50));
entry_colors_.emplace_back(background_fade_color_.inverse().lighten(25));
entry_colors_.emplace_back(background_fade_color_.inverse());
}
// Hace brillar los nombres de la tabla de records
void HiScoreTable::glowEntryNames()
{
const Color entry_color = getEntryColor(counter_ / 5);
for (const auto &entry_index : Options::settings.last_hi_score_entry)
{
if (entry_index != -1)
{
entry_names_.at(entry_index)->getTexture()->setColor(entry_color);
}
}
void HiScoreTable::glowEntryNames() {
const Color entry_color = getEntryColor(counter_ / 5);
for (const auto &entry_index : Options::settings.last_hi_score_entry) {
if (entry_index != -1) {
entry_names_.at(entry_index)->getTexture()->setColor(entry_color);
}
}
}
// Gestiona el contador
void HiScoreTable::updateCounter()
{
++counter_;
void HiScoreTable::updateCounter() {
++counter_;
if (counter_ == 150)
{
background_->setColor(background_fade_color_.darken());
background_->setAlpha(96);
}
if (counter_ == 150) {
background_->setColor(background_fade_color_.darken());
background_->setAlpha(96);
}
if (counter_ == COUNTER_END_)
{
fade_->activate();
}
if (counter_ == COUNTER_END_) {
fade_->activate();
}
}

View File

@@ -1,11 +1,12 @@
#pragma once
#include <SDL3/SDL.h> // Para Uint16, SDL_FRect, SDL_Renderer, SDL_Texture, Uint64, Uint8
#include <memory> // Para unique_ptr, shared_ptr
#include <string> // Para string
#include <vector> // Para vector
#include <SDL3/SDL.h> // Para Uint16, SDL_FRect, SDL_Renderer, SDL_Texture, Uint64, Uint8
#include "utils.h" // Para Color
#include <memory> // Para unique_ptr, shared_ptr
#include <string> // Para string
#include <vector> // Para vector
#include "utils.h" // Para Color
class Background;
class Fade;
@@ -15,64 +16,63 @@ enum class FadeMode : Uint8;
struct Path;
/*
Esta clase gestiona un estado del programa. Se encarga de mostrar la tabla con las puntuaciones
más altas. Para ello utiliza un objeto que se encarga de pintar el fondo y una textura
sobre la que escribe las puntuaciones. Esta textura se recorre modificando la ventana de vista
para dar el efecto de que la textura se mueve sobre la pantalla.
Esta clase gestiona un estado del programa. Se encarga de mostrar la tabla con las puntuaciones
más altas. Para ello utiliza un objeto que se encarga de pintar el fondo y una textura
sobre la que escribe las puntuaciones. Esta textura se recorre modificando la ventana de vista
para dar el efecto de que la textura se mueve sobre la pantalla.
Para mejorar la legibilidad de los textos, el objeto que dibuja el fondo es capaz de modificar
su atenuación.
Para mejorar la legibilidad de los textos, el objeto que dibuja el fondo es capaz de modificar
su atenuación.
*/
// Clase HiScoreTable
class HiScoreTable
{
public:
// Constructor
HiScoreTable();
class HiScoreTable {
public:
// Constructor
HiScoreTable();
// Destructor
~HiScoreTable();
// Destructor
~HiScoreTable();
// Bucle principal
void run();
// Bucle principal
void run();
private:
// --- Constantes ---
static constexpr Uint16 COUNTER_END_ = 800; // Valor final para el contador
private:
// --- Constantes ---
static constexpr Uint16 COUNTER_END_ = 800; // Valor final para el contador
// --- Objetos y punteros ---
SDL_Renderer *renderer_; // El renderizador de la ventana
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
// --- Objetos y punteros ---
SDL_Renderer *renderer_; // El renderizador de la ventana
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
std::unique_ptr<Sprite> header_; // Sprite con la cabecera del texto
std::vector<std::shared_ptr<PathSprite>> entry_names_; // Lista con los sprites de cada uno de los nombres de la tabla de records
std::vector<Path> paths_; // Vector con los recorridos precalculados
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
std::unique_ptr<Background> background_; // Objeto para dibujar el fondo del juego
std::unique_ptr<Sprite> header_; // Sprite con la cabecera del texto
std::vector<std::shared_ptr<PathSprite>> entry_names_; // Lista con los sprites de cada uno de los nombres de la tabla de records
std::vector<Path> paths_; // Vector con los recorridos precalculados
// --- Variables ---
Uint16 counter_ = 0; // Contador
Uint64 ticks_; // Contador de ticks para ajustar la velocidad del programa
SDL_FRect view_area_; // Parte de la textura que se muestra en pantalla
FadeMode fade_mode_; // Modo de fade a utilizar
Color background_fade_color_; // Color de atenuación del fondo
std::vector<Color> entry_colors_; // Colores para destacar las entradas en la tabla
// --- Variables ---
Uint16 counter_ = 0; // Contador
Uint64 ticks_; // Contador de ticks para ajustar la velocidad del programa
SDL_FRect view_area_; // Parte de la textura que se muestra en pantalla
FadeMode fade_mode_; // Modo de fade a utilizar
Color background_fade_color_; // Color de atenuación del fondo
std::vector<Color> entry_colors_; // Colores para destacar las entradas en la tabla
// --- Métodos internos ---
void update(); // Actualiza las variables
void render(); // Pinta en pantalla
void checkEvents(); // Comprueba los eventos
void checkInput(); // Comprueba las entradas
std::string format(int number); // Convierte un entero a un string con separadores de miles
void fillTexture(); // Dibuja los sprites en la textura
void updateFade(); // Gestiona el fade
void createSprites(); // Crea los sprites con los textos
void updateSprites(); // Actualiza las posiciones de los sprites de texto
void initFade(); // Inicializa el fade
void initBackground(); // Inicializa el fondo
Color getEntryColor(int counter_); // Obtiene un color del vector de colores de entradas
void iniEntryColors(); // Inicializa los colores de las entradas
void glowEntryNames(); // Hace brillar los nombres de la tabla de records
void updateCounter(); // Gestiona el contador
// --- Métodos internos ---
void update(); // Actualiza las variables
void render(); // Pinta en pantalla
void checkEvents(); // Comprueba los eventos
void checkInput(); // Comprueba las entradas
std::string format(int number); // Convierte un entero a un string con separadores de miles
void fillTexture(); // Dibuja los sprites en la textura
void updateFade(); // Gestiona el fade
void createSprites(); // Crea los sprites con los textos
void updateSprites(); // Actualiza las posiciones de los sprites de texto
void initFade(); // Inicializa el fade
void initBackground(); // Inicializa el fondo
Color getEntryColor(int counter_); // Obtiene un color del vector de colores de entradas
void iniEntryColors(); // Inicializa los colores de las entradas
void glowEntryNames(); // Hace brillar los nombres de la tabla de records
void updateCounter(); // Gestiona el contador
};

View File

@@ -1,382 +1,351 @@
#include "instructions.h"
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget, SDL_Re...
#include <algorithm> // Para max
#include <array> // Para array
#include <string> // Para basic_string, string
#include <utility> // Para move
#include <vector> // Para vector
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget, SDL_Re...
#include "audio.h" // Para Audio
#include "fade.h" // Para Fade, FadeMode, FadeType
#include "global_events.h" // Para check
#include "global_inputs.h" // Para check
#include "input.h" // Para Input
#include "lang.h" // Para getText
#include "param.h" // Para Param, param, ParamGame, ParamFade, Param...
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name, Options, options
#include "sprite.h" // Para Sprite
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR, TEXT_SHADOW
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
#include "utils.h" // Para Color, SHADOW_TEXT_COLOR, Zone, NO_TEXT_C...
#include <algorithm> // Para max
#include <array> // Para array
#include <string> // Para basic_string, string
#include <utility> // Para move
#include <vector> // Para vector
#include "audio.h" // Para Audio
#include "fade.h" // Para Fade, FadeMode, FadeType
#include "global_events.h" // Para check
#include "global_inputs.h" // Para check
#include "input.h" // Para Input
#include "lang.h" // Para getText
#include "param.h" // Para Param, param, ParamGame, ParamFade, Param...
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name, Options, options
#include "sprite.h" // Para Sprite
#include "text.h" // Para Text, TEXT_CENTER, TEXT_COLOR, TEXT_SHADOW
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
#include "utils.h" // Para Color, SHADOW_TEXT_COLOR, Zone, NO_TEXT_C...
// Constructor
Instructions::Instructions()
: renderer_(Screen::get()->getRenderer()),
texture_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
text_(Resource::get()->getText("smb2")),
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::STATIC)),
fade_(std::make_unique<Fade>())
{
// Configura las texturas
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
: renderer_(Screen::get()->getRenderer()),
texture_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
text_(Resource::get()->getText("smb2")),
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::STATIC)),
fade_(std::make_unique<Fade>()) {
// Configura las texturas
SDL_SetTextureBlendMode(backbuffer_, SDL_BLENDMODE_BLEND);
SDL_SetTextureBlendMode(texture_, SDL_BLENDMODE_BLEND);
// Inicializa variables
Section::name = Section::Name::INSTRUCTIONS;
view_ = param.game.game_area.rect;
// Inicializa variables
Section::name = Section::Name::INSTRUCTIONS;
view_ = param.game.game_area.rect;
// Inicializa objetos
tiled_bg_->setColor(param.title.bg_color);
fade_->setColor(param.fade.color);
fade_->setType(FadeType::FULLSCREEN);
fade_->setPostDuration(param.fade.post_duration);
fade_->setMode(FadeMode::IN);
fade_->activate();
// Inicializa objetos
tiled_bg_->setColor(param.title.bg_color);
fade_->setColor(param.fade.color);
fade_->setType(FadeType::FULLSCREEN);
fade_->setPostDuration(param.fade.post_duration);
fade_->setMode(FadeMode::IN);
fade_->activate();
// Inicializa las líneas con un retraso progresivo de 50 ms
lines_ = initializeLines(256);
// Inicializa las líneas con un retraso progresivo de 50 ms
lines_ = initializeLines(256);
// Rellena la textura de texto
fillTexture();
// Rellena la textura de texto
fillTexture();
// Inicializa los sprites de los items
iniSprites();
// Inicializa los sprites de los items
iniSprites();
}
// Destructor
Instructions::~Instructions()
{
item_textures_.clear();
sprites_.clear();
Instructions::~Instructions() {
item_textures_.clear();
sprites_.clear();
SDL_DestroyTexture(backbuffer_);
SDL_DestroyTexture(texture_);
SDL_DestroyTexture(backbuffer_);
SDL_DestroyTexture(texture_);
}
// Inicializa los sprites de los items
void Instructions::iniSprites()
{
// Inicializa las texturas
item_textures_.emplace_back(Resource::get()->getTexture("item_points1_disk.png"));
item_textures_.emplace_back(Resource::get()->getTexture("item_points2_gavina.png"));
item_textures_.emplace_back(Resource::get()->getTexture("item_points3_pacmar.png"));
item_textures_.emplace_back(Resource::get()->getTexture("item_clock.png"));
item_textures_.emplace_back(Resource::get()->getTexture("item_coffee.png"));
void Instructions::iniSprites() {
// Inicializa las texturas
item_textures_.emplace_back(Resource::get()->getTexture("item_points1_disk.png"));
item_textures_.emplace_back(Resource::get()->getTexture("item_points2_gavina.png"));
item_textures_.emplace_back(Resource::get()->getTexture("item_points3_pacmar.png"));
item_textures_.emplace_back(Resource::get()->getTexture("item_clock.png"));
item_textures_.emplace_back(Resource::get()->getTexture("item_coffee.png"));
// Inicializa los sprites
for (int i = 0; i < (int)item_textures_.size(); ++i)
{
auto sprite = std::make_unique<Sprite>(item_textures_[i], 0, 0, param.game.item_size, param.game.item_size);
sprite->setPosition((SDL_FPoint){sprite_pos_.x, sprite_pos_.y + ((param.game.item_size + item_space_) * i)});
sprites_.push_back(std::move(sprite));
}
// Inicializa los sprites
for (int i = 0; i < (int)item_textures_.size(); ++i) {
auto sprite = std::make_unique<Sprite>(item_textures_[i], 0, 0, param.game.item_size, param.game.item_size);
sprite->setPosition((SDL_FPoint){sprite_pos_.x, sprite_pos_.y + ((param.game.item_size + item_space_) * i)});
sprites_.push_back(std::move(sprite));
}
}
// Actualiza los sprites
void Instructions::updateSprites()
{
SDL_FRect src_rect = {0, 0, param.game.item_size, param.game.item_size};
void Instructions::updateSprites() {
SDL_FRect src_rect = {0, 0, param.game.item_size, param.game.item_size};
// Disquito
src_rect.y = param.game.item_size * (((counter_ + 12) / 36) % 2);
sprites_[0]->setSpriteClip(src_rect);
// Disquito
src_rect.y = param.game.item_size * (((counter_ + 12) / 36) % 2);
sprites_[0]->setSpriteClip(src_rect);
// Gavina
src_rect.y = param.game.item_size * (((counter_ + 9) / 36) % 2);
sprites_[1]->setSpriteClip(src_rect);
// Gavina
src_rect.y = param.game.item_size * (((counter_ + 9) / 36) % 2);
sprites_[1]->setSpriteClip(src_rect);
// Pacmar
src_rect.y = param.game.item_size * (((counter_ + 6) / 36) % 2);
sprites_[2]->setSpriteClip(src_rect);
// Pacmar
src_rect.y = param.game.item_size * (((counter_ + 6) / 36) % 2);
sprites_[2]->setSpriteClip(src_rect);
// Time Stopper
src_rect.y = param.game.item_size * (((counter_ + 3) / 36) % 2);
sprites_[3]->setSpriteClip(src_rect);
// Time Stopper
src_rect.y = param.game.item_size * (((counter_ + 3) / 36) % 2);
sprites_[3]->setSpriteClip(src_rect);
// Coffee
src_rect.y = param.game.item_size * (((counter_ + 0) / 36) % 2);
sprites_[4]->setSpriteClip(src_rect);
// Coffee
src_rect.y = param.game.item_size * (((counter_ + 0) / 36) % 2);
sprites_[4]->setSpriteClip(src_rect);
}
// Rellena la textura de texto
void Instructions::fillTexture()
{
const int desp_x = param.game.item_size + 8;
void Instructions::fillTexture() {
const int desp_x = param.game.item_size + 8;
// Modifica el renderizador para pintar en la textura
auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, texture_);
// Modifica el renderizador para pintar en la textura
auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, texture_);
// Limpia la textura
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
SDL_RenderClear(renderer_);
// Limpia la textura
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
SDL_RenderClear(renderer_);
// Constantes
constexpr int num_lines = 4;
constexpr int num_item_lines = 4;
constexpr int num_post_headers = 2;
constexpr int num_pre_headers = 1;
// Constantes
constexpr int num_lines = 4;
constexpr int num_item_lines = 4;
constexpr int num_post_headers = 2;
constexpr int num_pre_headers = 1;
constexpr int space_post_header = 20;
constexpr int space_pre_header = 28;
const int space_between_lines = text_->getCharacterSize() * 1.5f;
const int space_between_item_lines = param.game.item_size + item_space_;
const int space_new_paragraph = space_between_lines * 0.5f;
constexpr int space_post_header = 20;
constexpr int space_pre_header = 28;
const int space_between_lines = text_->getCharacterSize() * 1.5f;
const int space_between_item_lines = param.game.item_size + item_space_;
const int space_new_paragraph = space_between_lines * 0.5f;
const int size = (num_lines * space_between_lines) + (num_item_lines * space_between_item_lines) + (num_post_headers * space_post_header) + (num_pre_headers * space_pre_header) + (space_new_paragraph);
const int first_line = (param.game.height - size) / 2;
const int size = (num_lines * space_between_lines) + (num_item_lines * space_between_item_lines) + (num_post_headers * space_post_header) + (num_pre_headers * space_pre_header) + (space_new_paragraph);
const int first_line = (param.game.height - size) / 2;
// Calcula cual es el texto más largo de las descripciones de los items
int lenght = 0;
const std::array<std::string, 5> ITEM_DESCRIPTIONS = {
Lang::getText("[INSTRUCTIONS] 07"),
Lang::getText("[INSTRUCTIONS] 08"),
Lang::getText("[INSTRUCTIONS] 09"),
Lang::getText("[INSTRUCTIONS] 10"),
Lang::getText("[INSTRUCTIONS] 11")};
for (const auto &desc : ITEM_DESCRIPTIONS)
{
const int l = text_->lenght(desc);
lenght = l > lenght ? l : lenght;
}
const int ANCHOR_ITEM = (param.game.width - (lenght + desp_x)) / 2;
// Calcula cual es el texto más largo de las descripciones de los items
int lenght = 0;
const std::array<std::string, 5> ITEM_DESCRIPTIONS = {
Lang::getText("[INSTRUCTIONS] 07"),
Lang::getText("[INSTRUCTIONS] 08"),
Lang::getText("[INSTRUCTIONS] 09"),
Lang::getText("[INSTRUCTIONS] 10"),
Lang::getText("[INSTRUCTIONS] 11")};
for (const auto &desc : ITEM_DESCRIPTIONS) {
const int l = text_->lenght(desc);
lenght = l > lenght ? l : lenght;
}
const int ANCHOR_ITEM = (param.game.width - (lenght + desp_x)) / 2;
constexpr Color ORANGE_COLOR = Color(0XFF, 0X7A, 0X00);
constexpr Color ORANGE_COLOR = Color(0XFF, 0X7A, 0X00);
// Escribe el texto de las instrucciones
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, first_line, Lang::getText("[INSTRUCTIONS] 01"), 1, ORANGE_COLOR, 1, SHADOW_TEXT_COLOR);
// Escribe el texto de las instrucciones
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, first_line, Lang::getText("[INSTRUCTIONS] 01"), 1, ORANGE_COLOR, 1, SHADOW_TEXT_COLOR);
const int anchor1 = first_line + space_post_header;
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + space_between_lines * 0, Lang::getText("[INSTRUCTIONS] 02"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + space_between_lines * 1, Lang::getText("[INSTRUCTIONS] 03"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + space_new_paragraph + space_between_lines * 2, Lang::getText("[INSTRUCTIONS] 04"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + space_new_paragraph + space_between_lines * 3, Lang::getText("[INSTRUCTIONS] 05"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
const int anchor1 = first_line + space_post_header;
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + space_between_lines * 0, Lang::getText("[INSTRUCTIONS] 02"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + space_between_lines * 1, Lang::getText("[INSTRUCTIONS] 03"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + space_new_paragraph + space_between_lines * 2, Lang::getText("[INSTRUCTIONS] 04"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor1 + space_new_paragraph + space_between_lines * 3, Lang::getText("[INSTRUCTIONS] 05"), 1, NO_TEXT_COLOR, 1, SHADOW_TEXT_COLOR);
// Escribe el texto de los objetos y sus puntos
const int anchor2 = anchor1 + space_pre_header + space_new_paragraph + space_between_lines * 3;
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor2, Lang::getText("[INSTRUCTIONS] 06"), 1, ORANGE_COLOR, 1, SHADOW_TEXT_COLOR);
// Escribe el texto de los objetos y sus puntos
const int anchor2 = anchor1 + space_pre_header + space_new_paragraph + space_between_lines * 3;
text_->writeDX(TEXT_CENTER | TEXT_COLOR | TEXT_SHADOW, param.game.game_area.center_x, anchor2, Lang::getText("[INSTRUCTIONS] 06"), 1, ORANGE_COLOR, 1, SHADOW_TEXT_COLOR);
const int anchor3 = anchor2 + space_post_header;
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 0, Lang::getText("[INSTRUCTIONS] 07"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 1, Lang::getText("[INSTRUCTIONS] 08"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 2, Lang::getText("[INSTRUCTIONS] 09"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 3, Lang::getText("[INSTRUCTIONS] 10"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 4, Lang::getText("[INSTRUCTIONS] 11"), SHADOW_TEXT_COLOR);
const int anchor3 = anchor2 + space_post_header;
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 0, Lang::getText("[INSTRUCTIONS] 07"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 1, Lang::getText("[INSTRUCTIONS] 08"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 2, Lang::getText("[INSTRUCTIONS] 09"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 3, Lang::getText("[INSTRUCTIONS] 10"), SHADOW_TEXT_COLOR);
text_->writeShadowed(ANCHOR_ITEM + desp_x, anchor3 + space_between_item_lines * 4, Lang::getText("[INSTRUCTIONS] 11"), SHADOW_TEXT_COLOR);
// Deja el renderizador como estaba
SDL_SetRenderTarget(renderer_, temp);
// Deja el renderizador como estaba
SDL_SetRenderTarget(renderer_, temp);
// Da valor a la variable
sprite_pos_.x = ANCHOR_ITEM;
sprite_pos_.y = anchor3 - ((param.game.item_size - text_->getCharacterSize()) / 2);
// Da valor a la variable
sprite_pos_.x = ANCHOR_ITEM;
sprite_pos_.y = anchor3 - ((param.game.item_size - text_->getCharacterSize()) / 2);
}
// Rellena el backbuffer
void Instructions::fillBackbuffer()
{
// Modifica el renderizador para pintar en la textura
auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_);
void Instructions::fillBackbuffer() {
// Modifica el renderizador para pintar en la textura
auto temp = SDL_GetRenderTarget(renderer_);
SDL_SetRenderTarget(renderer_, backbuffer_);
// Limpia la textura
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
SDL_RenderClear(renderer_);
// Limpia la textura
SDL_SetRenderDrawColor(renderer_, 0, 0, 0, 0);
SDL_RenderClear(renderer_);
// Coloca el texto de fondo
SDL_RenderTexture(renderer_, texture_, nullptr, nullptr);
// Coloca el texto de fondo
SDL_RenderTexture(renderer_, texture_, nullptr, nullptr);
// Dibuja los sprites
for (auto &sprite : sprites_)
{
sprite->render();
}
// Dibuja los sprites
for (auto &sprite : sprites_) {
sprite->render();
}
// Deja el renderizador como estaba
SDL_SetRenderTarget(renderer_, temp);
// Deja el renderizador como estaba
SDL_SetRenderTarget(renderer_, temp);
}
// Actualiza las variables
void Instructions::update()
{
if (SDL_GetTicks() - ticks_ > param.game.speed)
{
// Actualiza el contador de ticks
ticks_ = SDL_GetTicks();
void Instructions::update() {
if (SDL_GetTicks() - ticks_ > param.game.speed) {
// Actualiza el contador de ticks
ticks_ = SDL_GetTicks();
// Actualiza el objeto screen
Screen::get()->update();
// Actualiza el objeto screen
Screen::get()->update();
// Incrementa el contador
counter_++;
// Incrementa el contador
counter_++;
// Actualiza los sprites
updateSprites();
// Actualiza los sprites
updateSprites();
// Gestiona la textura con los graficos
updateBackbuffer();
// Gestiona la textura con los graficos
updateBackbuffer();
// Actualiza el mosaico de fondo
tiled_bg_->update();
// Actualiza el mosaico de fondo
tiled_bg_->update();
// Actualiza el objeto "fade"
fade_->update();
// Actualiza el objeto "fade"
fade_->update();
// Rellena el backbuffer
fillBackbuffer();
}
// Rellena el backbuffer
fillBackbuffer();
}
}
// Pinta en pantalla
void Instructions::render()
{
// Prepara para empezar a dibujar en la textura de juego
Screen::get()->start();
void Instructions::render() {
// Prepara para empezar a dibujar en la textura de juego
Screen::get()->start();
// Limpia la pantalla
Screen::get()->clean();
// Limpia la pantalla
Screen::get()->clean();
// Dibuja el mosacico de fondo
tiled_bg_->render();
// Dibuja el mosacico de fondo
tiled_bg_->render();
// Copia la textura y el backbuffer al renderizador
if (view_.y == 0)
renderLines(renderer_, backbuffer_, lines_);
else
SDL_RenderTexture(renderer_, backbuffer_, nullptr, &view_);
// Copia la textura y el backbuffer al renderizador
if (view_.y == 0)
renderLines(renderer_, backbuffer_, lines_);
else
SDL_RenderTexture(renderer_, backbuffer_, nullptr, &view_);
fade_->render();
fade_->render();
// Vuelca el contenido del renderizador en pantalla
Screen::get()->render();
// Vuelca el contenido del renderizador en pantalla
Screen::get()->render();
}
// Comprueba los eventos
void Instructions::checkEvents()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
GlobalEvents::check(event);
}
void Instructions::checkEvents() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
GlobalEvents::check(event);
}
}
// Comprueba las entradas
void Instructions::checkInput()
{
Input::get()->update();
GlobalInputs::check();
void Instructions::checkInput() {
Input::get()->update();
GlobalInputs::check();
}
// Bucle para la pantalla de instrucciones
void Instructions::run()
{
Audio::get()->playMusic("title.ogg");
while (Section::name == Section::Name::INSTRUCTIONS)
{
checkInput();
update();
checkEvents(); // Tiene que ir antes del render
render();
}
void Instructions::run() {
Audio::get()->playMusic("title.ogg");
while (Section::name == Section::Name::INSTRUCTIONS) {
checkInput();
update();
checkEvents(); // Tiene que ir antes del render
render();
}
}
// Método para inicializar las líneas
std::vector<Line> Instructions::initializeLines(int height)
{
std::vector<Line> lines;
for (int y = 0; y < height; y++)
{
int direction = (y % 2 == 0) ? -1 : 1; // Pares a la izquierda, impares a la derecha
lines.emplace_back(y, 0.0f, direction);
}
return lines;
std::vector<Line> Instructions::initializeLines(int height) {
std::vector<Line> lines;
for (int y = 0; y < height; y++) {
int direction = (y % 2 == 0) ? -1 : 1; // Pares a la izquierda, impares a la derecha
lines.emplace_back(y, 0.0f, direction);
}
return lines;
}
// Método para mover las líneas con suavizado
bool Instructions::moveLines(std::vector<Line> &lines, int width, float duration, Uint32 startDelay)
{
Uint32 current_time = SDL_GetTicks();
bool all_lines_off_screen = true;
bool Instructions::moveLines(std::vector<Line> &lines, int width, float duration, Uint32 startDelay) {
Uint32 current_time = SDL_GetTicks();
bool all_lines_off_screen = true;
for (auto &line : lines)
{
// Establecer startTime en el primer cuadro de animación
if (line.startTime == 0)
{
line.startTime = current_time + line.y * startDelay;
}
for (auto &line : lines) {
// Establecer startTime en el primer cuadro de animación
if (line.startTime == 0) {
line.startTime = current_time + line.y * startDelay;
}
float elapsed_time = (current_time - line.startTime) / 1000.0f; // Convertir a segundos
if (elapsed_time < 0)
{
all_lines_off_screen = false; // Si aún no se debe mover esta línea, no están todas fuera de pantalla
continue;
}
if (elapsed_time >= duration)
{
continue; // Si la línea ha salido de los límites, no la muevas más
}
float elapsed_time = (current_time - line.startTime) / 1000.0f; // Convertir a segundos
if (elapsed_time < 0) {
all_lines_off_screen = false; // Si aún no se debe mover esta línea, no están todas fuera de pantalla
continue;
}
if (elapsed_time >= duration) {
continue; // Si la línea ha salido de los límites, no la muevas más
}
float t = elapsed_time / duration;
float smooth_factor = easeInOutQuint(t);
line.x = line.direction * smooth_factor * width;
all_lines_off_screen = false; // Si alguna línea aún se está moviendo, no están todas fuera de pantalla
}
float t = elapsed_time / duration;
float smooth_factor = easeInOutQuint(t);
line.x = line.direction * smooth_factor * width;
all_lines_off_screen = false; // Si alguna línea aún se está moviendo, no están todas fuera de pantalla
}
return all_lines_off_screen;
return all_lines_off_screen;
}
// Método para renderizar las líneas
void Instructions::renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines)
{
for (const auto &LINE : lines)
{
SDL_FRect srcRect = {0, static_cast<float>(LINE.y), 320, 1};
SDL_FRect dstRect = {static_cast<float>(LINE.x), static_cast<float>(LINE.y), 320, 1};
SDL_RenderTexture(renderer, texture, &srcRect, &dstRect);
}
void Instructions::renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines) {
for (const auto &LINE : lines) {
SDL_FRect srcRect = {0, static_cast<float>(LINE.y), 320, 1};
SDL_FRect dstRect = {static_cast<float>(LINE.x), static_cast<float>(LINE.y), 320, 1};
SDL_RenderTexture(renderer, texture, &srcRect, &dstRect);
}
}
// Gestiona la textura con los graficos
void Instructions::updateBackbuffer()
{
// Establece la ventana del backbuffer
view_.y = std::max(0.0f, param.game.height - counter_ + 100);
void Instructions::updateBackbuffer() {
// Establece la ventana del backbuffer
view_.y = std::max(0.0f, param.game.height - counter_ + 100);
// Verifica si view_.y == 0 y gestiona el temporizador
if (view_.y == 0)
{
if (!start_delay_triggered_)
{
// Activa el temporizador si no ha sido activado
start_delay_triggered_ = true;
start_delay_time_ = SDL_GetTicks();
}
else if (SDL_GetTicks() - start_delay_time_ >= 4000)
{
// Han pasado tres segundos, mover líneas
all_lines_off_screen_ = moveLines(lines_, 320, 1.0f, 5);
}
}
// Verifica si view_.y == 0 y gestiona el temporizador
if (view_.y == 0) {
if (!start_delay_triggered_) {
// Activa el temporizador si no ha sido activado
start_delay_triggered_ = true;
start_delay_time_ = SDL_GetTicks();
} else if (SDL_GetTicks() - start_delay_time_ >= 4000) {
// Han pasado tres segundos, mover líneas
all_lines_off_screen_ = moveLines(lines_, 320, 1.0f, 5);
}
}
// Comprueba si el contador ha llegado al final
if (all_lines_off_screen_)
{
Section::name = Section::Name::TITLE;
Section::options = Section::Options::TITLE_1;
}
// Comprueba si el contador ha llegado al final
if (all_lines_off_screen_) {
Section::name = Section::Name::TITLE;
Section::options = Section::Options::TITLE_1;
}
}

View File

@@ -1,8 +1,9 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_Texture, Uint32, SDL_Renderer, SDL_FPoint, SDL_FRect, Uint64
#include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector
#include <SDL3/SDL.h> // Para SDL_Texture, Uint32, SDL_Renderer, SDL_FPoint, SDL_FRect, Uint64
#include <memory> // Para unique_ptr, shared_ptr
#include <vector> // Para vector
class Fade;
class Sprite;
@@ -11,78 +12,76 @@ class Texture;
class TiledBG;
/*
Esta clase gestiona un estado del programa. Se encarga de poner en pantalla
un texto explicativo para entender cómo se juega.
Esta clase gestiona un estado del programa. Se encarga de poner en pantalla
un texto explicativo para entender cómo se juega.
Además muestra algunos items y explica para qué sirven.
Además muestra algunos items y explica para qué sirven.
Utiliza dos texturas de apoyo, una con el texto ya escrito y otra donde se combina
tanto el texto de la primera textura como los sprites de los items.
Utiliza dos texturas de apoyo, una con el texto ya escrito y otra donde se combina
tanto el texto de la primera textura como los sprites de los items.
Finalmente, una ventana recorre la textura para dar el efecto de que todo se desplaza
por la pantalla sobre el mosaico de fondo (gestionado por el correspondiente objeto).
Finalmente, una ventana recorre la textura para dar el efecto de que todo se desplaza
por la pantalla sobre el mosaico de fondo (gestionado por el correspondiente objeto).
*/
// Estructura para almacenar información de línea animada
struct Line
{
int y; // Coordenada Y de la línea
float x; // Coordenada X inicial (usamos float para mayor precisión en el suavizado)
int direction; // Dirección de movimiento: -1 para izquierda, 1 para derecha
Uint32 startTime; // Tiempo de inicio del movimiento
struct Line {
int y; // Coordenada Y de la línea
float x; // Coordenada X inicial (usamos float para mayor precisión en el suavizado)
int direction; // Dirección de movimiento: -1 para izquierda, 1 para derecha
Uint32 startTime; // Tiempo de inicio del movimiento
// Constructor de Line
Line(int y, float x, int direction)
: y(y), x(x), direction(direction), startTime(0) {}
// Constructor de Line
Line(int y, float x, int direction)
: y(y), x(x), direction(direction), startTime(0) {}
};
// Clase Instructions
class Instructions
{
public:
// Constructor
Instructions();
class Instructions {
public:
// Constructor
Instructions();
// Destructor
~Instructions();
// Destructor
~Instructions();
// Bucle principal
void run();
// Bucle principal
void run();
private:
// --- Objetos y punteros ---
SDL_Renderer *renderer_; // El renderizador de la ventana
SDL_Texture *texture_; // Textura fija con el texto
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
private:
// --- Objetos y punteros ---
SDL_Renderer *renderer_; // El renderizador de la ventana
SDL_Texture *texture_; // Textura fija con el texto
SDL_Texture *backbuffer_; // Textura para usar como backbuffer
std::vector<std::shared_ptr<Texture>> item_textures_; // Vector con las texturas de los items
std::vector<std::unique_ptr<Sprite>> sprites_; // Vector con los sprites de los items
std::shared_ptr<Text> text_; // Objeto para escribir texto
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
std::vector<std::shared_ptr<Texture>> item_textures_; // Vector con las texturas de los items
std::vector<std::unique_ptr<Sprite>> sprites_; // Vector con los sprites de los items
std::shared_ptr<Text> text_; // Objeto para escribir texto
std::unique_ptr<TiledBG> tiled_bg_; // Objeto para dibujar el mosaico animado de fondo
std::unique_ptr<Fade> fade_; // Objeto para renderizar fades
// --- Variables ---
int counter_ = 0; // Contador para manejar el progreso en la pantalla de instrucciones
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
SDL_FRect view_; // Vista del backbuffer que se va a mostrar por pantalla
SDL_FPoint sprite_pos_ = {0, 0}; // Posición del primer sprite en la lista
float item_space_ = 2.0; // Espacio entre los items en pantalla
std::vector<Line> lines_; // Vector que contiene las líneas animadas en la pantalla
bool all_lines_off_screen_ = false; // Indica si todas las líneas han salido de la pantalla
Uint32 start_delay_time_ = 0; // Tiempo de inicio del retraso para mover las líneas
bool start_delay_triggered_ = false; // Bandera para determinar si el retraso ha comenzado
// --- Variables ---
int counter_ = 0; // Contador para manejar el progreso en la pantalla de instrucciones
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
SDL_FRect view_; // Vista del backbuffer que se va a mostrar por pantalla
SDL_FPoint sprite_pos_ = {0, 0}; // Posición del primer sprite en la lista
float item_space_ = 2.0; // Espacio entre los items en pantalla
std::vector<Line> lines_; // Vector que contiene las líneas animadas en la pantalla
bool all_lines_off_screen_ = false; // Indica si todas las líneas han salido de la pantalla
Uint32 start_delay_time_ = 0; // Tiempo de inicio del retraso para mover las líneas
bool start_delay_triggered_ = false; // Bandera para determinar si el retraso ha comenzado
// --- Métodos internos ---
void update(); // Actualiza las variables
void render(); // Pinta en pantalla
void checkEvents(); // Comprueba los eventos
void checkInput(); // Comprueba las entradas
void fillTexture(); // Rellena la textura de texto
void fillBackbuffer(); // Rellena el backbuffer
void iniSprites(); // Inicializa los sprites de los items
void updateSprites(); // Actualiza los sprites
std::vector<Line> initializeLines(int height); // Inicializa las líneas animadas
bool moveLines(std::vector<Line> &lines, int width, float duration, Uint32 startDelay); // Mueve las líneas
void renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines); // Renderiza las líneas
void updateBackbuffer(); // Gestiona la textura con los gráficos
// --- Métodos internos ---
void update(); // Actualiza las variables
void render(); // Pinta en pantalla
void checkEvents(); // Comprueba los eventos
void checkInput(); // Comprueba las entradas
void fillTexture(); // Rellena la textura de texto
void fillBackbuffer(); // Rellena el backbuffer
void iniSprites(); // Inicializa los sprites de los items
void updateSprites(); // Actualiza los sprites
std::vector<Line> initializeLines(int height); // Inicializa las líneas animadas
bool moveLines(std::vector<Line> &lines, int width, float duration, Uint32 startDelay); // Mueve las líneas
void renderLines(SDL_Renderer *renderer, SDL_Texture *texture, const std::vector<Line> &lines); // Renderiza las líneas
void updateBackbuffer(); // Gestiona la textura con los gráficos
};

File diff suppressed because it is too large Load Diff

View File

@@ -1,74 +1,72 @@
#pragma once
#include <SDL3/SDL.h> // Para Uint32, Uint64
#include <memory> // Para unique_ptr
#include <vector> // Para vector
#include <SDL3/SDL.h> // Para Uint32, Uint64
#include "param.h" // Para Param, ParamIntro, param
#include "path_sprite.h" // Para PathSprite
#include "tiled_bg.h" // Para TiledBG
#include "utils.h" // Para Color
#include "writer.h" // Para Writer
#include <memory> // Para unique_ptr
#include <vector> // Para vector
#include "param.h" // Para Param, ParamIntro, param
#include "path_sprite.h" // Para PathSprite
#include "tiled_bg.h" // Para TiledBG
#include "utils.h" // Para Color
#include "writer.h" // Para Writer
/*
Esta clase gestiona un estado del programa. Se encarga de mostrar la secuencia
de introducción.
Esta clase gestiona un estado del programa. Se encarga de mostrar la secuencia
de introducción.
*/
// Clase Intro
class Intro
{
public:
// Constructor
Intro();
class Intro {
public:
// Constructor
Intro();
// Destructor
~Intro() = default;
// Destructor
~Intro() = default;
// Bucle principal
void run();
// Bucle principal
void run();
private:
// --- Estados internos ---
enum class IntroState
{
SCENES,
POST,
};
private:
// --- Estados internos ---
enum class IntroState {
SCENES,
POST,
};
enum class IntroPostState
{
STOP_BG,
END,
};
enum class IntroPostState {
STOP_BG,
END,
};
// --- Objetos ---
std::vector<std::unique_ptr<PathSprite>> card_sprites_; // Vector con los sprites inteligentes para los dibujos de la intro
std::vector<std::unique_ptr<PathSprite>> shadow_sprites_; // Vector con los sprites inteligentes para las sombras
std::vector<std::unique_ptr<Writer>> texts_; // Textos de la intro
std::unique_ptr<TiledBG> tiled_bg_; // Fondo en mosaico
// std::unique_ptr<Sprite> shadow_square_for_text_; // Sprite
// --- Objetos ---
std::vector<std::unique_ptr<PathSprite>> card_sprites_; // Vector con los sprites inteligentes para los dibujos de la intro
std::vector<std::unique_ptr<PathSprite>> shadow_sprites_; // Vector con los sprites inteligentes para las sombras
std::vector<std::unique_ptr<Writer>> texts_; // Textos de la intro
std::unique_ptr<TiledBG> tiled_bg_; // Fondo en mosaico
// std::unique_ptr<Sprite> shadow_square_for_text_; // Sprite
// --- Variables ---
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
int scene_ = 0; // Indica qué escena está activa
IntroState state_ = IntroState::SCENES; // Estado principal de la intro
IntroPostState post_state_ = IntroPostState::STOP_BG; // Estado POST
Uint32 state_start_time_; // Tiempo de inicio del estado actual
Color bg_color_ = param.intro.bg_color; // Color de fondo
// --- Variables ---
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
int scene_ = 0; // Indica qué escena está activa
IntroState state_ = IntroState::SCENES; // Estado principal de la intro
IntroPostState post_state_ = IntroPostState::STOP_BG; // Estado POST
Uint32 state_start_time_; // Tiempo de inicio del estado actual
Color bg_color_ = param.intro.bg_color; // Color de fondo
// --- Métodos internos ---
void update(); // Actualiza las variables del objeto
void render(); // Dibuja el objeto en pantalla
void checkEvents(); // Comprueba los eventos
void checkInput(); // Comprueba las entradas
void updateScenes(); // Actualiza las escenas de la intro
void initSprites(); // Inicializa las imágenes
void initTexts(); // Inicializa los textos
void updateSprites(); // Actualiza los sprites
void updateTexts(); // Actualiza los textos
void renderSprites(); // Dibuja los sprites
void renderTexts(); // Dibuja los textos
void renderTextRect(); // Dibuja el rectangulo de fondo del texto;
void updatePostState(); // Actualiza el estado POST
// --- Métodos internos ---
void update(); // Actualiza las variables del objeto
void render(); // Dibuja el objeto en pantalla
void checkEvents(); // Comprueba los eventos
void checkInput(); // Comprueba las entradas
void updateScenes(); // Actualiza las escenas de la intro
void initSprites(); // Inicializa las imágenes
void initTexts(); // Inicializa los textos
void updateSprites(); // Actualiza los sprites
void updateTexts(); // Actualiza los textos
void renderSprites(); // Dibuja los sprites
void renderTexts(); // Dibuja los textos
void renderTextRect(); // Dibuja el rectangulo de fondo del texto;
void updatePostState(); // Actualiza el estado POST
};

View File

@@ -1,211 +1,181 @@
#include "logo.h"
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_PollEvent, SDL_Event
#include <string> // Para basic_string
#include <utility> // Para move
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_PollEvent, SDL_Event
#include "audio.h" // Para Audio
#include "global_events.h" // Para check
#include "global_inputs.h" // Para check
#include "input.h" // Para Input
#include "param.h" // Para Param, ParamGame, param
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name
#include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture
#include "utils.h" // Para Color, Zone
#include <string> // Para basic_string
#include <utility> // Para move
#include "audio.h" // Para Audio
#include "global_events.h" // Para check
#include "global_inputs.h" // Para check
#include "input.h" // Para Input
#include "param.h" // Para Param, ParamGame, param
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name
#include "sprite.h" // Para Sprite
#include "texture.h" // Para Texture
#include "utils.h" // Para Color, Zone
// Constructor
Logo::Logo()
: since_texture_(Resource::get()->getTexture("logo_since_1998.png")),
since_sprite_(std::make_unique<Sprite>(since_texture_)),
jail_texture_(Resource::get()->getTexture("logo_jailgames.png"))
{
: since_texture_(Resource::get()->getTexture("logo_since_1998.png")),
since_sprite_(std::make_unique<Sprite>(since_texture_)),
jail_texture_(Resource::get()->getTexture("logo_jailgames.png")) {
// Inicializa variables
Section::name = Section::Name::LOGO;
dest_.x = param.game.game_area.center_x - jail_texture_->getWidth() / 2;
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2;
since_sprite_->setPosition(SDL_FRect{
static_cast<float>((param.game.width - since_texture_->getWidth()) / 2),
static_cast<float>(83 + jail_texture_->getHeight() + 5),
static_cast<float>(since_texture_->getWidth()),
static_cast<float>(since_texture_->getHeight())});
since_sprite_->setY(dest_.y + jail_texture_->getHeight() + 5);
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight());
since_texture_->setColor(0x00, 0x00, 0x00);
// Inicializa variables
Section::name = Section::Name::LOGO;
dest_.x = param.game.game_area.center_x - jail_texture_->getWidth() / 2;
dest_.y = param.game.game_area.center_y - jail_texture_->getHeight() / 2;
since_sprite_->setPosition(SDL_FRect{
static_cast<float>((param.game.width - since_texture_->getWidth()) / 2),
static_cast<float>(83 + jail_texture_->getHeight() + 5),
static_cast<float>(since_texture_->getWidth()),
static_cast<float>(since_texture_->getHeight())});
since_sprite_->setY(dest_.y + jail_texture_->getHeight() + 5);
since_sprite_->setSpriteClip(0, 0, since_texture_->getWidth(), since_texture_->getHeight());
since_texture_->setColor(0x00, 0x00, 0x00);
// Crea los sprites de cada linea
for (int i = 0; i < jail_texture_->getHeight(); ++i) {
auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), 1);
temp->setSpriteClip(0, i, jail_texture_->getWidth(), 1);
const int POS_X = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3);
temp->setX(POS_X);
temp->setY(dest_.y + i);
jail_sprite_.push_back(std::move(temp));
}
// Crea los sprites de cada linea
for (int i = 0; i < jail_texture_->getHeight(); ++i)
{
auto temp = std::make_unique<Sprite>(jail_texture_, 0, i, jail_texture_->getWidth(), 1);
temp->setSpriteClip(0, i, jail_texture_->getWidth(), 1);
const int POS_X = (i % 2 == 0) ? param.game.width + (i * 3) : -jail_texture_->getWidth() - (i * 3);
temp->setX(POS_X);
temp->setY(dest_.y + i);
jail_sprite_.push_back(std::move(temp));
}
// Inicializa el vector de colores
color_.push_back(Color(0x00, 0x00, 0x00)); // Black
color_.push_back(Color(0x00, 0x00, 0xd8)); // Blue
color_.push_back(Color(0xd8, 0x00, 0x00)); // Red
color_.push_back(Color(0xd8, 0x00, 0xd8)); // Magenta
color_.push_back(Color(0x00, 0xd8, 0x00)); // Green
color_.push_back(Color(0x00, 0xd8, 0xd8)); // Cyan
color_.push_back(Color(0xd8, 0xd8, 0x00)); // Yellow
color_.push_back(Color(0xFF, 0xFF, 0xFF)); // Bright white
// Inicializa el vector de colores
color_.push_back(Color(0x00, 0x00, 0x00)); // Black
color_.push_back(Color(0x00, 0x00, 0xd8)); // Blue
color_.push_back(Color(0xd8, 0x00, 0x00)); // Red
color_.push_back(Color(0xd8, 0x00, 0xd8)); // Magenta
color_.push_back(Color(0x00, 0xd8, 0x00)); // Green
color_.push_back(Color(0x00, 0xd8, 0xd8)); // Cyan
color_.push_back(Color(0xd8, 0xd8, 0x00)); // Yellow
color_.push_back(Color(0xFF, 0xFF, 0xFF)); // Bright white
}
// Destructor
Logo::~Logo()
{
jail_texture_->setColor(255, 255, 255);
since_texture_->setColor(255, 255, 255);
Audio::get()->stopAllSounds();
Audio::get()->stopMusic();
Logo::~Logo() {
jail_texture_->setColor(255, 255, 255);
since_texture_->setColor(255, 255, 255);
Audio::get()->stopAllSounds();
Audio::get()->stopMusic();
}
// Comprueba el manejador de eventos
void Logo::checkEvents()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
GlobalEvents::check(event);
}
void Logo::checkEvents() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
GlobalEvents::check(event);
}
}
// Comprueba las entradas
void Logo::checkInput()
{
Input::get()->update();
GlobalInputs::check();
void Logo::checkInput() {
Input::get()->update();
GlobalInputs::check();
}
// Gestiona el logo de JAILGAMES
void Logo::updateJAILGAMES()
{
if (counter_ == 30)
{
Audio::get()->playSound("logo.wav");
}
void Logo::updateJAILGAMES() {
if (counter_ == 30) {
Audio::get()->playSound("logo.wav");
}
if (counter_ > 30)
{
for (int i = 0; i < (int)jail_sprite_.size(); ++i)
{
if (jail_sprite_[i]->getX() != dest_.x)
{
if (i % 2 == 0)
{
jail_sprite_[i]->incX(-SPEED);
if (jail_sprite_[i]->getX() < dest_.x)
{
jail_sprite_[i]->setX(dest_.x);
}
}
else
{
jail_sprite_[i]->incX(SPEED);
if (jail_sprite_[i]->getX() > dest_.x)
{
jail_sprite_[i]->setX(dest_.x);
}
}
}
}
}
if (counter_ > 30) {
for (int i = 0; i < (int)jail_sprite_.size(); ++i) {
if (jail_sprite_[i]->getX() != dest_.x) {
if (i % 2 == 0) {
jail_sprite_[i]->incX(-SPEED);
if (jail_sprite_[i]->getX() < dest_.x) {
jail_sprite_[i]->setX(dest_.x);
}
} else {
jail_sprite_[i]->incX(SPEED);
if (jail_sprite_[i]->getX() > dest_.x) {
jail_sprite_[i]->setX(dest_.x);
}
}
}
}
}
// Comprueba si ha terminado el logo
if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION)
{
Section::name = Section::Name::INTRO;
}
// Comprueba si ha terminado el logo
if (counter_ == END_LOGO_COUNTER_MARK + POST_LOGO_DURATION) {
Section::name = Section::Name::INTRO;
}
}
// Gestiona el color de las texturas
void Logo::updateTextureColors()
{
constexpr int inc = 4;
void Logo::updateTextureColors() {
constexpr int inc = 4;
// Manejo de 'sinceTexture'
for (int i = 0; i <= 7; ++i)
{
if (counter_ == SHOW_SINCE_SPRITE_COUNTER_MARK + inc * i)
{
since_texture_->setColor(color_[i].r, color_[i].g, color_[i].b);
}
}
// Manejo de 'sinceTexture'
for (int i = 0; i <= 7; ++i) {
if (counter_ == SHOW_SINCE_SPRITE_COUNTER_MARK + inc * i) {
since_texture_->setColor(color_[i].r, color_[i].g, color_[i].b);
}
}
// Manejo de 'jailTexture' y 'sinceTexture' en el fade
for (int i = 0; i <= 6; ++i)
{
if (counter_ == INIT_FADE_COUNTER_MARK + inc * i)
{
jail_texture_->setColor(color_[6 - i].r, color_[6 - i].g, color_[6 - i].b);
since_texture_->setColor(color_[6 - i].r, color_[6 - i].g, color_[6 - i].b);
}
}
// Manejo de 'jailTexture' y 'sinceTexture' en el fade
for (int i = 0; i <= 6; ++i) {
if (counter_ == INIT_FADE_COUNTER_MARK + inc * i) {
jail_texture_->setColor(color_[6 - i].r, color_[6 - i].g, color_[6 - i].b);
since_texture_->setColor(color_[6 - i].r, color_[6 - i].g, color_[6 - i].b);
}
}
}
// Actualiza las variables
void Logo::update()
{
if (SDL_GetTicks() - ticks_ > param.game.speed)
{
// Actualiza el contador de ticks
ticks_ = SDL_GetTicks();
void Logo::update() {
if (SDL_GetTicks() - ticks_ > param.game.speed) {
// Actualiza el contador de ticks
ticks_ = SDL_GetTicks();
// Actualiza el objeto screen
Screen::get()->update();
// Actualiza el objeto screen
Screen::get()->update();
// Comprueba las entradas
checkInput();
// Comprueba las entradas
checkInput();
updateJAILGAMES();
updateTextureColors();
updateJAILGAMES();
updateTextureColors();
// Gestiona el contador
++counter_;
}
// Gestiona el contador
++counter_;
}
}
// Dibuja en pantalla
void Logo::render()
{
Screen::get()->start();
Screen::get()->clean();
void Logo::render() {
Screen::get()->start();
Screen::get()->clean();
renderJAILGAMES();
renderJAILGAMES();
Screen::get()->render();
Screen::get()->render();
}
// Bucle para el logo del juego
void Logo::run()
{
while (Section::name == Section::Name::LOGO)
{
checkInput();
update();
checkEvents(); // Tiene que ir antes del render
render();
}
void Logo::run() {
while (Section::name == Section::Name::LOGO) {
checkInput();
update();
checkEvents(); // Tiene que ir antes del render
render();
}
}
// Renderiza el logo de JAILGAMES
void Logo::renderJAILGAMES()
{
// Dibuja los sprites
for (auto &sprite : jail_sprite_)
{
sprite->render();
}
void Logo::renderJAILGAMES() {
// Dibuja los sprites
for (auto &sprite : jail_sprite_) {
sprite->render();
}
if (counter_ >= SHOW_SINCE_SPRITE_COUNTER_MARK)
{
since_sprite_->render();
}
if (counter_ >= SHOW_SINCE_SPRITE_COUNTER_MARK) {
since_sprite_->render();
}
}

View File

@@ -1,60 +1,60 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_FPoint, Uint64
#include <memory> // Para shared_ptr, unique_ptr
#include <vector> // Para vector
#include <SDL3/SDL.h> // Para SDL_FPoint, Uint64
#include <memory> // Para shared_ptr, unique_ptr
#include <vector> // Para vector
class Sprite;
class Texture;
struct Color;
/*
Esta clase gestiona un estado del programa. Se encarga de dibujar por pantalla el
logo de "JAILGAMES" utilizando un sencillo efecto consistente en generar un sprite por
cada línea del bitmap que forma la palabra "JAILGAMES". Posteriormente realiza una
modulación de color sobre la textura para simular un fade to black al estilo
ZX Spectrum.
Esta clase gestiona un estado del programa. Se encarga de dibujar por pantalla el
logo de "JAILGAMES" utilizando un sencillo efecto consistente en generar un sprite por
cada línea del bitmap que forma la palabra "JAILGAMES". Posteriormente realiza una
modulación de color sobre la textura para simular un fade to black al estilo
ZX Spectrum.
*/
// --- Clase Logo ---
class Logo
{
public:
// Constructor
Logo();
class Logo {
public:
// Constructor
Logo();
// Destructor
~Logo();
// Destructor
~Logo();
// Bucle principal
void run();
// Bucle principal
void run();
private:
// --- Constantes ---
static constexpr int SHOW_SINCE_SPRITE_COUNTER_MARK = 70; // Tiempo del contador en el que empieza a verse el sprite de "SINCE 1998"
static constexpr int INIT_FADE_COUNTER_MARK = 300; // Tiempo del contador cuando inicia el fade a negro
static constexpr int END_LOGO_COUNTER_MARK = 400; // Tiempo del contador para terminar el logo
static constexpr int POST_LOGO_DURATION = 20; // Tiempo que dura el logo con el fade al máximo
static constexpr int SPEED = 8; // Velocidad de desplazamiento de cada línea
private:
// --- Constantes ---
static constexpr int SHOW_SINCE_SPRITE_COUNTER_MARK = 70; // Tiempo del contador en el que empieza a verse el sprite de "SINCE 1998"
static constexpr int INIT_FADE_COUNTER_MARK = 300; // Tiempo del contador cuando inicia el fade a negro
static constexpr int END_LOGO_COUNTER_MARK = 400; // Tiempo del contador para terminar el logo
static constexpr int POST_LOGO_DURATION = 20; // Tiempo que dura el logo con el fade al máximo
static constexpr int SPEED = 8; // Velocidad de desplazamiento de cada línea
// --- Objetos y punteros ---
std::shared_ptr<Texture> since_texture_; // Textura con los gráficos "Since 1998"
std::unique_ptr<Sprite> since_sprite_; // Sprite para manejar la since_texture
std::shared_ptr<Texture> jail_texture_; // Textura con los gráficos "JAILGAMES"
std::vector<std::unique_ptr<Sprite>> jail_sprite_; // Vector con los sprites de cada línea que forman el bitmap JAILGAMES
// --- Objetos y punteros ---
std::shared_ptr<Texture> since_texture_; // Textura con los gráficos "Since 1998"
std::unique_ptr<Sprite> since_sprite_; // Sprite para manejar la since_texture
std::shared_ptr<Texture> jail_texture_; // Textura con los gráficos "JAILGAMES"
std::vector<std::unique_ptr<Sprite>> jail_sprite_; // Vector con los sprites de cada línea que forman el bitmap JAILGAMES
// --- Variables ---
std::vector<Color> color_; // Vector con los colores para el fade
int counter_ = 0; // Contador
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
SDL_FPoint dest_; // Posición donde dibujar el logo
// --- Variables ---
std::vector<Color> color_; // Vector con los colores para el fade
int counter_ = 0; // Contador
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
SDL_FPoint dest_; // Posición donde dibujar el logo
// --- Métodos internos ---
void update(); // Actualiza las variables
void render(); // Dibuja en pantalla
void checkEvents(); // Comprueba el manejador de eventos
void checkInput(); // Comprueba las entradas
void updateJAILGAMES(); // Gestiona el logo de JAILGAMES
void renderJAILGAMES(); // Renderiza el logo de JAILGAMES
void updateTextureColors(); // Gestiona el color de las texturas
// --- Métodos internos ---
void update(); // Actualiza las variables
void render(); // Dibuja en pantalla
void checkEvents(); // Comprueba el manejador de eventos
void checkInput(); // Comprueba las entradas
void updateJAILGAMES(); // Gestiona el logo de JAILGAMES
void renderJAILGAMES(); // Renderiza el logo de JAILGAMES
void updateTextureColors(); // Gestiona el color de las texturas
};

View File

@@ -1,579 +1,523 @@
#include "title.h"
#include <SDL3/SDL.h> // Para SDL_GetTicks, Uint32, SDL_EventType
#include <stddef.h> // Para size_t
#include <algorithm> // Para find_if
#include <iostream> // Para basic_ostream, basic_ostream::operator<<
#include <string> // Para basic_string, char_traits, operator+
#include <vector> // Para vector
#include <SDL3/SDL.h> // Para SDL_GetTicks, Uint32, SDL_EventType
#include <stddef.h> // Para size_t
#include "audio.h" // Para Audio
#include "define_buttons.h" // Para DefineButtons
#include "fade.h" // Para Fade, FadeType
#include "game_logo.h" // Para GameLogo
#include "global_events.h" // Para check
#include "global_inputs.h" // Para check
#include "input.h" // Para Input, INPUT_DO_NOT_ALLOW_REPEAT, Input...
#include "lang.h" // Para getText
#include "notifier.h" // Para Notifier
#include "options.h" // Para GamepadOptions, controllers, getPlayerW...
#include "param.h" // Para Param, param, ParamGame, ParamTitle
#include "player.h" // Para Player, PlayerState
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name, Options, options, AttractMode
#include "sprite.h" // Para Sprite
#include "text.h" // Para TEXT_CENTER, TEXT_SHADOW, Text
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
#include "ui/service_menu.h" // Para ServiceMenu
#include "utils.h" // Para Color, Zone, NO_TEXT_COLOR, TITLE_SHADO...
#include <algorithm> // Para find_if
#include <iostream> // Para basic_ostream, basic_ostream::operator<<
#include <string> // Para basic_string, char_traits, operator+
#include <vector> // Para vector
#include "audio.h" // Para Audio
#include "define_buttons.h" // Para DefineButtons
#include "fade.h" // Para Fade, FadeType
#include "game_logo.h" // Para GameLogo
#include "global_events.h" // Para check
#include "global_inputs.h" // Para check
#include "input.h" // Para Input, INPUT_DO_NOT_ALLOW_REPEAT, Input...
#include "lang.h" // Para getText
#include "notifier.h" // Para Notifier
#include "options.h" // Para GamepadOptions, controllers, getPlayerW...
#include "param.h" // Para Param, param, ParamGame, ParamTitle
#include "player.h" // Para Player, PlayerState
#include "resource.h" // Para Resource
#include "screen.h" // Para Screen
#include "section.h" // Para Name, name, Options, options, AttractMode
#include "sprite.h" // Para Sprite
#include "text.h" // Para TEXT_CENTER, TEXT_SHADOW, Text
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
#include "ui/service_menu.h" // Para ServiceMenu
#include "utils.h" // Para Color, Zone, NO_TEXT_COLOR, TITLE_SHADO...
class Texture;
#ifdef DEBUG
#include <iomanip> // Para operator<<, setfill, setw
#include <iomanip> // Para operator<<, setfill, setw
#endif
// Constructor
Title::Title()
: text_(Resource::get()->getText("smb2_grad")),
fade_(std::make_unique<Fade>()),
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::RANDOM)),
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))),
define_buttons_(std::make_unique<DefineButtons>()),
num_controllers_(Input::get()->getNumControllers()),
state_(TitleState::LOGO_ANIMATING)
{
// Configura objetos
tiled_bg_->setColor(param.title.bg_color);
game_logo_->enable();
mini_logo_sprite_->setX(param.game.game_area.center_x - mini_logo_sprite_->getWidth() / 2);
fade_->setColor(param.fade.color);
fade_->setType(FadeType::RANDOM_SQUARE);
fade_->setPostDuration(param.fade.post_duration);
initPlayers();
: text_(Resource::get()->getText("smb2_grad")),
fade_(std::make_unique<Fade>()),
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::RANDOM)),
game_logo_(std::make_unique<GameLogo>(param.game.game_area.center_x, param.title.title_c_c_position)),
mini_logo_sprite_(std::make_unique<Sprite>(Resource::get()->getTexture("logo_jailgames_mini.png"))),
define_buttons_(std::make_unique<DefineButtons>()),
num_controllers_(Input::get()->getNumControllers()),
state_(TitleState::LOGO_ANIMATING) {
// Configura objetos
tiled_bg_->setColor(param.title.bg_color);
game_logo_->enable();
mini_logo_sprite_->setX(param.game.game_area.center_x - mini_logo_sprite_->getWidth() / 2);
fade_->setColor(param.fade.color);
fade_->setType(FadeType::RANDOM_SQUARE);
fade_->setPostDuration(param.fade.post_duration);
initPlayers();
// Asigna valores a otras variables
Section::options = Section::Options::TITLE_1;
const bool IS_TITLE_TO_DEMO = (Section::attract_mode == Section::AttractMode::TITLE_TO_DEMO);
next_section_ = IS_TITLE_TO_DEMO ? Section::Name::GAME_DEMO : Section::Name::LOGO;
Section::attract_mode = IS_TITLE_TO_DEMO ? Section::AttractMode::TITLE_TO_LOGO : Section::AttractMode::TITLE_TO_DEMO;
// Asigna valores a otras variables
Section::options = Section::Options::TITLE_1;
const bool IS_TITLE_TO_DEMO = (Section::attract_mode == Section::AttractMode::TITLE_TO_DEMO);
next_section_ = IS_TITLE_TO_DEMO ? Section::Name::GAME_DEMO : Section::Name::LOGO;
Section::attract_mode = IS_TITLE_TO_DEMO ? Section::AttractMode::TITLE_TO_LOGO : Section::AttractMode::TITLE_TO_DEMO;
// Define los anclajes de los elementos
anchor_.mini_logo = (param.game.height / 5 * 4) + BLOCK;
mini_logo_sprite_->setY(anchor_.mini_logo);
anchor_.copyright_text = anchor_.mini_logo + mini_logo_sprite_->getHeight() + 3;
// Define los anclajes de los elementos
anchor_.mini_logo = (param.game.height / 5 * 4) + BLOCK;
mini_logo_sprite_->setY(anchor_.mini_logo);
anchor_.copyright_text = anchor_.mini_logo + mini_logo_sprite_->getHeight() + 3;
}
// Destructor
Title::~Title()
{
Audio::get()->stopAllSounds();
if (Section::name == Section::Name::LOGO)
{
Audio::get()->fadeOutMusic(300);
}
Title::~Title() {
Audio::get()->stopAllSounds();
if (Section::name == Section::Name::LOGO) {
Audio::get()->fadeOutMusic(300);
}
}
// Actualiza las variables del objeto
void Title::update()
{
if (SDL_GetTicks() - ticks_ > param.game.speed)
{
ticks_ = SDL_GetTicks();
updateFade();
updateState();
updateStartPrompt();
updatePlayers();
Screen::get()->update();
}
void Title::update() {
if (SDL_GetTicks() - ticks_ > param.game.speed) {
ticks_ = SDL_GetTicks();
updateFade();
updateState();
updateStartPrompt();
updatePlayers();
Screen::get()->update();
}
}
// Dibuja el objeto en pantalla
void Title::render()
{
Screen::get()->start();
Screen::get()->clean();
void Title::render() {
Screen::get()->start();
Screen::get()->clean();
tiled_bg_->render();
game_logo_->render();
renderPlayers();
renderStartPrompt();
renderCopyright();
tiled_bg_->render();
game_logo_->render();
renderPlayers();
renderStartPrompt();
renderCopyright();
define_buttons_->render();
fade_->render();
define_buttons_->render();
fade_->render();
Screen::get()->render();
Screen::get()->render();
}
// Comprueba los eventos
void Title::checkEvents()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
void Title::checkEvents() {
SDL_Event event;
while (SDL_PollEvent(&event)) {
#ifdef DEBUG
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 1)
{
static Color color = param.title.bg_color;
switch (event.key.key)
{
case SDLK_A:
if (color.r < 255)
++color.r;
break;
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 1) {
static Color color = param.title.bg_color;
switch (event.key.key) {
case SDLK_A:
if (color.r < 255)
++color.r;
break;
case SDLK_Z:
if (color.r > 0)
--color.r;
break;
case SDLK_Z:
if (color.r > 0)
--color.r;
break;
case SDLK_S:
if (color.g < 255)
++color.g;
break;
case SDLK_S:
if (color.g < 255)
++color.g;
break;
case SDLK_X:
if (color.g > 0)
--color.g;
break;
case SDLK_X:
if (color.g > 0)
--color.g;
break;
case SDLK_D:
if (color.b < 255)
++color.b;
break;
case SDLK_D:
if (color.b < 255)
++color.b;
break;
case SDLK_C:
if (color.b > 0)
--color.b;
break;
case SDLK_C:
if (color.b > 0)
--color.b;
break;
case SDLK_F:
if (color.r < 255)
++color.r;
if (color.g < 255)
++color.g;
if (color.b < 255)
++color.b;
break;
case SDLK_F:
if (color.r < 255)
++color.r;
if (color.g < 255)
++color.g;
if (color.b < 255)
++color.b;
break;
case SDLK_V:
if (color.r > 0)
--color.r;
if (color.g > 0)
--color.g;
if (color.b > 0)
--color.b;
break;
case SDLK_V:
if (color.r > 0)
--color.r;
if (color.g > 0)
--color.g;
if (color.b > 0)
--color.b;
break;
default:
break;
}
counter_ = 0;
tiled_bg_->setColor(color);
std::cout << "#"
<< std::hex << std::setw(2) << std::setfill('0') << (int)color.r
<< std::setw(2) << std::setfill('0') << (int)color.g
<< std::setw(2) << std::setfill('0') << (int)color.b
<< std::endl;
}
default:
break;
}
counter_ = 0;
tiled_bg_->setColor(color);
std::cout << "#"
<< std::hex << std::setw(2) << std::setfill('0') << (int)color.r
<< std::setw(2) << std::setfill('0') << (int)color.g
<< std::setw(2) << std::setfill('0') << (int)color.b
<< std::endl;
}
#endif
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 0)
{
switch (event.key.key)
{
case SDLK_1: // Redefine los botones del mando #0
define_buttons_->enable(0);
resetCounter();
break;
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 0) {
switch (event.key.key) {
case SDLK_1: // Redefine los botones del mando #0
define_buttons_->enable(0);
resetCounter();
break;
case SDLK_2: // Redefine los botones del mando #1
define_buttons_->enable(1);
resetCounter();
break;
case SDLK_2: // Redefine los botones del mando #1
define_buttons_->enable(1);
resetCounter();
break;
case SDLK_3: // Intercambia los mandos entre los dos jugadores
swapControllers();
resetCounter();
break;
case SDLK_3: // Intercambia los mandos entre los dos jugadores
swapControllers();
resetCounter();
break;
case SDLK_4: // Intercambia la asignación del teclado
swapKeyboard();
resetCounter();
break;
case SDLK_4: // Intercambia la asignación del teclado
swapKeyboard();
resetCounter();
break;
case SDLK_5: // Muestra la asignación de mandos y teclado
showControllers();
resetCounter();
break;
case SDLK_5: // Muestra la asignación de mandos y teclado
showControllers();
resetCounter();
break;
default:
break;
}
}
default:
break;
}
}
GlobalEvents::check(event);
define_buttons_->checkEvents(event);
}
GlobalEvents::check(event);
define_buttons_->checkEvents(event);
}
}
// Comprueba las entradas
void Title::checkInput()
{
// Comprueba las entradas solo si no se estan definiendo los botones
if (define_buttons_->isEnabled())
return;
void Title::checkInput() {
// Comprueba las entradas solo si no se estan definiendo los botones
if (define_buttons_->isEnabled())
return;
Input::get()->update();
Input::get()->update();
if (!ServiceMenu::get()->isEnabled())
{
// Comprueba todos los métodos de control
for (const auto &CONTROLLER : Options::controllers)
{
// Boton START
if (Input::get()->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index))
{
if ((state_ != TitleState::LOGO_ANIMATING || ALLOW_TITLE_ANIMATION_SKIP))
{
if (CONTROLLER.player_id == 1)
{
if (!player1_start_pressed_)
{
player1_start_pressed_ = true;
getPlayer(1)->setPlayingState(PlayerState::TITLE_ANIMATION);
setState(TitleState::START_HAS_BEEN_PRESSED);
counter_ = 0;
}
}
if (!ServiceMenu::get()->isEnabled()) {
// Comprueba todos los métodos de control
for (const auto &CONTROLLER : Options::controllers) {
// Boton START
if (Input::get()->checkInput(InputAction::START, INPUT_DO_NOT_ALLOW_REPEAT, CONTROLLER.type, CONTROLLER.index)) {
if ((state_ != TitleState::LOGO_ANIMATING || ALLOW_TITLE_ANIMATION_SKIP)) {
if (CONTROLLER.player_id == 1) {
if (!player1_start_pressed_) {
player1_start_pressed_ = true;
getPlayer(1)->setPlayingState(PlayerState::TITLE_ANIMATION);
setState(TitleState::START_HAS_BEEN_PRESSED);
counter_ = 0;
}
}
if (CONTROLLER.player_id == 2)
{
if (!player2_start_pressed_)
{
player2_start_pressed_ = true;
getPlayer(2)->setPlayingState(PlayerState::TITLE_ANIMATION);
setState(TitleState::START_HAS_BEEN_PRESSED);
counter_ = 0;
}
}
}
}
}
}
if (CONTROLLER.player_id == 2) {
if (!player2_start_pressed_) {
player2_start_pressed_ = true;
getPlayer(2)->setPlayingState(PlayerState::TITLE_ANIMATION);
setState(TitleState::START_HAS_BEEN_PRESSED);
counter_ = 0;
}
}
}
}
}
}
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
GlobalInputs::check();
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
GlobalInputs::check();
}
// Bucle para el titulo del juego
void Title::run()
{
while (Section::name == Section::Name::TITLE)
{
checkInput();
update();
checkEvents(); // Tiene que ir antes del render
render();
}
void Title::run() {
while (Section::name == Section::Name::TITLE) {
checkInput();
update();
checkEvents(); // Tiene que ir antes del render
render();
}
}
// Reinicia el contador interno
void Title::resetCounter() { counter_ = 0; }
// Intercambia la asignación de mandos a los jugadores
void Title::swapControllers()
{
if (Input::get()->getNumControllers() == 0)
return;
void Title::swapControllers() {
if (Input::get()->getNumControllers() == 0)
return;
Options::swapControllers();
showControllers();
Options::swapControllers();
showControllers();
}
// Intercambia el teclado de jugador
void Title::swapKeyboard()
{
Options::swapKeyboard();
std::string text = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(Options::getPlayerWhoUsesKeyboard()) + ": " + Lang::getText("[DEFINE_BUTTONS] KEYBOARD");
Notifier::get()->show({text});
void Title::swapKeyboard() {
Options::swapKeyboard();
std::string text = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(Options::getPlayerWhoUsesKeyboard()) + ": " + Lang::getText("[DEFINE_BUTTONS] KEYBOARD");
Notifier::get()->show({text});
}
// Muestra información sobre los controles y los jugadores
void Title::showControllers()
{
// Crea vectores de texto vacíos para un número máximo de mandos
constexpr size_t NUM_CONTROLLERS = 2;
std::vector<std::string> text(NUM_CONTROLLERS);
std::vector<int> player_controller_index(NUM_CONTROLLERS, -1);
void Title::showControllers() {
// Crea vectores de texto vacíos para un número máximo de mandos
constexpr size_t NUM_CONTROLLERS = 2;
std::vector<std::string> text(NUM_CONTROLLERS);
std::vector<int> player_controller_index(NUM_CONTROLLERS, -1);
// Obtiene de cada jugador el índice del mando que tiene asignado
for (size_t i = 0; i < NUM_CONTROLLERS; ++i)
{
// Ejemplo: el jugador 1 tiene el mando 2
player_controller_index.at(Options::controllers.at(i).player_id - 1) = i;
}
// Obtiene de cada jugador el índice del mando que tiene asignado
for (size_t i = 0; i < NUM_CONTROLLERS; ++i) {
// Ejemplo: el jugador 1 tiene el mando 2
player_controller_index.at(Options::controllers.at(i).player_id - 1) = i;
}
// Genera el texto correspondiente
for (size_t i = 0; i < NUM_CONTROLLERS; ++i)
{
const size_t index = player_controller_index.at(i);
if (Options::controllers.at(index).plugged)
{
text.at(i) = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(i + 1) + ": " + Options::controllers.at(index).name;
}
}
// Genera el texto correspondiente
for (size_t i = 0; i < NUM_CONTROLLERS; ++i) {
const size_t index = player_controller_index.at(i);
if (Options::controllers.at(index).plugged) {
text.at(i) = Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(i + 1) + ": " + Options::controllers.at(index).name;
}
}
// Muestra la notificación
Notifier::get()->show({text.at(0), text.at(1)});
// Muestra la notificación
Notifier::get()->show({text.at(0), text.at(1)});
}
// Actualiza el fade
void Title::updateFade()
{
fade_->update();
if (fade_->hasEnded())
{
const int COMBO = (player1_start_pressed_ ? 1 : 0) | (player2_start_pressed_ ? 2 : 0);
void Title::updateFade() {
fade_->update();
if (fade_->hasEnded()) {
const int COMBO = (player1_start_pressed_ ? 1 : 0) | (player2_start_pressed_ ? 2 : 0);
switch (COMBO)
{
case 0: // Ningún jugador ha pulsado Start
Section::name = next_section_;
break;
switch (COMBO) {
case 0: // Ningún jugador ha pulsado Start
Section::name = next_section_;
break;
case 1: // Solo el jugador 1 ha pulsado Start
Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_1P;
Audio::get()->stopMusic();
break;
case 1: // Solo el jugador 1 ha pulsado Start
Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_1P;
Audio::get()->stopMusic();
break;
case 2: // Solo el jugador 2 ha pulsado Start
Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_2P;
Audio::get()->stopMusic();
break;
case 2: // Solo el jugador 2 ha pulsado Start
Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_2P;
Audio::get()->stopMusic();
break;
case 3: // Ambos jugadores han pulsado Start
Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_BOTH;
Audio::get()->stopMusic();
break;
}
}
case 3: // Ambos jugadores han pulsado Start
Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_BOTH;
Audio::get()->stopMusic();
break;
}
}
}
// Actualiza el estado
void Title::updateState()
{
// Establece la lógica según el estado
switch (state_)
{
case TitleState::LOGO_ANIMATING:
{
game_logo_->update();
if (game_logo_->hasFinished())
{
setState(TitleState::LOGO_FINISHED);
}
break;
}
case TitleState::LOGO_FINISHED:
{
// El contador solo sube si no estamos definiendo botones
counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1;
void Title::updateState() {
// Establece la lógica según el estado
switch (state_) {
case TitleState::LOGO_ANIMATING: {
game_logo_->update();
if (game_logo_->hasFinished()) {
setState(TitleState::LOGO_FINISHED);
}
break;
}
case TitleState::LOGO_FINISHED: {
// El contador solo sube si no estamos definiendo botones
counter_ = define_buttons_->isEnabled() ? 0 : counter_ + 1;
// Actualiza el logo con el título del juego
game_logo_->update();
// Actualiza el logo con el título del juego
game_logo_->update();
// Actualiza el mosaico de fondo
tiled_bg_->update();
// Actualiza el mosaico de fondo
tiled_bg_->update();
if (counter_ == param.title.title_duration)
{
// El menu ha hecho time out
fade_->setPostDuration(0);
fade_->activate();
selection_ = Section::Options::TITLE_TIME_OUT;
}
if (counter_ == param.title.title_duration) {
// El menu ha hecho time out
fade_->setPostDuration(0);
fade_->activate();
selection_ = Section::Options::TITLE_TIME_OUT;
}
break;
}
case TitleState::START_HAS_BEEN_PRESSED:
{
// Actualiza el logo con el título del juego
game_logo_->update();
break;
}
case TitleState::START_HAS_BEEN_PRESSED: {
// Actualiza el logo con el título del juego
game_logo_->update();
// Actualiza el mosaico de fondo
tiled_bg_->update();
// Actualiza el mosaico de fondo
tiled_bg_->update();
if (counter_ == 100)
{
fade_->activate();
}
++counter_;
break;
}
if (counter_ == 100) {
fade_->activate();
}
++counter_;
break;
}
default:
break;
}
default:
break;
}
}
void Title::updateStartPrompt()
{
constexpr Uint32 LOGO_BLINK_PERIOD = 833; // milisegundos
constexpr Uint32 LOGO_BLINK_ON_TIME = 583; // 833 - 250
void Title::updateStartPrompt() {
constexpr Uint32 LOGO_BLINK_PERIOD = 833; // milisegundos
constexpr Uint32 LOGO_BLINK_ON_TIME = 583; // 833 - 250
constexpr Uint32 START_BLINK_PERIOD = 167;
constexpr Uint32 START_BLINK_ON_TIME = 83; // 167 - 83
constexpr Uint32 START_BLINK_PERIOD = 167;
constexpr Uint32 START_BLINK_ON_TIME = 83; // 167 - 83
Uint32 time_ms = SDL_GetTicks();
bool condition_met = false;
Uint32 time_ms = SDL_GetTicks();
bool condition_met = false;
if (!define_buttons_->isEnabled())
{
switch (state_)
{
case TitleState::LOGO_FINISHED:
condition_met = (time_ms % LOGO_BLINK_PERIOD) >= (LOGO_BLINK_PERIOD - LOGO_BLINK_ON_TIME);
break;
if (!define_buttons_->isEnabled()) {
switch (state_) {
case TitleState::LOGO_FINISHED:
condition_met = (time_ms % LOGO_BLINK_PERIOD) >= (LOGO_BLINK_PERIOD - LOGO_BLINK_ON_TIME);
break;
case TitleState::START_HAS_BEEN_PRESSED:
condition_met = (time_ms % START_BLINK_PERIOD) >= (START_BLINK_PERIOD - START_BLINK_ON_TIME);
break;
case TitleState::START_HAS_BEEN_PRESSED:
condition_met = (time_ms % START_BLINK_PERIOD) >= (START_BLINK_PERIOD - START_BLINK_ON_TIME);
break;
default:
break;
}
}
default:
break;
}
}
should_render_start_prompt = condition_met;
should_render_start_prompt = condition_met;
}
void Title::renderStartPrompt()
{
if (should_render_start_prompt)
{
text_->writeDX(TEXT_CENTER | TEXT_SHADOW,
param.game.game_area.center_x,
param.title.press_start_position,
Lang::getText("[TITLE] PRESS_BUTTON_TO_PLAY"),
1,
NO_TEXT_COLOR,
1,
TITLE_SHADOW_TEXT_COLOR);
}
void Title::renderStartPrompt() {
if (should_render_start_prompt) {
text_->writeDX(TEXT_CENTER | TEXT_SHADOW,
param.game.game_area.center_x,
param.title.press_start_position,
Lang::getText("[TITLE] PRESS_BUTTON_TO_PLAY"),
1,
NO_TEXT_COLOR,
1,
TITLE_SHADOW_TEXT_COLOR);
}
}
void Title::renderCopyright()
{
if (state_ != TitleState::LOGO_ANIMATING)
{
// Mini logo
mini_logo_sprite_->render();
void Title::renderCopyright() {
if (state_ != TitleState::LOGO_ANIMATING) {
// Mini logo
mini_logo_sprite_->render();
// Texto con el copyright
text_->writeDX(TEXT_CENTER | TEXT_SHADOW,
param.game.game_area.center_x,
anchor_.copyright_text,
TEXT_COPYRIGHT,
1,
NO_TEXT_COLOR,
1,
TITLE_SHADOW_TEXT_COLOR);
}
// Texto con el copyright
text_->writeDX(TEXT_CENTER | TEXT_SHADOW,
param.game.game_area.center_x,
anchor_.copyright_text,
TEXT_COPYRIGHT,
1,
NO_TEXT_COLOR,
1,
TITLE_SHADOW_TEXT_COLOR);
}
}
// Cambia el estado
void Title::setState(TitleState state)
{
if (state_ == state)
return;
void Title::setState(TitleState state) {
if (state_ == state)
return;
state_ = state;
switch (state_)
{
case TitleState::LOGO_ANIMATING:
break;
case TitleState::LOGO_FINISHED:
Audio::get()->playMusic("title.ogg");
break;
case TitleState::START_HAS_BEEN_PRESSED:
Audio::get()->fadeOutMusic(1500);
break;
}
state_ = state;
switch (state_) {
case TitleState::LOGO_ANIMATING:
break;
case TitleState::LOGO_FINISHED:
Audio::get()->playMusic("title.ogg");
break;
case TitleState::START_HAS_BEEN_PRESSED:
Audio::get()->fadeOutMusic(1500);
break;
}
}
// Inicializa los jugadores
void Title::initPlayers()
{
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures; // Vector con todas las texturas de los jugadores;
std::vector<std::vector<std::string>> player_animations; // Vector con las animaciones del jugador
void Title::initPlayers() {
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures; // Vector con todas las texturas de los jugadores;
std::vector<std::vector<std::string>> player_animations; // Vector con las animaciones del jugador
// Texturas - Player1
{
std::vector<std::shared_ptr<Texture>> player_texture;
player_texture.emplace_back(Resource::get()->getTexture("player1.gif"));
player_texture.emplace_back(Resource::get()->getTexture("player1_power.png"));
player_textures.push_back(player_texture);
}
// Texturas - Player1
{
std::vector<std::shared_ptr<Texture>> player_texture;
player_texture.emplace_back(Resource::get()->getTexture("player1.gif"));
player_texture.emplace_back(Resource::get()->getTexture("player1_power.png"));
player_textures.push_back(player_texture);
}
// Texturas - Player2
{
std::vector<std::shared_ptr<Texture>> player_texture;
player_texture.emplace_back(Resource::get()->getTexture("player2.gif"));
player_texture.emplace_back(Resource::get()->getTexture("player2_power.png"));
player_textures.push_back(player_texture);
}
// Texturas - Player2
{
std::vector<std::shared_ptr<Texture>> player_texture;
player_texture.emplace_back(Resource::get()->getTexture("player2.gif"));
player_texture.emplace_back(Resource::get()->getTexture("player2_power.png"));
player_textures.push_back(player_texture);
}
// Animaciones -- Jugador
{
player_animations.emplace_back(Resource::get()->getAnimation("player.ani"));
player_animations.emplace_back(Resource::get()->getAnimation("player_power.ani"));
}
// Animaciones -- Jugador
{
player_animations.emplace_back(Resource::get()->getAnimation("player.ani"));
player_animations.emplace_back(Resource::get()->getAnimation("player_power.ani"));
}
// Crea los dos jugadores
constexpr int PLAYER_WIDTH = 32;
constexpr int PLAYER_HEIGHT = 32;
const int Y = param.title.press_start_position - (PLAYER_HEIGHT / 2);
constexpr bool DEMO = false;
players_.emplace_back(std::make_unique<Player>(1, param.game.game_area.center_x - (PLAYER_WIDTH / 2), Y, DEMO, param.game.play_area.rect, player_textures.at(0), player_animations));
players_.back()->setPlayingState(PlayerState::TITLE_HIDDEN);
// Crea los dos jugadores
constexpr int PLAYER_WIDTH = 32;
constexpr int PLAYER_HEIGHT = 32;
const int Y = param.title.press_start_position - (PLAYER_HEIGHT / 2);
constexpr bool DEMO = false;
players_.emplace_back(std::make_unique<Player>(1, param.game.game_area.center_x - (PLAYER_WIDTH / 2), Y, DEMO, param.game.play_area.rect, player_textures.at(0), player_animations));
players_.back()->setPlayingState(PlayerState::TITLE_HIDDEN);
players_.emplace_back(std::make_unique<Player>(2, param.game.game_area.center_x - (PLAYER_WIDTH / 2), Y, DEMO, param.game.play_area.rect, player_textures.at(1), player_animations));
players_.back()->setPlayingState(PlayerState::TITLE_HIDDEN);
players_.emplace_back(std::make_unique<Player>(2, param.game.game_area.center_x - (PLAYER_WIDTH / 2), Y, DEMO, param.game.play_area.rect, player_textures.at(1), player_animations));
players_.back()->setPlayingState(PlayerState::TITLE_HIDDEN);
}
// Actualza los jugadores
void Title::updatePlayers()
{
for (auto &player : players_)
{
player->update();
}
void Title::updatePlayers() {
for (auto &player : players_) {
player->update();
}
}
// Renderiza los jugadores
void Title::renderPlayers()
{
for (auto const &player : players_)
{
player->render();
}
void Title::renderPlayers() {
for (auto const &player : players_) {
player->render();
}
}
// Obtiene un jugador a partir de su "id"
std::shared_ptr<Player> Title::getPlayer(int id)
{
auto it = std::find_if(players_.begin(), players_.end(), [id](const auto &player)
{ return player->getId() == id; });
std::shared_ptr<Player> Title::getPlayer(int id) {
auto it = std::find_if(players_.begin(), players_.end(), [id](const auto &player) { return player->getId() == id; });
if (it != players_.end())
{
return *it;
}
return nullptr;
if (it != players_.end()) {
return *it;
}
return nullptr;
}

View File

@@ -1,10 +1,11 @@
#pragma once
#include <SDL3/SDL.h> // Para Uint32
#include <memory> // Para unique_ptr, shared_ptr
#include <SDL3/SDL.h> // Para Uint32
#include <memory> // Para unique_ptr, shared_ptr
#include <vector>
#include "section.h" // Para Options
#include "section.h" // Para Options
class DefineButtons;
class Fade;
@@ -21,78 +22,75 @@ constexpr const char TEXT_COPYRIGHT[] = "@2020,2025 JailDesigner";
constexpr bool ALLOW_TITLE_ANIMATION_SKIP = false;
/*
Clase que gestiona el estado de título/menú principal del juego.
Responsable de mostrar el logo, el fondo animado y gestionar la entrada para comenzar la partida.
No permite saltar la animación del título salvo que se cambie el define.
Clase que gestiona el estado de título/menú principal del juego.
Responsable de mostrar el logo, el fondo animado y gestionar la entrada para comenzar la partida.
No permite saltar la animación del título salvo que se cambie el define.
*/
// Clase Title
class Title
{
public:
// --- Constructores y destructor ---
Title();
~Title();
class Title {
public:
// --- Constructores y destructor ---
Title();
~Title();
// --- Método principal ---
void run(); // Bucle para el título del juego
// --- Método principal ---
void run(); // Bucle para el título del juego
private:
// --- Enumeraciones ---
enum class TitleState
{
LOGO_ANIMATING, // El logo está animándose
LOGO_FINISHED, // El logo ha terminado de animarse
START_HAS_BEEN_PRESSED, // Se ha pulsado el botón de start
};
private:
// --- Enumeraciones ---
enum class TitleState {
LOGO_ANIMATING, // El logo está animándose
LOGO_FINISHED, // El logo ha terminado de animarse
START_HAS_BEEN_PRESSED, // Se ha pulsado el botón de start
};
// --- Estructura para definir anclas ---
struct Anchor
{
int mini_logo;
int copyright_text;
};
// --- Estructura para definir anclas ---
struct Anchor {
int mini_logo;
int copyright_text;
};
// --- Objetos y punteros ---
std::shared_ptr<Text> text_; // Objeto de texto para escribir en pantalla
std::unique_ptr<Fade> fade_; // Fundido en pantalla
std::unique_ptr<TiledBG> tiled_bg_; // Fondo animado de tiles
std::unique_ptr<GameLogo> game_logo_; // Logo del juego
std::unique_ptr<Sprite> mini_logo_sprite_; // Logo JailGames mini
std::unique_ptr<DefineButtons> define_buttons_; // Definición de botones del joystick
std::vector<std::shared_ptr<Player>> players_; // Vector de jugadores
// --- Objetos y punteros ---
std::shared_ptr<Text> text_; // Objeto de texto para escribir en pantalla
std::unique_ptr<Fade> fade_; // Fundido en pantalla
std::unique_ptr<TiledBG> tiled_bg_; // Fondo animado de tiles
std::unique_ptr<GameLogo> game_logo_; // Logo del juego
std::unique_ptr<Sprite> mini_logo_sprite_; // Logo JailGames mini
std::unique_ptr<DefineButtons> define_buttons_; // Definición de botones del joystick
std::vector<std::shared_ptr<Player>> players_; // Vector de jugadores
// --- Variables de estado ---
int counter_ = 0; // Temporizador para la pantalla de título
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad
Section::Name next_section_; // Siguiente sección a cargar
Section::Options selection_ = Section::Options::TITLE_TIME_OUT; // Opción elegida en el título
int num_controllers_; // Número de mandos conectados
TitleState state_; // Estado actual de la sección
bool should_render_start_prompt = false; // Indica si se muestra o no el texto de PRESS START BUTTON TO PLAY
bool player1_start_pressed_ = false; // Indica si se ha pulsdo el boton de empezar a jugar para el jugador 1
bool player2_start_pressed_ = false; // Indica si se ha pulsdo el boton de empezar a jugar para el jugador 2
// --- Variables de estado ---
int counter_ = 0; // Temporizador para la pantalla de título
Uint64 ticks_ = 0; // Contador de ticks para ajustar la velocidad
Section::Name next_section_; // Siguiente sección a cargar
Section::Options selection_ = Section::Options::TITLE_TIME_OUT; // Opción elegida en el título
int num_controllers_; // Número de mandos conectados
TitleState state_; // Estado actual de la sección
bool should_render_start_prompt = false; // Indica si se muestra o no el texto de PRESS START BUTTON TO PLAY
bool player1_start_pressed_ = false; // Indica si se ha pulsdo el boton de empezar a jugar para el jugador 1
bool player2_start_pressed_ = false; // Indica si se ha pulsdo el boton de empezar a jugar para el jugador 2
// -- Variables de diseño ---
Anchor anchor_; // Anclas para definir la posición de los elementos del titulo
// -- Variables de diseño ---
Anchor anchor_; // Anclas para definir la posición de los elementos del titulo
// --- Métodos internos ---
void update(); // Actualiza las variables del objeto
void render(); // Dibuja el objeto en pantalla
void checkEvents(); // Comprueba los eventos
void checkInput(); // Comprueba las entradas
void resetCounter(); // Reinicia el contador interno
void swapControllers(); // Intercambia la asignación de mandos a los jugadores
void swapKeyboard(); // Intercambia el teclado de jugador
void showControllers(); // Muestra información sobre los controles y los jugadores
void updateFade(); // Actualiza el efecto de fundido (fade in/out)
void updateState(); // Actualiza el estado actual del título
void updateStartPrompt(); // Actualiza el mensaje de "Pulsa Start"
void renderStartPrompt(); // Dibuja el mensaje de "Pulsa Start" en pantalla
void renderCopyright(); // Dibuja el aviso de copyright
void setState(TitleState state); // Cambia el estado del título
void initPlayers(); // Inicializa los jugadores
void renderPlayers(); // Renderiza los jugadores
void updatePlayers(); // Actualza los jugadores
std::shared_ptr<Player> getPlayer(int id); // Obtiene un jugador a partir de su "id"
// --- Métodos internos ---
void update(); // Actualiza las variables del objeto
void render(); // Dibuja el objeto en pantalla
void checkEvents(); // Comprueba los eventos
void checkInput(); // Comprueba las entradas
void resetCounter(); // Reinicia el contador interno
void swapControllers(); // Intercambia la asignación de mandos a los jugadores
void swapKeyboard(); // Intercambia el teclado de jugador
void showControllers(); // Muestra información sobre los controles y los jugadores
void updateFade(); // Actualiza el efecto de fundido (fade in/out)
void updateState(); // Actualiza el estado actual del título
void updateStartPrompt(); // Actualiza el mensaje de "Pulsa Start"
void renderStartPrompt(); // Dibuja el mensaje de "Pulsa Start" en pantalla
void renderCopyright(); // Dibuja el aviso de copyright
void setState(TitleState state); // Cambia el estado del título
void initPlayers(); // Inicializa los jugadores
void renderPlayers(); // Renderiza los jugadores
void updatePlayers(); // Actualza los jugadores
std::shared_ptr<Player> getPlayer(int id); // Obtiene un jugador a partir de su "id"
};