corregit del delay entre formacions

This commit is contained in:
2025-09-24 13:09:54 +02:00
parent ff5446fcdf
commit 504727b95f
2 changed files with 23 additions and 21 deletions

View File

@@ -81,12 +81,12 @@ void BalloonManager::render() {
// Crea una formación de globos
void BalloonManager::deployRandomFormation(int stage) {
// Solo despliega una formación enemiga si ha pasado cierto tiempo desde la última
if (balloon_deploy_counter_ >= DEFAULT_BALLOON_DEPLOY_COUNTER) {
// Solo despliega una formación enemiga si el timer ha llegado a cero
if (balloon_deploy_counter_ <= 0.0f) {
// En este punto se decide entre crear una powerball o una formación enemiga
if ((rand() % 100 < 15) && (canPowerBallBeCreated())) {
createPowerBall(); // Crea una powerball
balloon_deploy_counter_ = -10.0f / 60.0f; // Resetea con pequeño retraso (10 frames = ~0.167s negativos)
createPowerBall(); // Crea una powerball
balloon_deploy_counter_ = POWERBALL_DEPLOY_DELAY; // Resetea con pequeño retraso
} else {
// Decrementa el contador de despliegues de globos necesarios para la siguiente PowerBall
if (power_ball_counter_ > 0) {
@@ -118,8 +118,8 @@ void BalloonManager::deployRandomFormation(int stage) {
createBalloon(config);
}
// Reinicia el contador para el próximo despliegue
balloon_deploy_counter_ = 0;
// Reinicia el timer para el próximo despliegue
balloon_deploy_counter_ = DEFAULT_BALLOON_DEPLOY_DELAY;
}
}
}
@@ -162,10 +162,10 @@ void BalloonManager::freeBalloons() {
balloons_.erase(result.begin(), balloons_.end());
}
// Actualiza la variable enemyDeployCounter (time-based)
// Actualiza el timer de despliegue de globos (time-based)
void BalloonManager::updateBalloonDeployCounter(float deltaTime) {
// DeltaTime en segundos - contador incrementa hasta llegar al umbral
balloon_deploy_counter_ += deltaTime;
// DeltaTime en segundos - timer decrementa hasta llegar a cero
balloon_deploy_counter_ -= deltaTime;
}
// Indica si se puede crear una powerball
@@ -280,7 +280,7 @@ auto BalloonManager::popBalloon(const std::shared_ptr<Balloon> &balloon) -> int
balloon->pop(true);
score = destroyAllBalloons();
power_ball_enabled_ = false;
balloon_deploy_counter_ = -20.0f / 60.0f; // Resetea con retraso (20 frames = ~0.333s negativos)
balloon_deploy_counter_ = BALLOON_POP_DELAY; // Resetea con retraso
} else {
score = balloon->getScore();
if (balloon->getSize() != Balloon::Size::SMALL) {
@@ -336,7 +336,7 @@ auto BalloonManager::destroyAllBalloons() -> int {
score += destroyBalloon(balloon);
}
balloon_deploy_counter_ = -300.0f / 60.0f; // Resetea con retraso grande (300 frames = 5s negativos)
balloon_deploy_counter_ = DEFAULT_BALLOON_DEPLOY_DELAY;
Screen::get()->flash(Colors::FLASH, 3);
Screen::get()->shake();

View File

@@ -28,28 +28,28 @@ class BalloonManager {
~BalloonManager() = default;
// --- Métodos principales ---
void update(float deltaTime); // Actualiza el estado de los globos (time-based)
void render(); // Renderiza los globos en pantalla
void update(float deltaTime); // Actualiza el estado de los globos (time-based)
void render(); // Renderiza los globos en pantalla
// --- Gestión de globos ---
void freeBalloons(); // Libera globos que ya no sirven
// --- Creación de formaciones enemigas ---
void deployRandomFormation(int stage); // Crea una formación de globos aleatoria
void deployFormation(int formation_id); // Crea una formación específica
void deployRandomFormation(int stage); // Crea una formación de globos aleatoria
void deployFormation(int formation_id); // Crea una formación específica
void deployFormation(int formation_id, float y); // Crea una formación específica con coordenadas
// --- Creación de globos ---
auto createBalloon(Balloon::Config config) -> std::shared_ptr<Balloon>; // Crea un nuevo globo
void createChildBalloon(const std::shared_ptr<Balloon> &balloon, const std::string &direction); // Crea un globo a partir de otro
void createPowerBall(); // Crea una PowerBall
void createTwoBigBalloons(); // Crea dos globos grandes
auto createBalloon(Balloon::Config config) -> std::shared_ptr<Balloon>; // Crea un nuevo globo
void createChildBalloon(const std::shared_ptr<Balloon> &balloon, const std::string &direction); // Crea un globo a partir de otro
void createPowerBall(); // Crea una PowerBall
void createTwoBigBalloons(); // Crea dos globos grandes
// --- Control de velocidad y despliegue ---
void setBalloonSpeed(float speed); // Ajusta la velocidad de los globos
void setDefaultBalloonSpeed(float speed) { default_balloon_speed_ = speed; }; // Establece la velocidad base
void resetBalloonSpeed() { setBalloonSpeed(default_balloon_speed_); }; // Restablece la velocidad de los globos
void updateBalloonDeployCounter(float deltaTime); // Actualiza el contador de despliegue (time-based)
void updateBalloonDeployCounter(float deltaTime); // Actualiza el contador de despliegue (time-based)
auto canPowerBallBeCreated() -> bool; // Indica si se puede crear una PowerBall
auto calculateScreenPower() -> int; // Calcula el poder de los globos en pantalla
@@ -82,7 +82,9 @@ class BalloonManager {
private:
// --- Constantes ---
static constexpr float DEFAULT_BALLOON_DEPLOY_COUNTER = 300.0f / 60.0f; // 300 frames = 5 segundos
static constexpr float DEFAULT_BALLOON_DEPLOY_DELAY = 5.0f; // 300 frames = 5 segundos
static constexpr float POWERBALL_DEPLOY_DELAY = 0.167f; // 10 frames = 0.167 segundos
static constexpr float BALLOON_POP_DELAY = 0.333f; // 20 frames = 0.333 segundos
// --- Objetos y punteros ---
Balloons balloons_; // Vector con los globos activos