fix: el temporitzador del tabe continuava contant amb el joc en pausa

This commit is contained in:
2025-07-19 13:25:44 +02:00
parent 2d1738f20a
commit 18ca6bdf86
3 changed files with 35 additions and 8 deletions

View File

@@ -26,10 +26,12 @@ struct TabeTimer {
Uint32 current_time; // Tiempo actual
Uint32 delta_time; // Diferencia de tiempo desde la última actualización
Uint32 last_time; // Tiempo de la última actualización
bool is_paused; // Indica si el temporizador está pausado
// Constructor
TabeTimer(float minTime, float maxTime)
: min_spawn_time(minTime * 60000), max_spawn_time(maxTime * 60000), current_time(SDL_GetTicks()) {
: min_spawn_time(minTime * 60000), max_spawn_time(maxTime * 60000),
current_time(SDL_GetTicks()), is_paused(false) {
reset();
}
@@ -43,19 +45,36 @@ struct TabeTimer {
// Actualiza el temporizador, decrementando el tiempo hasta la próxima aparición
void update() {
current_time = SDL_GetTicks();
delta_time = current_time - last_time;
// Solo actualizar si no está pausado
if (!is_paused) {
delta_time = current_time - last_time;
if (time_until_next_spawn > delta_time) {
time_until_next_spawn -= delta_time;
} else {
time_until_next_spawn = 0;
}
}
// Siempre actualizar last_time para evitar saltos de tiempo al despausar
last_time = current_time;
}
if (time_until_next_spawn > delta_time) {
time_until_next_spawn -= delta_time;
} else {
time_until_next_spawn = 0;
// Pausa o reanuda el temporizador
void setPaused(bool paused) {
if (is_paused != paused) {
is_paused = paused;
// Al despausar, actualizar last_time para evitar saltos
if (!paused) {
last_time = SDL_GetTicks();
}
}
}
// Indica si el temporizador ha finalizado
bool should_spawn() const {
return time_until_next_spawn == 0;
return time_until_next_spawn == 0 && !is_paused;
}
};
@@ -72,6 +91,7 @@ class Tabe {
void enable(); // Habilita el objeto
void setState(TabeState state); // Establece el estado
bool tryToGetBonus(); // Intenta obtener el bonus
void pauseTimer(bool value); // Detiene/activa el timer
// --- Getters ---
SDL_FRect &getCollider() { return sprite_->getRect(); } // Obtiene el área de colisión