diff --git a/source/balloon.cpp b/source/balloon.cpp index 52d6935..a44b30c 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -24,201 +24,52 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel { case BalloonType::BALLOON: { - switch (size_) - { - case BalloonSize::SIZE1: - // Alto y ancho del objeto - width_ = BALLOON_WIDTH_1; - height_ = BALLOON_WIDTH_1; - power_ = 1; + vel_y_ = 0; + max_vel_y_ = 3.0f; - // Inicializa los valores de velocidad y gravedad - vel_y_ = 0; - max_vel_y_ = 3.0f; - gravity_ = param.balloon_1.grav; - default_vel_y_ = param.balloon_1.vel; + const int size = static_cast(size_); + gravity_ = param.balloon.at(size).grav; + default_vel_y_ = param.balloon.at(size).vel; + height_ = width_ = BALLOON_SIZE[size]; + power_ = BALLOON_POWER[size]; + menace_ = BALLOON_MENACE[size]; + score_ = BALLOON_SCORE[size]; - // Puntos que da el globo al ser destruido - score_ = BALLOON_SCORE_1; - - // Amenaza que genera el globo - menace_ = 1; - - break; - - case BalloonSize::SIZE2: - // Alto y ancho del objeto - width_ = BALLOON_WIDTH_2; - height_ = BALLOON_WIDTH_2; - power_ = 3; - - // Inicializa los valores de velocidad y gravedad - vel_y_ = 0; - max_vel_y_ = 3.0f; - gravity_ = param.balloon_2.grav; - default_vel_y_ = param.balloon_2.vel; - - // Puntos que da el globo al ser destruido - score_ = BALLOON_SCORE_2; - - // Amenaza que genera el globo - menace_ = 2; - - break; - - case BalloonSize::SIZE3: - // Alto y ancho del objeto - width_ = BALLOON_WIDTH_3; - height_ = BALLOON_WIDTH_3; - power_ = 7; - - // Inicializa los valores de velocidad y gravedad - vel_y_ = 0; - max_vel_y_ = 3.0f; - gravity_ = param.balloon_3.grav; - default_vel_y_ = param.balloon_3.vel; - - // Puntos que da el globo al ser destruido - score_ = BALLOON_SCORE_3; - - // Amenaza que genera el globo - menace_ = 4; - - break; - - case BalloonSize::SIZE4: - // Alto y ancho del objeto - width_ = BALLOON_WIDTH_4; - height_ = BALLOON_WIDTH_4; - power_ = 15; - - // Inicializa los valores de velocidad y gravedad - vel_y_ = 0; - max_vel_y_ = 3.0f; - gravity_ = param.balloon_4.grav; - default_vel_y_ = param.balloon_4.vel; - - // Puntos que da el globo al ser destruido - score_ = BALLOON_SCORE_4; - - // Amenaza que genera el globo - menace_ = 8; - - break; - } break; } - case BalloonType::HEXAGON: + case BalloonType::FLOATER: { - switch (size_) - { - case BalloonSize::SIZE1: - // Alto y ancho del objeto - width_ = BALLOON_WIDTH_1; - height_ = BALLOON_WIDTH_1; - power_ = 1; + default_vel_y_ = max_vel_y_ = vel_y_ = fabs(vel_x_ * 2.0f); + gravity_ = 0.00f; - // Inicializa los valores de velocidad y gravedad - vel_y_ = fabs(vel_x_ * 2.0f); - max_vel_y_ = vel_y_; - gravity_ = 0.00f; - default_vel_y_ = vel_y_; + const int size = static_cast(size_); + height_ = width_ = BALLOON_SIZE[size]; + power_ = BALLOON_POWER[size]; + menace_ = BALLOON_MENACE[size]; + score_ = BALLOON_SCORE[size]; - // Puntos que da el globo al ser destruido - score_ = BALLOON_SCORE_1; - - // Amenaza que genera el globo - menace_ = 1; - - break; - - case BalloonSize::SIZE2: - // Alto y ancho del objeto - width_ = BALLOON_WIDTH_2; - height_ = BALLOON_WIDTH_2; - power_ = 3; - - // Inicializa los valores de velocidad y gravedad - vel_y_ = fabs(vel_x_ * 2.0f); - max_vel_y_ = vel_y_; - gravity_ = 0.00f; - default_vel_y_ = vel_y_; - - // Puntos que da el globo al ser destruido - score_ = BALLOON_SCORE_2; - - // Amenaza que genera el globo - menace_ = 2; - - break; - - case BalloonSize::SIZE3: - // Alto y ancho del objeto - width_ = BALLOON_WIDTH_3; - height_ = BALLOON_WIDTH_3; - power_ = 7; - - // Inicializa los valores de velocidad y gravedad - vel_y_ = fabs(vel_x_ * 2.0f); - max_vel_y_ = vel_y_; - gravity_ = 0.00f; - default_vel_y_ = vel_y_; - - // Puntos que da el globo al ser destruido - score_ = BALLOON_SCORE_3; - - // Amenaza que genera el globo - menace_ = 4; - - break; - - case BalloonSize::SIZE4: - // Alto y ancho del objeto - width_ = BALLOON_WIDTH_4; - height_ = BALLOON_WIDTH_4; - power_ = 15; - - // Inicializa los valores de velocidad y gravedad - vel_y_ = fabs(vel_x_ * 2.0f); - max_vel_y_ = vel_y_; - gravity_ = 0.00f; - default_vel_y_ = vel_y_; - - // Puntos que da el globo al ser destruido - score_ = BALLOON_SCORE_4; - - // Amenaza que genera el globo - menace_ = 8; - - break; - } break; } case BalloonType::POWERBALL: { + const int size = 3; // Alto y ancho del objeto - width_ = BALLOON_WIDTH_4; - height_ = BALLOON_WIDTH_4; - power_ = 0; + height_ = width_ = BALLOON_SIZE[size]; + power_ = score_ = menace_ = 0; // Inicializa los valores de velocidad y gravedad vel_y_ = 0; max_vel_y_ = 3.0f; - gravity_ = param.balloon_4.grav; - default_vel_y_ = param.balloon_4.vel; - - // Puntos que da el globo al ser destruido - score_ = 0; - - // Amenaza que genera el globo - menace_ = 0; + gravity_ = param.balloon.at(size).grav; + default_vel_y_ = param.balloon.at(size).vel; // Añade rotación al sprite_ sprite_->disableRotate(); sprite_->setRotateSpeed(0); - vel_x_ > 0.0f ? sprite_->setRotateAmount(2.0) : sprite_->setRotateAmount(-2.0); + sprite_->setRotateAmount(vel_x_ > 0.0f ? 2.0 : -2.0); + break; } @@ -240,11 +91,9 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel // Configura el sprite sprite_->setPos({static_cast(pos_x_), static_cast(pos_y_), width_, height_}); - // Tamaño del circulo de colisión - collider_.r = width_ / 2; - // Alinea el circulo de colisión con el objeto - updateColliders(); + collider_.r = width_ / 2; + shiftColliders(); } // Centra el globo en la posición X @@ -266,7 +115,7 @@ void Balloon::allignTo(int x) sprite_->setPosY(getPosY()); // Alinea el circulo de colisión con el objeto - updateColliders(); + shiftColliders(); } // Pinta el globo en la pantalla @@ -301,7 +150,7 @@ void Balloon::render() if (type_ == BalloonType::POWERBALL && !isBeingCreated()) { auto sp = std::make_unique(sprite_->getTexture(), sprite_->getPosition()); - sp->setSpriteClip(BALLOON_WIDTH_4, 0, BALLOON_WIDTH_4, BALLOON_WIDTH_4); + sp->setSpriteClip(BALLOON_SIZE[3], 0, BALLOON_SIZE[3], BALLOON_SIZE[3]); sp->render(); } } @@ -445,7 +294,7 @@ void Balloon::update() sprite_->update(); move(); updateAnimation(); - updateColliders(); + shiftColliders(); updateState(); updateBounce(); ++counter_; @@ -484,7 +333,7 @@ void Balloon::updateState() sprite_->setPosY(getPosY()); // Actualiza la posición del circulo de colisión - updateColliders(); + shiftColliders(); } creation_counter_--; @@ -541,7 +390,7 @@ void Balloon::updateAnimation() creating_animation = "powerball"; normal_animation = "powerball"; } - else if (type_ == BalloonType::HEXAGON) + else if (type_ == BalloonType::FLOATER) { creating_animation = "red"; normal_animation = "green"; @@ -697,7 +546,7 @@ Circle &Balloon::getCollider() } // Alinea el circulo de colisión con la posición del objeto globo -void Balloon::updateColliders() +void Balloon::shiftColliders() { collider_.x = Uint16(pos_x_ + collider_.r); collider_.y = pos_y_ + collider_.r; diff --git a/source/balloon.h b/source/balloon.h index d9e449b..682c056 100644 --- a/source/balloon.h +++ b/source/balloon.h @@ -6,16 +6,17 @@ #include // para vector #include "animated_sprite.h" // para SpriteAnimated #include "utils.h" // para Circle +#include "param.h" class Texture; // Cantidad de elementos del vector con los valores de la deformación del globo al rebotar constexpr int MAX_BOUNCE = 10; // Puntos de globo -constexpr int BALLOON_SCORE_1 = 50; -constexpr int BALLOON_SCORE_2 = 100; -constexpr int BALLOON_SCORE_3 = 200; -constexpr int BALLOON_SCORE_4 = 400; +constexpr int BALLOON_SCORE[4] = {50, 100, 200, 400}; +constexpr int BALLOON_POWER[4] = {1, 3, 7, 15}; +constexpr int BALLOON_MENACE[4] = {1, 2, 4, 8}; +constexpr int BALLOON_SIZE[4] = {10, 16, 26, 46}; // Tamaños de globo enum class BalloonSize : Uint8 @@ -30,7 +31,7 @@ enum class BalloonSize : Uint8 enum class BalloonType : Uint8 { BALLOON = 0, - HEXAGON = 1, + FLOATER = 1, POWERBALL = 2, }; @@ -50,12 +51,6 @@ constexpr float BALLOON_SPEED_3 = 0.80f; constexpr float BALLOON_SPEED_4 = 0.90f; constexpr float BALLOON_SPEED_5 = 1.00f; -// Tamaño de los globos -constexpr int BALLOON_WIDTH_1 = 10; -constexpr int BALLOON_WIDTH_2 = 16; -constexpr int BALLOON_WIDTH_3 = 26; -constexpr int BALLOON_WIDTH_4 = 46; - // PowerBall constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10; constexpr int POWERBALL_COUNTER = 8; @@ -112,7 +107,7 @@ private: Bouncing bouncing_; // Contiene las variables para el efecto de rebote // Alinea el circulo de colisión con la posición del objeto globo - void updateColliders(); + void shiftColliders(); // Activa el efecto void bounceStart(); diff --git a/source/balloon_formations.cpp b/source/balloon_formations.cpp index defcbb4..d1d7e1d 100644 --- a/source/balloon_formations.cpp +++ b/source/balloon_formations.cpp @@ -16,20 +16,20 @@ void BalloonFormations::initBalloonFormations() { constexpr int y4 = -BLOCK; const int x4_0 = param.game.play_area.rect.x; - const int x4_100 = param.game.play_area.rect.w - BALLOON_WIDTH_4; + const int x4_100 = param.game.play_area.rect.w - BALLOON_SIZE[3]; constexpr int y3 = -BLOCK; const int x3_0 = param.game.play_area.rect.x; - const int x3_100 = param.game.play_area.rect.w - BALLOON_WIDTH_3; + const int x3_100 = param.game.play_area.rect.w - BALLOON_SIZE[2]; constexpr int y2 = -BLOCK; const int x2_0 = param.game.play_area.rect.x; - const int x2_100 = param.game.play_area.rect.w - BALLOON_WIDTH_2; + const int x2_100 = param.game.play_area.rect.w - BALLOON_SIZE[1]; constexpr int y1 = -BLOCK; const int x1_0 = param.game.play_area.rect.x; - const int x1_50 = param.game.play_area.center_x - (BALLOON_WIDTH_1 / 2); - const int x1_100 = param.game.play_area.rect.w - BALLOON_WIDTH_1; + const int x1_50 = param.game.play_area.center_x - (BALLOON_SIZE[0] / 2); + const int x1_100 = param.game.play_area.rect.w - BALLOON_SIZE[0]; // Inicializa a cero las variables for (int j = 0; j < NUMBER_OF_BALLOON_FORMATIONS; ++j) @@ -67,7 +67,7 @@ void BalloonFormations::initBalloonFormations() inc_time = 0; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { - balloon_formation_[j].init[i].x = param.game.play_area.first_quarter_x - (BALLOON_WIDTH_4 / 2) + (i * inc_x); + balloon_formation_[j].init[i].x = param.game.play_area.first_quarter_x - (BALLOON_SIZE[3] / 2) + (i * inc_x); balloon_formation_[j].init[i].y = y4; balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1); balloon_formation_[j].init[i].size = BalloonSize::SIZE4; @@ -77,7 +77,7 @@ void BalloonFormations::initBalloonFormations() // #02 - Cuatro enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro j = 2; balloon_formation_[j].number_of_balloons = 4; - inc_x = BALLOON_WIDTH_2 + 1; + inc_x = BALLOON_SIZE[1] + 1; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -91,7 +91,7 @@ void BalloonFormations::initBalloonFormations() // #03 - Cuatro enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro j = 3; balloon_formation_[j].number_of_balloons = 4; - inc_x = BALLOON_WIDTH_2 + 1; + inc_x = BALLOON_SIZE[1] + 1; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -105,7 +105,7 @@ void BalloonFormations::initBalloonFormations() // #04 - Tres enemigos BALLOON3. 0, 25, 50. Hacia la derecha j = 4; balloon_formation_[j].number_of_balloons = 3; - inc_x = BALLOON_WIDTH_3 * 2; + inc_x = BALLOON_SIZE[2] * 2; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -119,7 +119,7 @@ void BalloonFormations::initBalloonFormations() // #05 - Tres enemigos BALLOON3. 50, 75, 100. Hacia la izquierda j = 5; balloon_formation_[j].number_of_balloons = 3; - inc_x = BALLOON_WIDTH_3 * 2; + inc_x = BALLOON_SIZE[2] * 2; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -133,7 +133,7 @@ void BalloonFormations::initBalloonFormations() // #06 - Tres enemigos BALLOON3. 0, 0, 0. Hacia la derecha j = 6; balloon_formation_[j].number_of_balloons = 3; - inc_x = BALLOON_WIDTH_3 + 1; + inc_x = BALLOON_SIZE[2] + 1; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -147,7 +147,7 @@ void BalloonFormations::initBalloonFormations() // #07 - Tres enemigos BALLOON3. 100, 100, 100. Hacia la izquierda j = 7; balloon_formation_[j].number_of_balloons = 3; - inc_x = BALLOON_WIDTH_3 + 1; + inc_x = BALLOON_SIZE[2] + 1; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -161,7 +161,7 @@ void BalloonFormations::initBalloonFormations() // #08 - Seis enemigos BALLOON1. 0, 0, 0, 0, 0, 0. Hacia la derecha j = 8; balloon_formation_[j].number_of_balloons = 6; - inc_x = BALLOON_WIDTH_1 + 1; + inc_x = BALLOON_SIZE[0] + 1; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -175,7 +175,7 @@ void BalloonFormations::initBalloonFormations() // #09 - Seis enemigos BALLOON1. 100, 100, 100, 100, 100, 100. Hacia la izquierda j = 9; balloon_formation_[j].number_of_balloons = 6; - inc_x = BALLOON_WIDTH_1 + 1; + inc_x = BALLOON_SIZE[0] + 1; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -189,7 +189,7 @@ void BalloonFormations::initBalloonFormations() // #10 - Tres enemigos BALLOON4 seguidos desde la izquierda j = 10; balloon_formation_[j].number_of_balloons = 3; - inc_x = BALLOON_WIDTH_4 + 1; + inc_x = BALLOON_SIZE[3] + 1; inc_time = 15; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -203,7 +203,7 @@ void BalloonFormations::initBalloonFormations() // #11 - Tres enemigos BALLOON4 seguidos desde la derecha j = 11; balloon_formation_[j].number_of_balloons = 3; - inc_x = BALLOON_WIDTH_4 + 1; + inc_x = BALLOON_SIZE[3] + 1; inc_time = 15; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -217,7 +217,7 @@ void BalloonFormations::initBalloonFormations() // #12 - Seis enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro j = 12; balloon_formation_[j].number_of_balloons = 6; - inc_x = BALLOON_WIDTH_2 + 1; + inc_x = BALLOON_SIZE[1] + 1; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -231,7 +231,7 @@ void BalloonFormations::initBalloonFormations() // #13 - Seis enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro j = 13; balloon_formation_[j].number_of_balloons = 6; - inc_x = BALLOON_WIDTH_2 + 1; + inc_x = BALLOON_SIZE[1] + 1; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -245,7 +245,7 @@ void BalloonFormations::initBalloonFormations() // #14 - Cinco enemigos BALLOON3. Hacia la derecha. Separados j = 14; balloon_formation_[j].number_of_balloons = 5; - inc_x = BALLOON_WIDTH_3 * 2; + inc_x = BALLOON_SIZE[2] * 2; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -259,7 +259,7 @@ void BalloonFormations::initBalloonFormations() // #15 - Cinco enemigos BALLOON3. Hacia la izquierda. Separados j = 15; balloon_formation_[j].number_of_balloons = 5; - inc_x = BALLOON_WIDTH_3 * 2; + inc_x = BALLOON_SIZE[2] * 2; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -273,7 +273,7 @@ void BalloonFormations::initBalloonFormations() // #16 - Cinco enemigos BALLOON3. Hacia la derecha. Juntos j = 16; balloon_formation_[j].number_of_balloons = 5; - inc_x = BALLOON_WIDTH_3 + 1; + inc_x = BALLOON_SIZE[2] + 1; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -287,7 +287,7 @@ void BalloonFormations::initBalloonFormations() // #17 - Cinco enemigos BALLOON3. Hacia la izquierda. Juntos j = 17; balloon_formation_[j].number_of_balloons = 5; - inc_x = BALLOON_WIDTH_3 + 1; + inc_x = BALLOON_SIZE[2] + 1; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -301,7 +301,7 @@ void BalloonFormations::initBalloonFormations() // #18 - Doce enemigos BALLOON1. Hacia la derecha. Juntos j = 18; balloon_formation_[j].number_of_balloons = 12; - inc_x = BALLOON_WIDTH_1 + 1; + inc_x = BALLOON_SIZE[0] + 1; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -315,7 +315,7 @@ void BalloonFormations::initBalloonFormations() // #19 - Doce enemigos BALLOON1. Hacia la izquierda. Juntos j = 19; balloon_formation_[j].number_of_balloons = 12; - inc_x = BALLOON_WIDTH_1 + 1; + inc_x = BALLOON_SIZE[0] + 1; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -329,7 +329,7 @@ void BalloonFormations::initBalloonFormations() // #20 - Dos enemigos BALLOON4 seguidos desde la izquierda/derecha. Simetricos j = 20; balloon_formation_[j].number_of_balloons = 4; - inc_x = BALLOON_WIDTH_4 + 1; + inc_x = BALLOON_SIZE[3] + 1; inc_time = 0; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -352,7 +352,7 @@ void BalloonFormations::initBalloonFormations() // #21 - Diez enemigos BALLOON2 uno detras del otro. Izquierda/derecha. Simetricos j = 21; balloon_formation_[j].number_of_balloons = 10; - inc_x = BALLOON_WIDTH_2 + 1; + inc_x = BALLOON_SIZE[1] + 1; inc_time = 3; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -376,7 +376,7 @@ void BalloonFormations::initBalloonFormations() // #22 - Diez enemigos BALLOON3. Hacia la derecha/izquierda. Separados. Simetricos j = 22; balloon_formation_[j].number_of_balloons = 10; - inc_x = BALLOON_WIDTH_3 * 2; + inc_x = BALLOON_SIZE[2] * 2; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -400,7 +400,7 @@ void BalloonFormations::initBalloonFormations() // #23 - Diez enemigos BALLOON3. Hacia la derecha. Juntos. Simetricos j = 23; balloon_formation_[j].number_of_balloons = 10; - inc_x = BALLOON_WIDTH_3 + 1; + inc_x = BALLOON_SIZE[2] + 1; inc_time = 10; for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) { @@ -478,7 +478,7 @@ void BalloonFormations::initBalloonFormations() balloon_formation_[k + 50].init[i].vel_x = balloon_formation_[k].init[i].vel_x; balloon_formation_[k + 50].init[i].creation_counter = balloon_formation_[k].init[i].creation_counter; balloon_formation_[k + 50].init[i].size = balloon_formation_[k].init[i].size; - balloon_formation_[k + 50].init[i].type = BalloonType::HEXAGON; + balloon_formation_[k + 50].init[i].type = BalloonType::FLOATER; } } diff --git a/source/game.cpp b/source/game.cpp index 3cafefe..93bd407 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -448,8 +448,8 @@ void Game::createPowerBall() constexpr int creation_time = 300; const auto left = param.game.play_area.rect.x; - const auto center = param.game.play_area.center_x - (BALLOON_WIDTH_4 / 2); - const auto right = param.game.play_area.rect.w - BALLOON_WIDTH_4; + const auto center = param.game.play_area.center_x - (BALLOON_SIZE[3] / 2); + const auto right = param.game.play_area.rect.w - BALLOON_SIZE[3]; const auto luck = rand() % values; const int x[values] = {left, left, center, center, right, right}; @@ -560,19 +560,19 @@ void Game::destroyBalloon(std::shared_ptr &balloon) switch (balloon->getSize()) { case BalloonSize::SIZE4: - score = BALLOON_SCORE_4 + (2 * BALLOON_SCORE_3) + (4 * BALLOON_SCORE_2) + (8 * BALLOON_SCORE_1); + score = BALLOON_SCORE[3] + (2 * BALLOON_SCORE[2]) + (4 * BALLOON_SCORE[1]) + (8 * BALLOON_SCORE[0]); break; case BalloonSize::SIZE3: - score = BALLOON_SCORE_3 + (2 * BALLOON_SCORE_2) + (4 * BALLOON_SCORE_1); + score = BALLOON_SCORE[2] + (2 * BALLOON_SCORE[1]) + (4 * BALLOON_SCORE[0]); break; case BalloonSize::SIZE2: - score = BALLOON_SCORE_2 + (2 * BALLOON_SCORE_1); + score = BALLOON_SCORE[1] + (2 * BALLOON_SCORE[0]); break; case BalloonSize::SIZE1: - score = BALLOON_SCORE_1; + score = BALLOON_SCORE[0]; break; default: @@ -764,8 +764,8 @@ void Game::checkBulletBalloonCollision() { return; } - player->incScoreMultiplier(); player->addScore(balloon->getScore() * player->getScoreMultiplier() * difficulty_score_multiplier_); + player->incScoreMultiplier(); updateHiScore(); // Suelta el item si se da el caso diff --git a/source/param.cpp b/source/param.cpp index 5088156..4b98408 100644 --- a/source/param.cpp +++ b/source/param.cpp @@ -43,18 +43,14 @@ void initParam() param.title.title_c_c_position = 11; // BACKGROUND - param.background.attenuate_color = (Color){255, 255, 255}; + param.background.attenuate_color = Color(255, 255, 255); param.background.attenuate_alpha = 32; // BALLOONS - param.balloon_1.vel = 2.60f; - param.balloon_1.grav = 0.09f; - param.balloon_2.vel = 3.50f; - param.balloon_2.grav = 0.10f; - param.balloon_3.vel = 4.50f; - param.balloon_3.grav = 0.10f; - param.balloon_4.vel = 4.95f; - param.balloon_4.grav = 0.10f; + param.balloon.emplace_back(0.09f, 2.60f); + param.balloon.emplace_back(0.10f, 3.50f); + param.balloon.emplace_back(0.10f, 4.50f); + param.balloon.emplace_back(0.10f, 4.95f); // NOTIFICATION param.notification.pos_v = NotifyPosition::TOP; @@ -249,42 +245,42 @@ bool setParams(const std::string &var, const std::string &value) // BALLOON else if (var == "balloon_1.vel") { - param.balloon_1.vel = std::stof(value); + param.balloon.at(0).vel = std::stof(value); } else if (var == "balloon_1.grav") { - param.balloon_1.grav = std::stof(value); + param.balloon.at(0).grav = std::stof(value); } else if (var == "balloon_2.vel") { - param.balloon_2.vel = std::stof(value); + param.balloon.at(1).vel = std::stof(value); } else if (var == "balloon_2.grav") { - param.balloon_2.grav = std::stof(value); + param.balloon.at(1).grav = std::stof(value); } else if (var == "balloon_3.vel") { - param.balloon_3.vel = std::stof(value); + param.balloon.at(2).vel = std::stof(value); } else if (var == "balloon_3.grav") { - param.balloon_3.grav = std::stof(value); + param.balloon.at(2).grav = std::stof(value); } else if (var == "balloon_4.vel") { - param.balloon_4.vel = std::stof(value); + param.balloon.at(3).vel = std::stof(value); } else if (var == "balloon_4.grav") { - param.balloon_4.grav = std::stof(value); + param.balloon.at(3).grav = std::stof(value); } // NOTIFICACIONES diff --git a/source/utils.h b/source/utils.h index d08deaa..e86612d 100644 --- a/source/utils.h +++ b/source/utils.h @@ -235,11 +235,14 @@ struct ParamBackground int attenuate_alpha; }; -// Estructura para guardar los parametros de un globo struct ParamBalloon { float grav; // Aceleración en el eje Y. Modifica la velocidad float vel; // Velocidad inicial que tienen al rebotar contra el suelo + + // Constructor + explicit ParamBalloon(float grav_val = 0.0f, float vel_val = 0.0f) + : grav(grav_val), vel(vel_val) {} }; // Estructura para las opciones de las notificaciones @@ -254,13 +257,18 @@ struct ParamNotification // Estructura para almacenar todos los parámetros del juego struct Param { - ParamGame game; // Parametros relacionados con el juego - ParamFade fade; // Parametros para ajustar el fade - SDL_Rect scoreboard; // Posición y tamaño del marcador - ParamTitle title; // Parametros con ajustes para la sección Title - ParamBackground background; // Parametros que afectan a la clase Background - ParamBalloon balloon_1, balloon_2, balloon_3, balloon_4; // Parametros de velocidad y gravedad de cada tipo de globo - ParamNotification notification; // Opciones para las notificaciones + ParamGame game; // Parametros relacionados con el juego + ParamFade fade; // Parametros para ajustar el fade + SDL_Rect scoreboard; // Posición y tamaño del marcador + ParamTitle title; // Parametros con ajustes para la sección Title + ParamBackground background; // Parametros que afectan a la clase Background + std::vector balloon; // Parametros de velocidad y gravedad de cada tipo de globo + ParamNotification notification; // Opciones para las notificaciones + + Param() + { + balloon.reserve(4); // Reservar espacio para 4 elementos + } }; // Calcula el cuadrado de la distancia entre dos puntos