corregits bugs de toquetechar vectors i merdes i passats a lists

This commit is contained in:
2025-10-20 12:29:37 +02:00
parent 2b4523d644
commit c8bf9640cf
5 changed files with 62 additions and 63 deletions

View File

@@ -158,8 +158,9 @@ void BalloonManager::deployFormation(int formation_id, float y) {
// Vacia del vector de globos los globos que ya no sirven
void BalloonManager::freeBalloons() {
auto result = std::ranges::remove_if(balloons_, [](const auto& balloon) { return !balloon->isEnabled(); });
balloons_.erase(result.begin(), balloons_.end());
std::erase_if(balloons_, [](const auto& balloon) {
return !balloon->isEnabled();
});
}
// Actualiza el timer de despliegue de globos (time-based)
@@ -194,49 +195,50 @@ auto BalloonManager::createBalloon(Balloon::Config config) -> std::shared_ptr<Ba
}
// Crea un globo a partir de otro globo
void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon>& balloon, const std::string& direction) {
void BalloonManager::createChildBalloon(const std::shared_ptr<Balloon>& parent_balloon, const std::string& direction) {
if (can_deploy_balloons_) {
// Calcula parametros
const int PARENT_HEIGHT = balloon->getHeight();
const int CHILD_HEIGHT = Balloon::WIDTH.at(static_cast<int>(balloon->getSize()) - 1);
const int PARENT_HEIGHT = parent_balloon->getHeight();
const int CHILD_HEIGHT = Balloon::WIDTH.at(static_cast<size_t>(parent_balloon->getSize()) - 1);
const int CHILD_WIDTH = CHILD_HEIGHT;
const float X = direction == "LEFT" ? balloon->getPosX() + (balloon->getWidth() / 3) : balloon->getPosX() + (2 * (balloon->getWidth() / 3));
const float X = direction == "LEFT" ? parent_balloon->getPosX() + (parent_balloon->getWidth() / 3) : parent_balloon->getPosX() + (2 * (parent_balloon->getWidth() / 3));
const float MIN_X = play_area_.x;
const float MAX_X = play_area_.w - CHILD_WIDTH;
Balloon::Config config = {
.x = std::clamp(X - (CHILD_WIDTH / 2), MIN_X, MAX_X),
.y = balloon->getPosY() + ((PARENT_HEIGHT - CHILD_HEIGHT) / 2),
.type = balloon->getType(),
.size = static_cast<Balloon::Size>(static_cast<int>(balloon->getSize()) - 1),
.y = parent_balloon->getPosY() + ((PARENT_HEIGHT - CHILD_HEIGHT) / 2),
.type = parent_balloon->getType(),
.size = static_cast<Balloon::Size>(static_cast<int>(parent_balloon->getSize()) - 1),
.vel_x = direction == "LEFT" ? Balloon::VELX_NEGATIVE : Balloon::VELX_POSITIVE,
.game_tempo = balloon_speed_,
.creation_counter = 0};
// Crea el globo
auto b = createBalloon(config);
// Crea el globo hijo
auto child_balloon = createBalloon(config);
// Establece parametros
constexpr float VEL_Y_BALLOON_PER_S = -150.0F;
switch (b->getType()) {
case Balloon::Type::BALLOON: {
b->setVelY(VEL_Y_BALLOON_PER_S);
break;
// Configura el globo hijo
if (child_balloon != nullptr) {
// Establece parametros
constexpr float VEL_Y_BALLOON_PER_S = -150.0F;
switch (child_balloon->getType()) {
case Balloon::Type::BALLOON: {
child_balloon->setVelY(VEL_Y_BALLOON_PER_S);
break;
}
case Balloon::Type::FLOATER: {
child_balloon->setVelY(Balloon::VELX_NEGATIVE * 2.0F);
break;
}
default:
break;
}
case Balloon::Type::FLOATER: {
const float MODIFIER = (rand() % 2 == 0) ? 1.0F : 1.0F;
b->setVelY(Balloon::VELX_NEGATIVE * 2.0F * MODIFIER);
(rand() % 2 == 0) ? b->alterVelX(1.0F) : b->alterVelX(1.0F);
break;
}
default:
break;
// Herencia de estados
if (parent_balloon->isStopped()) { child_balloon->stop(); }
if (parent_balloon->isUsingReversedColor()) { child_balloon->useReverseColor(); }
}
// Herencia de estados
if (balloon->isStopped()) { b->stop(); }
if (balloon->isUsingReversedColor()) { b->useReverseColor(); }
}
}