@@ -32,6 +32,8 @@ class Tabe {
|
||||
void setState(State state); // Establece el estado
|
||||
auto tryToGetBonus() -> bool; // Intenta obtener el bonus
|
||||
void pauseTimer(bool value); // Detiene/activa el timer
|
||||
void disableSpawning(); // Deshabilita el spawning permanentemente
|
||||
void enableSpawning(); // Habilita el spawning nuevamente
|
||||
|
||||
// --- Getters ---
|
||||
auto getCollider() -> SDL_FRect& { return sprite_->getRect(); } // Obtiene el área de colisión
|
||||
@@ -54,7 +56,8 @@ class Tabe {
|
||||
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{false}; // Indica si el temporizador está pausado
|
||||
bool is_paused{false}; // Indica si el temporizador está pausado (por pausa de juego)
|
||||
bool spawn_disabled{false}; // Indica si el spawning está deshabilitado permanentemente
|
||||
|
||||
// Constructor - los parámetros min_time y max_time están en mintos
|
||||
Timer(float min_time, float max_time)
|
||||
@@ -75,8 +78,8 @@ class Tabe {
|
||||
void update() {
|
||||
current_time = SDL_GetTicks();
|
||||
|
||||
// Solo actualizar si no está pausado
|
||||
if (!is_paused) {
|
||||
// Solo actualizar si no está pausado (ni por juego ni por spawn deshabilitado)
|
||||
if (!is_paused && !spawn_disabled) {
|
||||
delta_time = current_time - last_time;
|
||||
|
||||
if (time_until_next_spawn > delta_time) {
|
||||
@@ -101,9 +104,20 @@ class Tabe {
|
||||
}
|
||||
}
|
||||
|
||||
// Pausa o reanuda el spawning
|
||||
void setSpawnDisabled(bool disabled) {
|
||||
if (spawn_disabled != disabled) {
|
||||
spawn_disabled = disabled;
|
||||
// Al reactivar, actualizar last_time para evitar saltos
|
||||
if (!disabled) {
|
||||
last_time = SDL_GetTicks();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Indica si el temporizador ha finalizado
|
||||
[[nodiscard]] auto shouldSpawn() const -> bool {
|
||||
return time_until_next_spawn == 0 && !is_paused;
|
||||
return time_until_next_spawn == 0 && !is_paused && !spawn_disabled;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user