migrat Scoreboard a time based

This commit is contained in:
2025-10-31 09:30:33 +01:00
parent f08b2f9193
commit 1bb3d00e7c
4 changed files with 31 additions and 16 deletions

View File

@@ -30,8 +30,6 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
surface_dest_ = {.x = 0, .y = Options::game.height - SURFACE_HEIGHT, .w = SURFACE_WIDTH, .h = SURFACE_HEIGHT};
// Inicializa las variables
counter_ = 0;
change_color_speed_ = 4;
is_paused_ = false;
paused_time_ = 0;
paused_time_elapsed_ = 0;
@@ -50,12 +48,15 @@ void Scoreboard::render() {
}
// Actualiza las variables del objeto
void Scoreboard::update() {
counter_++;
player_sprite_->update();
void Scoreboard::update(float delta_time) {
// Acumular tiempo para animaciones
time_accumulator_ += delta_time;
// Actualizar sprite con delta time
player_sprite_->update(delta_time);
// Actualiza el color de la cantidad de items recogidos
updateItemsColor();
updateItemsColor(delta_time);
// Dibuja la textura
fillTexture();
@@ -98,12 +99,20 @@ void Scoreboard::setPaused(bool value) {
}
// Actualiza el color de la cantidad de items recogidos
void Scoreboard::updateItemsColor() {
void Scoreboard::updateItemsColor(float delta_time) {
if (!data_->jail_is_open) {
return;
}
if (counter_ % 20 < 10) {
items_color_timer_ += delta_time;
// Resetear timer cada 2 ciclos (0.666s total)
if (items_color_timer_ >= ITEMS_COLOR_BLINK_DURATION * 2.0F) {
items_color_timer_ = 0.0F;
}
// Alternar color cada ITEMS_COLOR_BLINK_DURATION
if (items_color_timer_ < ITEMS_COLOR_BLINK_DURATION) {
items_color_ = stringToColor("white");
} else {
items_color_ = stringToColor("magenta");
@@ -129,8 +138,9 @@ void Scoreboard::fillTexture() {
constexpr int LINE2 = 3 * TILE_SIZE;
// Dibuja las vidas
const int DESP = (counter_ / 40) % 8;
const int FRAME = DESP % 4;
// Calcular desplazamiento basado en tiempo
const int DESP = static_cast<int>(time_accumulator_ / SPRITE_WALK_CYCLE_DURATION) % 8;
const int FRAME = DESP % SPRITE_WALK_FRAMES;
player_sprite_->setCurrentAnimationFrame(FRAME);
player_sprite_->setPosY(LINE2);
for (int i = 0; i < data_->lives; ++i) {