This commit is contained in:
2025-10-24 17:50:31 +02:00
parent 3cfb65320c
commit 4679255d60
8 changed files with 68 additions and 44 deletions

View File

@@ -432,7 +432,7 @@ void Credits::updateBlackRects(float delta_time) {
static_cast<float>(param.game.game_area.center_y + 1));
int bottom_steps_by_h = static_cast<int>(bottom_black_rect_.h) - prev_bottom_h;
int bottom_steps_by_y = prev_bottom_y - static_cast<int>(bottom_black_rect_.y);
int bottom_steps = std::max(0, std::max(bottom_steps_by_h, bottom_steps_by_y));
int bottom_steps = std::max({0, bottom_steps_by_h, bottom_steps_by_y});
int steps_done = top_delta + bottom_steps;
if (steps_done > 0) {
@@ -460,20 +460,20 @@ void Credits::updateBlackRects(float delta_time) {
if (!horizontal_done_) {
int prev_left_w = static_cast<int>(left_black_rect_.w);
left_black_rect_.w = std::min(left_black_rect_.w + static_cast<float>(HORIZONTAL_SPEED),
static_cast<float>(param.game.game_area.center_x));
param.game.game_area.center_x);
int left_gain = static_cast<int>(left_black_rect_.w) - prev_left_w;
int prev_right_x = static_cast<int>(right_black_rect_.x);
right_black_rect_.w = right_black_rect_.w + static_cast<float>(HORIZONTAL_SPEED);
right_black_rect_.x = std::max(right_black_rect_.x - static_cast<float>(HORIZONTAL_SPEED),
static_cast<float>(param.game.game_area.center_x));
param.game.game_area.center_x);
int right_move = prev_right_x - static_cast<int>(right_black_rect_.x);
int steps_done = left_gain + right_move;
if (steps_done > 0) {
current_step_ = std::max(0.0f, current_step_ - static_cast<float>(steps_done));
current_step_ = std::max(0.0F, current_step_ - static_cast<float>(steps_done));
float vol_f = initial_volume_ * (current_step_ / static_cast<float>(total_steps_));
int vol_i = static_cast<int>(std::clamp(vol_f, 0.0f, static_cast<float>(initial_volume_)));
int vol_i = static_cast<int>(std::clamp(vol_f, 0.0F, static_cast<float>(initial_volume_)));
Audio::get()->setMusicVolume(vol_i); // usa tu API de audio aquí
}
@@ -495,7 +495,9 @@ void Credits::updateBlackRects(float delta_time) {
// Usar segundos puros en lugar de frames equivalentes
if (counter_pre_fade_ >= PRE_FADE_DELAY_S) {
if (fade_out_) fade_out_->activate();
if (fade_out_) {
fade_out_->activate();
}
} else {
counter_pre_fade_ += delta_time;
}
@@ -680,7 +682,9 @@ void Credits::startCredits() {
int pasos_right = (dx_right + (HORIZONTAL_SPEED - 1)) / HORIZONTAL_SPEED; // ceil
total_steps_ = pasos_top + pasos_bottom + pasos_left + pasos_right;
if (total_steps_ <= 0) total_steps_ = 1;
if (total_steps_ <= 0) {
total_steps_ = 1;
}
current_step_ = static_cast<float>(total_steps_);
@@ -690,7 +694,9 @@ void Credits::startCredits() {
initialized_ = true;
// Asegurar volumen inicial consistente
if (steps_ <= 0) steps_ = 1;
if (steps_ <= 0) {
steps_ = 1;
}
float vol_f = initial_volume_ * (current_step_ / static_cast<float>(total_steps_));
setVolume(static_cast<int>(std::clamp(vol_f, 0.0F, static_cast<float>(initial_volume_))));
}
@@ -711,8 +717,8 @@ void Credits::drawBorderRect() {
SDL_Rect r;
r.x = static_cast<int>(std::floor(border_rect_.x + 0.5F));
r.y = static_cast<int>(std::floor(border_rect_.y + 0.5F));
r.w = static_cast<int>(std::max(0.0f, std::floor(border_rect_.w + 0.5F)));
r.h = static_cast<int>(std::max(0.0f, std::floor(border_rect_.h + 0.5F)));
r.w = static_cast<int>(std::max(0.0F, std::floor(border_rect_.w + 0.5F)));
r.h = static_cast<int>(std::max(0.0F, std::floor(border_rect_.h + 0.5F)));
if (r.w > 0 && r.h > 0) {
SDL_RenderRect(Screen::get()->getRenderer(), &border_rect_);