revisant title.cpp (falla el jugador)

This commit is contained in:
2025-09-23 14:13:48 +02:00
parent 3fafff026b
commit 6a223b68ba
5 changed files with 55 additions and 38 deletions

View File

@@ -46,6 +46,7 @@ Title::Title()
num_controllers_(Input::get()->getNumGamepads()) {
// Configura objetos
tiled_bg_->setColor(param.title.bg_color);
tiled_bg_->setSpeed(60.0F); // Set appropriate speed for seconds-based deltaTime
game_logo_->enable();
mini_logo_sprite_->setX(param.game.game_area.center_x - (mini_logo_sprite_->getWidth() / 2));
fade_->setColor(param.fade.color);
@@ -82,7 +83,7 @@ void Title::update(float deltaTime) {
Screen::get()->update();
updateFade();
updateState(deltaTime);
updateStartPrompt();
updateStartPrompt(deltaTime);
for (auto& player : players_) {
player->update(deltaTime);
@@ -94,7 +95,7 @@ void Title::update(float deltaTime) {
// Calcula el tiempo transcurrido desde el último frame
float Title::calculateDeltaTime() {
const Uint64 current_time = SDL_GetTicks();
const float delta_time = static_cast<float>(current_time - last_time_);
const float delta_time = static_cast<float>(current_time - last_time_) / 1000.0f; // Convert ms to seconds
last_time_ = current_time;
return delta_time;
}
@@ -403,7 +404,7 @@ void Title::updateState(float deltaTime) {
case State::START_HAS_BEEN_PRESSED: {
counter_time_ += deltaTime;
if (counter_time_ >= START_PRESSED_DELAY_MS) {
if (counter_time_ >= START_PRESSED_DELAY_S) {
fade_->activate();
}
break;
@@ -414,23 +415,38 @@ void Title::updateState(float deltaTime) {
}
}
void Title::updateStartPrompt() {
Uint32 time_ms = SDL_GetTicks();
void Title::updateStartPrompt(float deltaTime) {
blink_accumulator_ += deltaTime;
bool condition_met = false;
float period = 0.0f;
float on_time = 0.0f;
switch (state_) {
case State::LOGO_FINISHED:
condition_met = (time_ms % LOGO_BLINK_PERIOD_MS) >= (LOGO_BLINK_PERIOD_MS - LOGO_BLINK_ON_TIME_MS);
period = LOGO_BLINK_PERIOD_S;
on_time = LOGO_BLINK_ON_TIME_S;
break;
case State::START_HAS_BEEN_PRESSED:
condition_met = (time_ms % START_BLINK_PERIOD_MS) >= (START_BLINK_PERIOD_MS - START_BLINK_ON_TIME_MS);
period = START_BLINK_PERIOD_S;
on_time = START_BLINK_ON_TIME_S;
break;
default:
break;
}
if (period > 0.0f) {
// Reset accumulator when it exceeds the period
if (blink_accumulator_ >= period) {
blink_accumulator_ -= period;
}
// Check if we're in the "on" time of the blink cycle
condition_met = blink_accumulator_ >= (period - on_time);
}
should_render_start_prompt_ = condition_met;
}

View File

@@ -33,7 +33,7 @@ struct Gamepad;
// • Timeouts automáticos: transición automática si no hay interacción
// • Debug de colores: herramientas de depuración para ajustes visuales
//
// La clase utiliza un sistema de tiempo basado en milisegundos para garantizar
// La clase utiliza un sistema de tiempo basado en segundos para garantizar
// comportamiento consistente independientemente del framerate.
class Title {
public:
@@ -45,16 +45,16 @@ class Title {
void run();
private:
// --- Constantes de tiempo (en milisegundos) ---
static constexpr float START_PRESSED_DELAY_MS = 1666.67f; // Tiempo antes de fade tras pulsar start (100 frames a 60fps)
static constexpr int MUSIC_FADE_OUT_LONG_MS = 1500; // Fade out largo de música
static constexpr int MUSIC_FADE_OUT_SHORT_MS = 300; // Fade out corto de música
// --- Constantes de tiempo (en segundos) ---
static constexpr float START_PRESSED_DELAY_S = 1666.67f / 1000.0f; // Tiempo antes de fade tras pulsar start (100 frames a 60fps)
static constexpr int MUSIC_FADE_OUT_LONG_MS = 1500; // Fade out largo de música
static constexpr int MUSIC_FADE_OUT_SHORT_MS = 300; // Fade out corto de música
// --- Constantes de parpadeo ---
static constexpr Uint32 LOGO_BLINK_PERIOD_MS = 833; // Período de parpadeo del logo
static constexpr Uint32 LOGO_BLINK_ON_TIME_MS = 583; // Tiempo encendido del logo (833-250)
static constexpr Uint32 START_BLINK_PERIOD_MS = 167; // Período de parpadeo del start
static constexpr Uint32 START_BLINK_ON_TIME_MS = 83; // Tiempo encendido del start (167-83)
// --- Constantes de parpadeo (en segundos) ---
static constexpr float LOGO_BLINK_PERIOD_S = 833.0f / 1000.0f; // Período de parpadeo del logo (833ms)
static constexpr float LOGO_BLINK_ON_TIME_S = 583.0f / 1000.0f; // Tiempo encendido del logo (583ms)
static constexpr float START_BLINK_PERIOD_S = 167.0f / 1000.0f; // Período de parpadeo del start (167ms)
static constexpr float START_BLINK_ON_TIME_S = 83.0f / 1000.0f; // Tiempo encendido del start (83ms)
// --- Constantes de layout ---
static constexpr int MINI_LOGO_Y_DIVISOR = 5; // Divisor para posición Y del mini logo
@@ -92,7 +92,8 @@ class Title {
Section::Options selection_ = Section::Options::TITLE_TIME_OUT; // Opción elegida en el título
State state_; // Estado actual de la sección
Uint64 last_time_ = 0; // Último timestamp para calcular delta-time
float counter_time_ = 0.0f; // Temporizador para la pantalla de título (en milisegundos)
float counter_time_ = 0.0f; // Temporizador para la pantalla de título (en segundos)
float blink_accumulator_ = 0.0f; // Acumulador para el parpadeo (en segundos)
int num_controllers_; // Número de mandos conectados
bool should_render_start_prompt_ = false; // Indica si se muestra el texto de PRESS START BUTTON TO PLAY
bool player1_start_pressed_ = false; // Indica si se ha pulsado el botón de empezar para el jugador 1
@@ -127,7 +128,7 @@ class Title {
// --- Visualización / Renderizado ---
void render(); // Dibuja el objeto en pantalla
void updateFade(); // Actualiza el efecto de fundido (fade in/out)
void updateStartPrompt(); // Actualiza el mensaje de "Pulsa Start"
void updateStartPrompt(float deltaTime); // Actualiza el mensaje de "Pulsa Start"
void renderStartPrompt(); // Dibuja el mensaje de "Pulsa Start" en pantalla
void renderCopyright(); // Dibuja el aviso de copyright