Revisada la classe Balloon

This commit is contained in:
2024-10-26 18:08:04 +02:00
parent f750997b34
commit 6235d0b684
3 changed files with 218 additions and 344 deletions

View File

@@ -230,27 +230,22 @@ void Game::deployBalloonFormation()
power_ball_counter_ = (power_ball_counter_ > 0) ? (power_ball_counter_ - 1) : 0;
// Elige una formación enemiga la azar
auto set = rand() % 10;
auto formation = rand() % 10;
// Evita repetir la ultima formación enemiga desplegada
if (set == last_balloon_deploy_)
if (formation == last_balloon_deploy_)
{
++set %= 10;
++formation %= 10;
}
last_balloon_deploy_ = set;
last_balloon_deploy_ = formation;
const Stage stage = balloon_formations_->getStage(current_stage_);
const auto numEnemies = stage.balloon_pool.set[set].number_of_balloons;
const auto set = balloon_formations_->getStage(0).balloon_pool.set[formation];
const auto numEnemies = set.number_of_balloons;
for (int i = 0; i < numEnemies; ++i)
{
createBalloon(stage.balloon_pool.set[set].init[i].x,
stage.balloon_pool.set[set].init[i].y,
stage.balloon_pool.set[set].init[i].type,
stage.balloon_pool.set[set].init[i].size,
stage.balloon_pool.set[set].init[i].vel_x,
balloon_speed_,
stage.balloon_pool.set[set].init[i].creation_counter);
auto p = set.init[i];
createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter);
}
balloon_deploy_counter_ = 300;
@@ -476,34 +471,17 @@ void Game::setBalloonSpeed(float speed)
// Actualiza la velocidad de los globos en funcion del poder acumulado de la fase
void Game::updateBalloonSpeed()
{
const float percent = (float)current_power_ / (float)balloon_formations_->getStage(current_stage_).power_to_complete;
float old_balloon_speed = balloon_speed_;
const float percent = static_cast<float>(current_power_) / balloon_formations_->getStage(current_stage_).power_to_complete;
const float thresholds[] = {0.2f, 0.4f, 0.6f, 0.8f};
// Comprueba si se ha de modificar la velocidad de los globos
if (balloon_speed_ == BALLOON_SPEED_1 && percent > 0.2f)
for (size_t i = 0; i < std::size(thresholds); ++i)
{
balloon_speed_ = BALLOON_SPEED_2;
}
else if (balloon_speed_ == BALLOON_SPEED_2 && percent > 0.4f)
{
balloon_speed_ = BALLOON_SPEED_3;
}
else if (balloon_speed_ == BALLOON_SPEED_3 && percent > 0.6f)
{
balloon_speed_ = BALLOON_SPEED_4;
}
else if (balloon_speed_ == BALLOON_SPEED_4 && percent > 0.8f)
{
balloon_speed_ = BALLOON_SPEED_5;
}
// Si ha habido cambio, se aplica a todos los globos
if (old_balloon_speed != balloon_speed_)
{
setBalloonSpeed(balloon_speed_);
if (balloon_speed_ == BALLOON_SPEED[i] && percent > thresholds[i])
{
balloon_speed_ = BALLOON_SPEED[i + 1];
setBalloonSpeed(balloon_speed_);
break; // Salir del bucle una vez actualizada la velocidad y aplicada
}
}
}
@@ -534,11 +512,11 @@ void Game::popBalloon(std::shared_ptr<Balloon> balloon)
const auto lower_size = static_cast<BalloonSize>(size - 1);
// En cualquier otro caso, crea dos globos de un tipo inferior
auto balloon_left = createBalloon(0, balloon->getPosY(), balloon->getType(), lower_size, BALLOON_VELX_NEGATIVE, balloon_speed_, 0);
balloon_left->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
balloon_left->alignTo(balloon->getPosX() + (balloon->getWidth() / 2));
balloon_left->setVelY(balloon_left->getType() == BalloonType::BALLOON ? -2.50f : BALLOON_VELX_NEGATIVE * 2.0f);
auto balloon_right = createBalloon(0, balloon->getPosY(), balloon->getType(), lower_size, BALLOON_VELX_POSITIVE, balloon_speed_, 0);
balloon_right->allignTo(balloon->getPosX() + (balloon->getWidth() / 2));
balloon_right->alignTo(balloon->getPosX() + (balloon->getWidth() / 2));
balloon_right->setVelY(balloon_right->getType() == BalloonType::BALLOON ? -2.50f : BALLOON_VELX_NEGATIVE * 2.0f);
// Elimina el globo
@@ -2167,7 +2145,7 @@ void Game::initDifficultyVars()
{
case GameDifficulty::EASY:
{
default_balloon_speed_ = BALLOON_SPEED_1;
default_balloon_speed_ = BALLOON_SPEED[0];
difficulty_score_multiplier_ = 0.5f;
scoreboard_->setColor(scoreboard_easy_color);
break;
@@ -2175,7 +2153,7 @@ void Game::initDifficultyVars()
case GameDifficulty::NORMAL:
{
default_balloon_speed_ = BALLOON_SPEED_1;
default_balloon_speed_ = BALLOON_SPEED[0];
difficulty_score_multiplier_ = 1.0f;
scoreboard_->setColor(scoreboard_normal_color);
break;
@@ -2183,7 +2161,7 @@ void Game::initDifficultyVars()
case GameDifficulty::HARD:
{
default_balloon_speed_ = BALLOON_SPEED_5;
default_balloon_speed_ = BALLOON_SPEED[4];
difficulty_score_multiplier_ = 1.5f;
scoreboard_->setColor(scoreboard_hard_color);
break;