forked from jaildesigner-jailgames/jaildoctors_dilemma
migrant LoadingScreen a delta_time i estats
This commit is contained in:
@@ -32,8 +32,13 @@ enum class Options {
|
|||||||
TITLE_WITHOUT_LOADING_SCREEN // Al título sin pantalla de carga
|
TITLE_WITHOUT_LOADING_SCREEN // Al título sin pantalla de carga
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- Variables de estado globales (inline C++17) ---
|
// --- Variables de estado globales ---
|
||||||
|
#ifndef _DEBUG
|
||||||
inline Scene current = Scene::LOGO; // Escena actual
|
inline Scene current = Scene::LOGO; // Escena actual
|
||||||
inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual
|
inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual
|
||||||
|
#else
|
||||||
|
inline Scene current = Scene::LOADING_SCREEN; // Escena actual
|
||||||
|
inline Options options = Options::LOGO_TO_LOADING_SCREEN; // Opciones de la escena actual
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace SceneManager
|
} // namespace SceneManager
|
||||||
|
|||||||
@@ -21,7 +21,11 @@ LoadingScreen::LoadingScreen()
|
|||||||
color_loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")),
|
color_loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")),
|
||||||
mono_loading_screen_sprite_(std::make_shared<SurfaceSprite>(mono_loading_screen_surface_, 0, 0, mono_loading_screen_surface_->getWidth(), mono_loading_screen_surface_->getHeight())),
|
mono_loading_screen_sprite_(std::make_shared<SurfaceSprite>(mono_loading_screen_surface_, 0, 0, mono_loading_screen_surface_->getWidth(), mono_loading_screen_surface_->getHeight())),
|
||||||
color_loading_screen_sprite_(std::make_shared<SurfaceSprite>(color_loading_screen_surface_, 0, 0, color_loading_screen_surface_->getWidth(), color_loading_screen_surface_->getHeight())),
|
color_loading_screen_sprite_(std::make_shared<SurfaceSprite>(color_loading_screen_surface_, 0, 0, color_loading_screen_surface_->getWidth(), color_loading_screen_surface_->getHeight())),
|
||||||
screen_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)) {
|
screen_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
|
||||||
|
delta_timer_(std::make_unique<DeltaTimer>()),
|
||||||
|
state_(LoadingState::PRE_LOADING),
|
||||||
|
state_time_(0.0f),
|
||||||
|
load_rect_{0, 0, 0, 1.0f} {
|
||||||
// Configura la superficie donde se van a pintar los sprites
|
// Configura la superficie donde se van a pintar los sprites
|
||||||
screen_surface_->clear(static_cast<Uint8>(PaletteColor::WHITE));
|
screen_surface_->clear(static_cast<Uint8>(PaletteColor::WHITE));
|
||||||
|
|
||||||
@@ -29,16 +33,8 @@ LoadingScreen::LoadingScreen()
|
|||||||
SceneManager::current = SceneManager::Scene::LOADING_SCREEN;
|
SceneManager::current = SceneManager::Scene::LOADING_SCREEN;
|
||||||
SceneManager::options = SceneManager::Options::NONE;
|
SceneManager::options = SceneManager::Options::NONE;
|
||||||
|
|
||||||
// Establece el orden de las lineas para imitar el direccionamiento de memoria del spectrum
|
// Inicializa el array de índices de líneas
|
||||||
for (int i = 0; i < 192; ++i) {
|
initLineIndexArray();
|
||||||
if (i < 64) { // Primer bloque de 2K
|
|
||||||
line_index_[i] = ((i % 8) * 8) + (i / 8);
|
|
||||||
} else if (i < 128) { // Segundo bloque de 2K
|
|
||||||
line_index_[i] = 64 + ((i % 8) * 8) + ((i - 64) / 8);
|
|
||||||
} else { // Tercer bloque de 2K
|
|
||||||
line_index_[i] = 128 + ((i % 8) * 8) + ((i - 128) / 8);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cambia el color del borde
|
// Cambia el color del borde
|
||||||
Screen::get()->setBorderColor(stringToColor("black"));
|
Screen::get()->setBorderColor(stringToColor("black"));
|
||||||
@@ -62,63 +58,141 @@ void LoadingScreen::checkInput() {
|
|||||||
globalInputs::check();
|
globalInputs::check();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona el contador de carga
|
// Inicializa el array de índices de líneas (imita el direccionamiento de memoria del Spectrum)
|
||||||
void LoadingScreen::updateLoad() {
|
void LoadingScreen::initLineIndexArray() {
|
||||||
// Primera parte de la carga, la parte en blanco y negro
|
for (int i = 0; i < MONO_TOTAL_LINES; ++i) {
|
||||||
if (loading_first_part_) {
|
if (i < 64) { // Primer bloque de 2K
|
||||||
// Cada 5 pasos el load_counter_ se incrementa en uno
|
line_index_[i] = ((i % 8) * 8) + (i / 8);
|
||||||
constexpr int NUM_STEPS = 5;
|
} else if (i < 128) { // Segundo bloque de 2K
|
||||||
constexpr int STEPS = 51;
|
line_index_[i] = 64 + ((i % 8) * 8) + ((i - 64) / 8);
|
||||||
load_counter_ = counter_ / NUM_STEPS;
|
} else { // Tercer bloque de 2K
|
||||||
|
line_index_[i] = 128 + ((i % 8) * 8) + ((i - 128) / 8);
|
||||||
if (load_counter_ < 192) {
|
|
||||||
load_rect_.x = STEPS * (counter_ % NUM_STEPS);
|
|
||||||
load_rect_.y = line_index_[load_counter_];
|
|
||||||
mono_loading_screen_sprite_->setClip(load_rect_);
|
|
||||||
mono_loading_screen_sprite_->setPosition(load_rect_);
|
|
||||||
}
|
|
||||||
// Una vez actualizadas las 192 lineas, pasa a la segunda fase de la carga
|
|
||||||
else if (load_counter_ == 192) {
|
|
||||||
loading_first_part_ = false;
|
|
||||||
load_counter_ = 0;
|
|
||||||
load_rect_ = {0, 0, 16, 8};
|
|
||||||
color_loading_screen_sprite_->setClip(load_rect_);
|
|
||||||
color_loading_screen_sprite_->setPosition(load_rect_);
|
|
||||||
JA_PlayMusic(Resource::get()->getMusic("loading_sound3.ogg"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Segunda parte de la carga, la parte de los bloques en color
|
|
||||||
else {
|
|
||||||
load_counter_ += 2;
|
|
||||||
load_rect_.x = (load_counter_ * 8) % 256;
|
|
||||||
load_rect_.y = (load_counter_ / 32) * 8;
|
|
||||||
color_loading_screen_sprite_->setClip(load_rect_);
|
|
||||||
color_loading_screen_sprite_->setPosition(load_rect_);
|
|
||||||
|
|
||||||
// Comprueba si ha terminado la intro
|
|
||||||
if (load_counter_ >= 768) {
|
|
||||||
SceneManager::current = SceneManager::Scene::TITLE;
|
|
||||||
SceneManager::options = SceneManager::Options::TITLE_WITH_LOADING_SCREEN;
|
|
||||||
JA_StopMusic();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gestiona el contador interno
|
// Transiciona a un nuevo estado
|
||||||
void LoadingScreen::updateCounter() {
|
void LoadingScreen::transitionToState(LoadingState new_state) {
|
||||||
(pre_counter_ >= 50) ? counter_++ : pre_counter_++;
|
state_ = new_state;
|
||||||
|
state_time_ = 0.0f;
|
||||||
|
|
||||||
if (counter_ == 1) {
|
// Acciones específicas al entrar en cada estado
|
||||||
JA_PlayMusic(Resource::get()->getMusic("loading_sound2.ogg"));
|
switch (new_state) {
|
||||||
|
case LoadingState::PRE_LOADING:
|
||||||
|
// No hay acción específica
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LoadingState::LOADING_MONO:
|
||||||
|
// Reproducir sonido de carga monocromática
|
||||||
|
JA_PlayMusic(Resource::get()->getMusic("loading_sound2.ogg"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LoadingState::LOADING_COLOR:
|
||||||
|
// Reproducir sonido de carga en color
|
||||||
|
JA_PlayMusic(Resource::get()->getMusic("loading_sound3.ogg"));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LoadingState::COMPLETE:
|
||||||
|
// Transicionar a la pantalla de título
|
||||||
|
SceneManager::current = SceneManager::Scene::TITLE;
|
||||||
|
SceneManager::options = SceneManager::Options::TITLE_WITH_LOADING_SCREEN;
|
||||||
|
JA_StopMusic();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Actualiza el estado actual
|
||||||
|
void LoadingScreen::updateState(float delta_time) {
|
||||||
|
state_time_ += delta_time;
|
||||||
|
|
||||||
|
// Solo PRE_LOADING transiciona por tiempo
|
||||||
|
// LOADING_MONO y LOADING_COLOR transicionan cuando completan su progreso
|
||||||
|
if (state_ == LoadingState::PRE_LOADING) {
|
||||||
|
if (state_time_ >= PRE_LOADING_DURATION) {
|
||||||
|
transitionToState(LoadingState::LOADING_MONO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestiona la carga monocromática (time-based simplificado)
|
||||||
|
void LoadingScreen::updateMonoLoad(float delta_time) {
|
||||||
|
// Calcular progreso lineal (0.0 - 1.0)
|
||||||
|
float progress = state_time_ / LOADING_MONO_DURATION;
|
||||||
|
progress = std::min(progress, 1.0f);
|
||||||
|
|
||||||
|
// Calcular paso total actual (0-959)
|
||||||
|
const int total_steps = MONO_TOTAL_LINES * MONO_STEPS_PER_LINE; // 192 * 5 = 960
|
||||||
|
const int current_step = static_cast<int>(progress * total_steps);
|
||||||
|
|
||||||
|
// Calcular línea y sub-paso
|
||||||
|
const int current_line = current_step / MONO_STEPS_PER_LINE; // 0-191
|
||||||
|
const int current_substep = current_step % MONO_STEPS_PER_LINE; // 0-4
|
||||||
|
|
||||||
|
// Verificar si ha completado todas las líneas
|
||||||
|
if (current_line >= MONO_TOTAL_LINES) {
|
||||||
|
transitionToState(LoadingState::LOADING_COLOR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calcular rectángulo de clip (con floats para mayor precisión)
|
||||||
|
const float texture_width = static_cast<float>(mono_loading_screen_surface_->getWidth());
|
||||||
|
const float clip_width = texture_width / MONO_STEPS_PER_LINE;
|
||||||
|
const float clip_x = current_substep * clip_width;
|
||||||
|
|
||||||
|
load_rect_.x = clip_x;
|
||||||
|
load_rect_.y = static_cast<float>(line_index_[current_line]);
|
||||||
|
load_rect_.w = clip_width;
|
||||||
|
load_rect_.h = 1.0f;
|
||||||
|
|
||||||
|
// Configurar y dibujar sobre screen_surface_
|
||||||
|
mono_loading_screen_sprite_->setClip(load_rect_);
|
||||||
|
mono_loading_screen_sprite_->setPosition(load_rect_);
|
||||||
|
|
||||||
|
auto previous_renderer = Screen::get()->getRendererSurface();
|
||||||
|
Screen::get()->setRendererSurface(screen_surface_);
|
||||||
|
mono_loading_screen_sprite_->render(1, stringToColor("black"));
|
||||||
|
Screen::get()->setRendererSurface(previous_renderer);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gestiona la carga en color (time-based simplificado)
|
||||||
|
void LoadingScreen::updateColorLoad(float delta_time) {
|
||||||
|
// Calcular progreso lineal (0.0 - 1.0)
|
||||||
|
float progress = state_time_ / LOADING_COLOR_DURATION;
|
||||||
|
progress = std::min(progress, 1.0f);
|
||||||
|
|
||||||
|
// Calcular iteración actual (el código original incrementaba de 2 en 2)
|
||||||
|
const int total_iterations = COLOR_TOTAL_BLOCKS / 2; // 768 / 2 = 384 iteraciones
|
||||||
|
const int current_iteration = static_cast<int>(progress * total_iterations);
|
||||||
|
|
||||||
|
// Convertir a bloque (incrementa de 2 en 2, empezando en 2)
|
||||||
|
const int current_block = (current_iteration + 1) * 2;
|
||||||
|
|
||||||
|
// Verificar si ha completado todos los bloques
|
||||||
|
if (current_block >= COLOR_TOTAL_BLOCKS) {
|
||||||
|
transitionToState(LoadingState::COMPLETE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calcular posición del bloque
|
||||||
|
load_rect_.x = static_cast<float>((current_block * COLOR_BLOCK_SPACING) % 256);
|
||||||
|
load_rect_.y = static_cast<float>((current_block / COLOR_BLOCKS_PER_ROW) * COLOR_BLOCK_SPACING);
|
||||||
|
load_rect_.w = static_cast<float>(COLOR_BLOCK_WIDTH);
|
||||||
|
load_rect_.h = static_cast<float>(COLOR_BLOCK_HEIGHT);
|
||||||
|
|
||||||
|
// Configurar y dibujar sobre screen_surface_
|
||||||
|
color_loading_screen_sprite_->setClip(load_rect_);
|
||||||
|
color_loading_screen_sprite_->setPosition(load_rect_);
|
||||||
|
|
||||||
|
auto previous_renderer = Screen::get()->getRendererSurface();
|
||||||
|
Screen::get()->setRendererSurface(screen_surface_);
|
||||||
|
color_loading_screen_sprite_->render();
|
||||||
|
Screen::get()->setRendererSurface(previous_renderer);
|
||||||
|
}
|
||||||
|
|
||||||
// Dibuja la pantalla de carga
|
// Dibuja la pantalla de carga
|
||||||
void LoadingScreen::renderLoad() {
|
void LoadingScreen::renderLoad() {
|
||||||
auto previuos_renderer = Screen::get()->getRendererSurface();
|
// El dibujo incremental ya se realiza en updateMonoLoad() y updateColorLoad()
|
||||||
Screen::get()->setRendererSurface(screen_surface_);
|
// Esta función ya no es necesaria, pero se mantiene por compatibilidad
|
||||||
loading_first_part_ ? mono_loading_screen_sprite_->render(1, stringToColor("black")) : color_loading_screen_sprite_->render();
|
|
||||||
Screen::get()->setRendererSurface(previuos_renderer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja el efecto de carga en el borde
|
// Dibuja el efecto de carga en el borde
|
||||||
@@ -150,15 +224,33 @@ void LoadingScreen::renderBorder() {
|
|||||||
|
|
||||||
// Actualiza las variables
|
// Actualiza las variables
|
||||||
void LoadingScreen::update() {
|
void LoadingScreen::update() {
|
||||||
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
|
// Obtener delta time desde el último frame
|
||||||
if (SDL_GetTicks() - ticks_ > GAME_SPEED) {
|
const float delta_time = delta_timer_->tick();
|
||||||
ticks_ = SDL_GetTicks();
|
|
||||||
checkInput();
|
checkInput(); // Comprueba las entradas
|
||||||
updateCounter();
|
updateState(delta_time); // Actualiza el estado y gestiona transiciones
|
||||||
updateLoad();
|
|
||||||
renderLoad();
|
// Actualizar la carga según el estado actual
|
||||||
Screen::get()->update();
|
switch (state_) {
|
||||||
|
case LoadingState::PRE_LOADING:
|
||||||
|
// No hay animación de carga durante la pausa inicial
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LoadingState::LOADING_MONO:
|
||||||
|
updateMonoLoad(delta_time);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LoadingState::LOADING_COLOR:
|
||||||
|
updateColorLoad(delta_time);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LoadingState::COMPLETE:
|
||||||
|
// No hay más actualizaciones
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderLoad(); // Dibuja la pantalla de carga
|
||||||
|
Screen::get()->update(); // Actualiza el objeto Screen
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dibuja en pantalla
|
// Dibuja en pantalla
|
||||||
|
|||||||
@@ -2,59 +2,66 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#include <memory> // Para shared_ptr
|
#include <array> // Para std::array
|
||||||
class SurfaceSprite; // lines 7-7
|
#include <memory> // Para shared_ptr
|
||||||
class Surface; // lines 8-8
|
|
||||||
|
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||||
|
class SurfaceSprite; // Forward declaration
|
||||||
|
class Surface; // Forward declaration
|
||||||
|
|
||||||
|
// Estados de la secuencia de carga
|
||||||
|
enum class LoadingState {
|
||||||
|
PRE_LOADING, // Pausa inicial antes de empezar
|
||||||
|
LOADING_MONO, // Carga de pantalla monocromática (escaneo de líneas)
|
||||||
|
LOADING_COLOR, // Carga de pantalla en color (bloques)
|
||||||
|
COMPLETE // Carga completa
|
||||||
|
};
|
||||||
|
|
||||||
class LoadingScreen {
|
class LoadingScreen {
|
||||||
|
public:
|
||||||
|
LoadingScreen(); // Constructor
|
||||||
|
~LoadingScreen(); // Destructor
|
||||||
|
void run(); // Bucle principal
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Objetos y punteros
|
// --- Constantes de tiempo (en segundos) ---
|
||||||
|
static constexpr float PRE_LOADING_DURATION = 1.0f; // Pausa inicial
|
||||||
|
static constexpr float LOADING_MONO_DURATION = 16.0f; // Duración total de la carga monocromática
|
||||||
|
static constexpr float LOADING_COLOR_DURATION = 4.0f; // Duración total de la carga en color
|
||||||
|
|
||||||
|
// --- Constantes de geometría ---
|
||||||
|
static constexpr int MONO_TOTAL_LINES = 192; // Total de líneas en carga monocromática
|
||||||
|
static constexpr int MONO_STEPS_PER_LINE = 5; // Pasos de animación por línea
|
||||||
|
static constexpr int COLOR_TOTAL_BLOCKS = 768; // Total de bloques en carga color
|
||||||
|
static constexpr int COLOR_BLOCK_WIDTH = 16; // Ancho del bloque de color
|
||||||
|
static constexpr int COLOR_BLOCK_HEIGHT = 8; // Alto del bloque de color
|
||||||
|
static constexpr int COLOR_BLOCKS_PER_ROW = 32; // Bloques por fila (256 / 8)
|
||||||
|
static constexpr int COLOR_BLOCK_SPACING = 8; // Espaciado entre bloques
|
||||||
|
|
||||||
|
// --- Objetos y punteros ---
|
||||||
std::shared_ptr<Surface> mono_loading_screen_surface_; // Surface con la pantalla de carga en blanco y negro
|
std::shared_ptr<Surface> mono_loading_screen_surface_; // Surface con la pantalla de carga en blanco y negro
|
||||||
std::shared_ptr<Surface> color_loading_screen_surface_; // Surface con la pantalla de carga en color
|
std::shared_ptr<Surface> color_loading_screen_surface_; // Surface con la pantalla de carga en color
|
||||||
std::shared_ptr<SurfaceSprite> mono_loading_screen_sprite_; // SSprite para manejar la textura loadingScreenTexture1
|
std::shared_ptr<SurfaceSprite> mono_loading_screen_sprite_; // SSprite para manejar la textura loadingScreenTexture1
|
||||||
std::shared_ptr<SurfaceSprite> color_loading_screen_sprite_; // SSprite para manejar la textura loadingScreenTexture2
|
std::shared_ptr<SurfaceSprite> color_loading_screen_sprite_; // SSprite para manejar la textura loadingScreenTexture2
|
||||||
std::shared_ptr<Surface> screen_surface_; // Surface para dibujar la pantalla de carga
|
std::shared_ptr<Surface> screen_surface_; // Surface para dibujar la pantalla de carga
|
||||||
|
|
||||||
// Variables
|
// --- Variables de estado ---
|
||||||
int pre_counter_ = 0; // Contador previo para realizar una pausa inicial
|
std::unique_ptr<DeltaTimer> delta_timer_; // Timer para delta time
|
||||||
int counter_ = 0; // Contador
|
LoadingState state_; // Estado actual de la secuencia
|
||||||
Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa
|
float state_time_; // Tiempo acumulado en el estado actual
|
||||||
int load_counter_ = 0; // Contador para controlar las cargas
|
std::array<int, MONO_TOTAL_LINES> line_index_; // El orden en el que se procesan las 192 líneas de la pantalla de carga
|
||||||
bool loading_first_part_ = true; // Para saber en que parte de la carga se encuentra
|
SDL_FRect load_rect_; // Rectángulo para dibujar la pantalla de carga
|
||||||
int line_index_[192]; // El orden en el que se procesan las 192 lineas de la pantalla de carga
|
|
||||||
SDL_FRect load_rect_ = {0, 0, 52, 1}; // Rectangulo para dibujar la pantalla de carga
|
|
||||||
|
|
||||||
// Actualiza las variables
|
// --- Funciones ---
|
||||||
void update();
|
void update(); // Actualiza las variables
|
||||||
|
void render(); // Dibuja en pantalla
|
||||||
// Dibuja en pantalla
|
void checkEvents(); // Comprueba el manejador de eventos
|
||||||
void render();
|
void checkInput(); // Comprueba las entradas
|
||||||
|
void updateState(float delta_time); // Actualiza el estado actual
|
||||||
// Comprueba el manejador de eventos
|
void transitionToState(LoadingState new_state); // Transiciona a un nuevo estado
|
||||||
void checkEvents();
|
void updateMonoLoad(float delta_time); // Gestiona la carga monocromática (time-based)
|
||||||
|
void updateColorLoad(float delta_time); // Gestiona la carga en color (time-based)
|
||||||
// Comprueba las entradas
|
void renderLoad(); // Dibuja la pantalla de carga
|
||||||
void checkInput();
|
void renderBorder(); // Dibuja el efecto de carga en el borde
|
||||||
|
void initLineIndexArray(); // Inicializa el array de índices de líneas
|
||||||
// Gestiona el contador interno
|
|
||||||
void updateCounter();
|
|
||||||
|
|
||||||
// Gestiona el contador de carga
|
|
||||||
void updateLoad();
|
|
||||||
|
|
||||||
// Dibuja la pantalla de carga
|
|
||||||
void renderLoad();
|
|
||||||
|
|
||||||
// Dibuja el efecto de carga en el borde
|
|
||||||
void renderBorder();
|
|
||||||
|
|
||||||
public:
|
|
||||||
// Constructor
|
|
||||||
LoadingScreen();
|
|
||||||
|
|
||||||
// Destructor
|
|
||||||
~LoadingScreen();
|
|
||||||
|
|
||||||
// Bucle principal
|
|
||||||
void run();
|
|
||||||
};
|
};
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "game/scenes/logo.hpp"
|
#include "game/scenes/logo.hpp"
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#include <algorithm> // Para std::clamp
|
#include <algorithm> // Para std::clamp
|
||||||
|
|
||||||
#include "core/input/global_inputs.hpp" // Para check
|
#include "core/input/global_inputs.hpp" // Para check
|
||||||
@@ -105,8 +106,8 @@ void Logo::updateTextureColors() {
|
|||||||
|
|
||||||
case LogoState::DISPLAY: {
|
case LogoState::DISPLAY: {
|
||||||
// Asegurar que ambos logos estén en blanco durante el display
|
// Asegurar que ambos logos estén en blanco durante el display
|
||||||
jailgames_color_ = color_.back(); // BRIGHT_WHITE
|
jailgames_color_ = color_.back(); // BRIGHT_WHITE
|
||||||
since_1998_color_ = color_.back(); // BRIGHT_WHITE
|
since_1998_color_ = color_.back(); // BRIGHT_WHITE
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,20 +2,21 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
#include <memory> // Para shared_ptr
|
#include <memory> // Para shared_ptr
|
||||||
#include <vector> // Para vector
|
#include <vector> // Para vector
|
||||||
|
|
||||||
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
#include "utils/delta_timer.hpp" // Para DeltaTimer
|
||||||
class SurfaceSprite; // Forward declaration
|
class SurfaceSprite; // Forward declaration
|
||||||
class Surface; // Forward declaration
|
class Surface; // Forward declaration
|
||||||
|
|
||||||
// Estados de la secuencia del logo
|
// Estados de la secuencia del logo
|
||||||
enum class LogoState {
|
enum class LogoState {
|
||||||
INITIAL, // Espera inicial
|
INITIAL, // Espera inicial
|
||||||
JAILGAMES_SLIDE_IN, // Las líneas de JAILGAMES se deslizan hacia el centro
|
JAILGAMES_SLIDE_IN, // Las líneas de JAILGAMES se deslizan hacia el centro
|
||||||
SINCE_1998_FADE_IN, // Aparición gradual del texto "Since 1998"
|
SINCE_1998_FADE_IN, // Aparición gradual del texto "Since 1998"
|
||||||
DISPLAY, // Logo completo visible
|
DISPLAY, // Logo completo visible
|
||||||
FADE_OUT, // Desaparición gradual
|
FADE_OUT, // Desaparición gradual
|
||||||
END // Fin de la secuencia
|
END // Fin de la secuencia
|
||||||
};
|
};
|
||||||
|
|
||||||
class Logo {
|
class Logo {
|
||||||
@@ -26,11 +27,11 @@ class Logo {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// --- Constantes de tiempo (en segundos) ---
|
// --- Constantes de tiempo (en segundos) ---
|
||||||
static constexpr float INITIAL_DELAY = 0.5f; // Tiempo antes de que empiece la animación
|
static constexpr float INITIAL_DELAY = 0.5f; // Tiempo antes de que empiece la animación
|
||||||
static constexpr float JAILGAMES_SLIDE_DURATION = 1.2f; // Duración del slide-in de JAILGAMES
|
static constexpr float JAILGAMES_SLIDE_DURATION = 1.2f; // Duración del slide-in de JAILGAMES
|
||||||
static constexpr float SINCE_1998_FADE_DURATION = 0.5f; // Duración del fade-in de "Since 1998"
|
static constexpr float SINCE_1998_FADE_DURATION = 0.5f; // Duración del fade-in de "Since 1998"
|
||||||
static constexpr float DISPLAY_DURATION = 3.5f; // Tiempo que el logo permanece visible
|
static constexpr float DISPLAY_DURATION = 3.5f; // Tiempo que el logo permanece visible
|
||||||
static constexpr float FADE_OUT_DURATION = 0.5f; // Duración del fade-out final
|
static constexpr float FADE_OUT_DURATION = 0.5f; // Duración del fade-out final
|
||||||
|
|
||||||
// --- Constantes de animación ---
|
// --- Constantes de animación ---
|
||||||
static constexpr float JAILGAMES_SLIDE_SPEED = 800.0f; // Velocidad de slide-in (pixels/segundo)
|
static constexpr float JAILGAMES_SLIDE_SPEED = 800.0f; // Velocidad de slide-in (pixels/segundo)
|
||||||
@@ -45,22 +46,22 @@ class Logo {
|
|||||||
Uint8 since_1998_color_ = 0; // Color para el sprite de "Since 1998"
|
Uint8 since_1998_color_ = 0; // Color para el sprite de "Since 1998"
|
||||||
|
|
||||||
// --- Variables de estado ---
|
// --- Variables de estado ---
|
||||||
std::vector<Uint8> color_; // Vector con los colores para el fade
|
std::vector<Uint8> color_; // Vector con los colores para el fadeF
|
||||||
std::unique_ptr<DeltaTimer> delta_timer_; // Timer para delta time
|
std::unique_ptr<DeltaTimer> delta_timer_; // Timer para delta time
|
||||||
LogoState state_; // Estado actual de la secuencia
|
LogoState state_; // Estado actual de la secuencia
|
||||||
float state_time_; // Tiempo acumulado en el estado actual
|
float state_time_; // Tiempo acumulado en el estado actual
|
||||||
|
|
||||||
// --- Funciones ---
|
// --- Funciones ---
|
||||||
void update(); // Actualiza las variables
|
void update(); // Actualiza las variables
|
||||||
void render(); // Dibuja en pantalla
|
void render(); // Dibuja en pantalla
|
||||||
void checkEvents(); // Comprueba el manejador de eventos
|
void checkEvents(); // Comprueba el manejador de eventos
|
||||||
void checkInput(); // Comprueba las entradas
|
void checkInput(); // Comprueba las entradas
|
||||||
void updateJAILGAMES(float delta_time); // Gestiona el logo de JAILGAME (time-based)
|
void updateJAILGAMES(float delta_time); // Gestiona el logo de JAILGAME (time-based)
|
||||||
void updateTextureColors(); // Gestiona el color de las texturas
|
void updateTextureColors(); // Gestiona el color de las texturas
|
||||||
void updateState(float delta_time); // Actualiza el estado actual
|
void updateState(float delta_time); // Actualiza el estado actual
|
||||||
void transitionToState(LogoState new_state); // Transiciona a un nuevo estado
|
void transitionToState(LogoState new_state); // Transiciona a un nuevo estado
|
||||||
int getColorIndex(float progress) const; // Calcula el índice de color según el progreso (0.0-1.0)
|
int getColorIndex(float progress) const; // Calcula el índice de color según el progreso (0.0-1.0)
|
||||||
void endSection(); // Termina la sección
|
void endSection(); // Termina la sección
|
||||||
void initColors(); // Inicializa el vector de colores
|
void initColors(); // Inicializa el vector de colores
|
||||||
void initSprites(); // Crea los sprites de cada linea
|
void initSprites(); // Crea los sprites de cada linea
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user