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

View File

@@ -82,7 +82,9 @@ class BalloonManager {
private: private:
// --- Constantes --- // --- 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 --- // --- Objetos y punteros ---
Balloons balloons_; // Vector con los globos activos Balloons balloons_; // Vector con los globos activos