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

@@ -42,7 +42,7 @@ Director::Director(int argc, std::span<char *> argv) {
Section::name = Section::Name::GAME;
Section::options = Section::Options::GAME_PLAY_1P;
#elif _DEBUG
Section::name = Section::Name::CREDITS;
Section::name = Section::Name::TITLE;
Section::options = Section::Options::GAME_PLAY_1P;
#else // NORMAL GAME
Section::name = Section::Name::LOGO;

View File

@@ -174,8 +174,8 @@ void GameLogo::handleCoffeeCrisisFinished(float deltaTime) {
}
void GameLogo::handleArcadeEditionMoving(float deltaTime) {
// DeltaTime puro: decremento por milisegundo
zoom_ -= (ZOOM_DECREMENT_PER_MS * ZOOM_FACTOR) * deltaTime;
// DeltaTime en segundos: decremento por segundo
zoom_ -= (ZOOM_DECREMENT_PER_S * ZOOM_FACTOR) * deltaTime;
arcade_edition_sprite_->setZoom(zoom_);
if (zoom_ <= 1.0F) {
@@ -196,8 +196,8 @@ void GameLogo::handleArcadeEditionShaking(float deltaTime) {
void GameLogo::processShakeEffect(SmartSprite* primary_sprite, SmartSprite* secondary_sprite, float deltaTime) {
shake_.time_accumulator += deltaTime;
if (shake_.time_accumulator >= SHAKE_DELAY_MS) {
shake_.time_accumulator -= SHAKE_DELAY_MS;
if (shake_.time_accumulator >= SHAKE_DELAY_S) {
shake_.time_accumulator -= SHAKE_DELAY_S;
const auto DISPLACEMENT = calculateShakeDisplacement();
primary_sprite->setPosX(shake_.origin + DISPLACEMENT);
if (secondary_sprite != nullptr) {
@@ -208,8 +208,8 @@ void GameLogo::processShakeEffect(SmartSprite* primary_sprite, SmartSprite* seco
}
void GameLogo::processArcadeEditionShake(float deltaTime) {
// Delay fijo en milisegundos (shake_.delay era frames, ahora usamos constante)
float delayTime = SHAKE_DELAY_MS;
// Delay fijo en segundos (shake_.delay era frames, ahora usamos constante)
float delayTime = SHAKE_DELAY_S;
shake_.time_accumulator += deltaTime;
@@ -267,7 +267,7 @@ void GameLogo::enable() {
// Indica si ha terminado la animación
auto GameLogo::hasFinished() const -> bool {
return post_finished_timer_ >= post_finished_delay_ms_;
return post_finished_timer_ >= post_finished_delay_s_;
}
// Calcula el desplazamiento vertical inicial

View File

@@ -12,15 +12,15 @@ class Texture;
class GameLogo {
public:
// --- Constantes ---
static constexpr float COFFEE_VEL_Y = 0.15F; // Velocidad Y de coffee sprite (pixels/ms) - 2.5F/16.67
static constexpr float COFFEE_ACCEL_Y = 0.00036F; // Aceleración Y de coffee sprite (pixels/ms²) - 0.1F/(16.67)²
static constexpr float CRISIS_VEL_Y = -0.15F; // Velocidad Y de crisis sprite (pixels/ms) - -2.5F/16.67
static constexpr float CRISIS_ACCEL_Y = -0.00036F; // Aceleración Y de crisis sprite (pixels/ms²) - -0.1F/(16.67)²
static constexpr int CRISIS_OFFSET_X = 15; // Desplazamiento X de crisis sprite
static constexpr int DUST_SIZE = 16; // Tamaño de dust sprites
static constexpr float ZOOM_DECREMENT_PER_MS = 0.006F; // Decremento de zoom por milisegundo (0.1F/16.67ms)
static constexpr float SHAKE_DELAY_MS = 33.34F; // Delay de shake en milisegundos (2 frames * 16.67ms)
static constexpr float POST_FINISHED_FRAME_TIME = 16.67F; // Tiempo entre decrementos del counter (1 frame)
static constexpr float COFFEE_VEL_Y = 0.15F * 1000.0F; // Velocidad Y de coffee sprite (pixels/s) - 0.15F * 1000 = 150 pixels/s
static constexpr float COFFEE_ACCEL_Y = 0.00036F * 1000000.0F; // Aceleración Y de coffee sprite (pixels/s²) - 0.00036F * 1000000 = 360 pixels/s²
static constexpr float CRISIS_VEL_Y = -0.15F * 1000.0F; // Velocidad Y de crisis sprite (pixels/s) - -0.15F * 1000 = -150 pixels/s
static constexpr float CRISIS_ACCEL_Y = -0.00036F * 1000000.0F; // Aceleración Y de crisis sprite (pixels/s²) - -0.00036F * 1000000 = -360 pixels/s²
static constexpr int CRISIS_OFFSET_X = 15; // Desplazamiento X de crisis sprite
static constexpr int DUST_SIZE = 16; // Tamaño de dust sprites
static constexpr float ZOOM_DECREMENT_PER_S = 0.006F * 1000.0F; // Decremento de zoom por segundo (0.006F * 1000 = 6.0F per second)
static constexpr float SHAKE_DELAY_S = 33.34F / 1000.0F; // Delay de shake en segundos (33.34ms / 1000 = 0.03334s)
static constexpr float POST_FINISHED_FRAME_TIME_S = 16.67F / 1000.0F; // Tiempo entre decrementos del counter (16.67ms / 1000 = 0.01667s)
// --- Constructores y destructor ---
GameLogo(int x, int y);
@@ -92,8 +92,8 @@ class GameLogo {
float x_; // Posición X del logo
float y_; // Posición Y del logo
float zoom_ = 1.0F; // Zoom aplicado al texto "ARCADE EDITION"
float post_finished_delay_ms_ = POST_FINISHED_FRAME_TIME; // Retraso final tras animaciones (ms)
float post_finished_timer_ = 0.0f; // Timer acumulado para retraso final (ms)
float post_finished_delay_s_ = POST_FINISHED_FRAME_TIME_S; // Retraso final tras animaciones (s)
float post_finished_timer_ = 0.0f; // Timer acumulado para retraso final (s)
// --- Inicialización ---
void init(); // Inicializa las variables

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