diff --git a/source/balloon.cpp b/source/balloon.cpp index af3362c..360f4dd 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -95,10 +95,9 @@ Balloon::Balloon(float x, float y, Type type, Size size, float vel_x, float spee // Centra el globo en la posición X void Balloon::alignTo(int x) { - x_ = static_cast(x - (w_ / 2)); - const int MIN_X = play_area_.x; - const int MAX_X = play_area_.w - w_; - x_ = std::clamp(x_, static_cast(MIN_X), static_cast(MAX_X)); + const float MIN_X = play_area_.x; + const float MAX_X = play_area_.w - w_; + x_ = std::clamp(x - (w_ / 2), MIN_X, MAX_X); } // Pinta el globo en la pantalla diff --git a/source/balloon_manager.cpp b/source/balloon_manager.cpp index 9214235..25d41df 100644 --- a/source/balloon_manager.cpp +++ b/source/balloon_manager.cpp @@ -175,23 +175,22 @@ void BalloonManager::createChildBalloon(const std::shared_ptr &balloon, const auto SIZE = static_cast(static_cast(balloon->getSize()) - 1); const int PARENT_HEIGHT = balloon->getHeight(); const int CHILD_HEIGHT = Balloon::WIDTH.at(static_cast(balloon->getSize()) - 1); - const int Y = balloon->getPosY() + (PARENT_HEIGHT - CHILD_HEIGHT) / 2; - const int X = direction == "LEFT" ? balloon->getPosX() + (balloon->getWidth() / 3) : balloon->getPosX() + 2 * (balloon->getWidth() / 3); + const int CHILD_WIDTH = CHILD_HEIGHT; + const float Y = balloon->getPosY() + ((PARENT_HEIGHT - CHILD_HEIGHT) / 2); + float x = direction == "LEFT" ? balloon->getPosX() + (balloon->getWidth() / 3) : balloon->getPosX() + (2 * (balloon->getWidth() / 3)); + const float MIN_X = play_area_.x; + const float MAX_X = play_area_.w - CHILD_WIDTH; + x = std::clamp(x - (CHILD_WIDTH / 2), MIN_X, MAX_X); // Crea el globo - auto b = createBalloon(0, Y, balloon->getType(), SIZE, VX, balloon_speed_, 0); + auto b = createBalloon(x, Y, balloon->getType(), SIZE, VX, balloon_speed_, 0); // Establece parametros - b->alignTo(X); b->setVelY(b->getType() == Balloon::Type::BALLOON ? -2.50F : Balloon::VELX_NEGATIVE * 2.0F); // Herencia de estados - if (balloon->isStopped()) { - b->stop(); - } - if (balloon->isUsingReversedColor()) { - b->useReverseColor(); - } + if (balloon->isStopped()) { b->stop(); } + if (balloon->isUsingReversedColor()) { b->useReverseColor(); } } }