migrat correctament a delta_time credits.cpp i eliminat un bug que feia que si no pasaves a ma el final, no acabara mai
This commit is contained in:
@@ -82,7 +82,7 @@ void Credits::run() {
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables (time-based)
|
||||
// Actualiza las variables (time-based puro - sin conversión frame-based)
|
||||
void Credits::update(float delta_time) {
|
||||
const float MULTIPLIER = want_to_pass_ ? FAST_FORWARD_MULTIPLIER : 1.0F;
|
||||
const float ADJUSTED_DELTA_TIME = delta_time * MULTIPLIER;
|
||||
@@ -99,10 +99,6 @@ void Credits::update(float delta_time) {
|
||||
updatePlayers(ADJUSTED_DELTA_TIME);
|
||||
updateAllFades(ADJUSTED_DELTA_TIME);
|
||||
|
||||
// Convertir deltaTime a equivalente de frames (60fps)
|
||||
const float FRAME_FACTOR = ADJUSTED_DELTA_TIME * 60.0F;
|
||||
counter_ += FRAME_FACTOR;
|
||||
|
||||
fillCanvas();
|
||||
}
|
||||
|
||||
@@ -270,7 +266,7 @@ void Credits::fillCanvas() {
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), temp);
|
||||
}
|
||||
|
||||
// Actualiza el destino de los rectangulos de las texturas (time-based)
|
||||
// Actualiza el destino de los rectangulos de las texturas (time-based puro)
|
||||
void Credits::updateTextureDstRects(float delta_time) {
|
||||
constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0F / 60.0F; // ~0.167s (cada 10 frames)
|
||||
credits_state_.texture_accumulator += delta_time;
|
||||
@@ -284,34 +280,45 @@ void Credits::updateTextureDstRects(float delta_time) {
|
||||
}
|
||||
|
||||
// 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 <= static_cast<float>(mini_logo_final_pos_)) {
|
||||
// Forzar posición exacta para evitar problemas de comparación float
|
||||
mini_logo_rect_dst_.y = static_cast<float>(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_) {
|
||||
fading_ = true;
|
||||
}
|
||||
|
||||
// Se activa el contador para evitar que la sección sea infinita
|
||||
if (counter_prevent_endless_ == 1000) {
|
||||
fading_ = true;
|
||||
} else {
|
||||
++counter_prevent_endless_;
|
||||
}
|
||||
} else {
|
||||
--mini_logo_rect_dst_.y;
|
||||
}
|
||||
}
|
||||
|
||||
// Acumular tiempo desde que el logo llegó a su posición (fuera del if para que se ejecute cada frame)
|
||||
if (mini_logo_on_position_) {
|
||||
time_since_logo_positioned_ += delta_time;
|
||||
|
||||
// Timeout para evitar que la sección sea infinita
|
||||
if (time_since_logo_positioned_ >= MAX_TIME_AFTER_LOGO_S) {
|
||||
fading_ = true;
|
||||
}
|
||||
|
||||
// Si el jugador quiere pasar los titulos de credito, el fade se inicia solo
|
||||
if (want_to_pass_) {
|
||||
fading_ = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tira globos al escenario (time-based)
|
||||
// Tira globos al escenario (time-based puro)
|
||||
void Credits::throwBalloons(float delta_time) {
|
||||
constexpr int SPEED = 200;
|
||||
constexpr size_t NUM_SETS = 8; // Tamaño del vector SETS
|
||||
const std::vector<int> SETS = {0, 63, 25, 67, 17, 75, 13, 50};
|
||||
constexpr float BALLOON_INTERVAL_S = SPEED / 60.0F; // ~3.33s (cada 200 frames)
|
||||
constexpr float POWERBALL_INTERVAL_S = (SPEED * 4) / 60.0F; // ~13.33s (cada 800 frames)
|
||||
constexpr float BALLOON_INTERVAL_S = SPEED / 60.0F; // ~3.33s (cada 200 frames)
|
||||
constexpr float POWERBALL_INTERVAL_S = (SPEED * 4) / 60.0F; // ~13.33s (cada 800 frames)
|
||||
constexpr float MAX_BALLOON_TIME_S = ((NUM_SETS - 1) * SPEED * 3) / 60.0F; // Tiempo máximo para lanzar globos
|
||||
|
||||
if (counter_ > ((SETS.size() - 1) * SPEED) * 3) {
|
||||
// Acumular tiempo total de globos
|
||||
elapsed_time_balloons_ += delta_time;
|
||||
|
||||
// Detener lanzamiento después del tiempo límite
|
||||
if (elapsed_time_balloons_ > MAX_BALLOON_TIME_S) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -320,11 +327,11 @@ void Credits::throwBalloons(float delta_time) {
|
||||
|
||||
if (credits_state_.balloon_accumulator >= BALLOON_INTERVAL_S) {
|
||||
credits_state_.balloon_accumulator -= BALLOON_INTERVAL_S;
|
||||
const int INDEX = (static_cast<int>(counter_ / SPEED)) % SETS.size();
|
||||
const int INDEX = (static_cast<int>(elapsed_time_balloons_ * 60.0F / SPEED)) % SETS.size();
|
||||
balloon_manager_->deployFormation(SETS.at(INDEX), -60);
|
||||
}
|
||||
|
||||
if (credits_state_.powerball_accumulator >= POWERBALL_INTERVAL_S && counter_ > 0) {
|
||||
if (credits_state_.powerball_accumulator >= POWERBALL_INTERVAL_S && elapsed_time_balloons_ > 0.0F) {
|
||||
credits_state_.powerball_accumulator -= POWERBALL_INTERVAL_S;
|
||||
balloon_manager_->createPowerBall();
|
||||
}
|
||||
@@ -485,11 +492,12 @@ void Credits::updateBlackRects(float delta_time) {
|
||||
// Fase final: ya completado el movimiento de rects
|
||||
Audio::get()->setMusicVolume(0);
|
||||
// Audio::get()->stopMusic(); // opcional, si quieres parar la reproducción
|
||||
if (counter_pre_fade_ >= 400.0f) {
|
||||
|
||||
// Usar segundos puros en lugar de frames equivalentes
|
||||
if (counter_pre_fade_ >= PRE_FADE_DELAY_S) {
|
||||
if (fade_out_) fade_out_->activate();
|
||||
} else {
|
||||
const float frame_increment = delta_time * FRAMES_PER_SECOND;
|
||||
counter_pre_fade_ += frame_increment;
|
||||
counter_pre_fade_ += delta_time;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user