diff --git a/source/sections/game.cpp b/source/sections/game.cpp index 81e7f1c..b617f2b 100644 --- a/source/sections/game.cpp +++ b/source/sections/game.cpp @@ -1824,8 +1824,8 @@ void Game::setState(State state) { playSound("power_ball_explosion.wav"); // Sonido de destruir todos los globos destroyAllItems(); // Destruye todos los items background_->setAlpha(0); // Elimina el tono rojo de las últimas pantallas + tabe_->disableSpawning(); // Deshabilita la creacion de Tabes break; - default: break; } diff --git a/source/tabe.cpp b/source/tabe.cpp index 5bfb1bc..5cee1a6 100644 --- a/source/tabe.cpp +++ b/source/tabe.cpp @@ -210,4 +210,14 @@ void Tabe::disable() { // Detiene/activa el timer void Tabe::pauseTimer(bool value) { timer_.setPaused(value); +} + +// Deshabilita el spawning permanentemente +void Tabe::disableSpawning() { + timer_.setSpawnDisabled(true); +} + +// Habilita el spawning nuevamente +void Tabe::enableSpawning() { + timer_.setSpawnDisabled(false); } \ No newline at end of file diff --git a/source/tabe.h b/source/tabe.h index 4abf3a8..7b392b2 100644 --- a/source/tabe.h +++ b/source/tabe.h @@ -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; } };