Revisant la classe Balloon

This commit is contained in:
2024-10-26 14:13:08 +02:00
parent de2a29b669
commit f750997b34
6 changed files with 104 additions and 256 deletions

View File

@@ -24,201 +24,52 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
{ {
case BalloonType::BALLOON: case BalloonType::BALLOON:
{ {
switch (size_) vel_y_ = 0;
{ max_vel_y_ = 3.0f;
case BalloonSize::SIZE1:
// Alto y ancho del objeto
width_ = BALLOON_WIDTH_1;
height_ = BALLOON_WIDTH_1;
power_ = 1;
// Inicializa los valores de velocidad y gravedad const int size = static_cast<int>(size_);
vel_y_ = 0; gravity_ = param.balloon.at(size).grav;
max_vel_y_ = 3.0f; default_vel_y_ = param.balloon.at(size).vel;
gravity_ = param.balloon_1.grav; height_ = width_ = BALLOON_SIZE[size];
default_vel_y_ = param.balloon_1.vel; 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; break;
} }
case BalloonType::HEXAGON: case BalloonType::FLOATER:
{ {
switch (size_) default_vel_y_ = max_vel_y_ = vel_y_ = fabs(vel_x_ * 2.0f);
{ gravity_ = 0.00f;
case BalloonSize::SIZE1:
// Alto y ancho del objeto
width_ = BALLOON_WIDTH_1;
height_ = BALLOON_WIDTH_1;
power_ = 1;
// Inicializa los valores de velocidad y gravedad const int size = static_cast<int>(size_);
vel_y_ = fabs(vel_x_ * 2.0f); height_ = width_ = BALLOON_SIZE[size];
max_vel_y_ = vel_y_; power_ = BALLOON_POWER[size];
gravity_ = 0.00f; menace_ = BALLOON_MENACE[size];
default_vel_y_ = vel_y_; 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; break;
} }
case BalloonType::POWERBALL: case BalloonType::POWERBALL:
{ {
const int size = 3;
// Alto y ancho del objeto // Alto y ancho del objeto
width_ = BALLOON_WIDTH_4; height_ = width_ = BALLOON_SIZE[size];
height_ = BALLOON_WIDTH_4; power_ = score_ = menace_ = 0;
power_ = 0;
// Inicializa los valores de velocidad y gravedad // Inicializa los valores de velocidad y gravedad
vel_y_ = 0; vel_y_ = 0;
max_vel_y_ = 3.0f; max_vel_y_ = 3.0f;
gravity_ = param.balloon_4.grav; gravity_ = param.balloon.at(size).grav;
default_vel_y_ = param.balloon_4.vel; default_vel_y_ = param.balloon.at(size).vel;
// Puntos que da el globo al ser destruido
score_ = 0;
// Amenaza que genera el globo
menace_ = 0;
// Añade rotación al sprite_ // Añade rotación al sprite_
sprite_->disableRotate(); sprite_->disableRotate();
sprite_->setRotateSpeed(0); 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; break;
} }
@@ -240,11 +91,9 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
// Configura el sprite // Configura el sprite
sprite_->setPos({static_cast<int>(pos_x_), static_cast<int>(pos_y_), width_, height_}); sprite_->setPos({static_cast<int>(pos_x_), static_cast<int>(pos_y_), width_, height_});
// Tamaño del circulo de colisión
collider_.r = width_ / 2;
// Alinea el circulo de colisión con el objeto // Alinea el circulo de colisión con el objeto
updateColliders(); collider_.r = width_ / 2;
shiftColliders();
} }
// Centra el globo en la posición X // Centra el globo en la posición X
@@ -266,7 +115,7 @@ void Balloon::allignTo(int x)
sprite_->setPosY(getPosY()); sprite_->setPosY(getPosY());
// Alinea el circulo de colisión con el objeto // Alinea el circulo de colisión con el objeto
updateColliders(); shiftColliders();
} }
// Pinta el globo en la pantalla // Pinta el globo en la pantalla
@@ -301,7 +150,7 @@ void Balloon::render()
if (type_ == BalloonType::POWERBALL && !isBeingCreated()) if (type_ == BalloonType::POWERBALL && !isBeingCreated())
{ {
auto sp = std::make_unique<Sprite>(sprite_->getTexture(), sprite_->getPosition()); auto sp = std::make_unique<Sprite>(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(); sp->render();
} }
} }
@@ -445,7 +294,7 @@ void Balloon::update()
sprite_->update(); sprite_->update();
move(); move();
updateAnimation(); updateAnimation();
updateColliders(); shiftColliders();
updateState(); updateState();
updateBounce(); updateBounce();
++counter_; ++counter_;
@@ -484,7 +333,7 @@ void Balloon::updateState()
sprite_->setPosY(getPosY()); sprite_->setPosY(getPosY());
// Actualiza la posición del circulo de colisión // Actualiza la posición del circulo de colisión
updateColliders(); shiftColliders();
} }
creation_counter_--; creation_counter_--;
@@ -541,7 +390,7 @@ void Balloon::updateAnimation()
creating_animation = "powerball"; creating_animation = "powerball";
normal_animation = "powerball"; normal_animation = "powerball";
} }
else if (type_ == BalloonType::HEXAGON) else if (type_ == BalloonType::FLOATER)
{ {
creating_animation = "red"; creating_animation = "red";
normal_animation = "green"; normal_animation = "green";
@@ -697,7 +546,7 @@ Circle &Balloon::getCollider()
} }
// Alinea el circulo de colisión con la posición del objeto globo // 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_.x = Uint16(pos_x_ + collider_.r);
collider_.y = pos_y_ + collider_.r; collider_.y = pos_y_ + collider_.r;

View File

@@ -6,16 +6,17 @@
#include <vector> // para vector #include <vector> // para vector
#include "animated_sprite.h" // para SpriteAnimated #include "animated_sprite.h" // para SpriteAnimated
#include "utils.h" // para Circle #include "utils.h" // para Circle
#include "param.h"
class Texture; class Texture;
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar // Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
constexpr int MAX_BOUNCE = 10; constexpr int MAX_BOUNCE = 10;
// Puntos de globo // Puntos de globo
constexpr int BALLOON_SCORE_1 = 50; constexpr int BALLOON_SCORE[4] = {50, 100, 200, 400};
constexpr int BALLOON_SCORE_2 = 100; constexpr int BALLOON_POWER[4] = {1, 3, 7, 15};
constexpr int BALLOON_SCORE_3 = 200; constexpr int BALLOON_MENACE[4] = {1, 2, 4, 8};
constexpr int BALLOON_SCORE_4 = 400; constexpr int BALLOON_SIZE[4] = {10, 16, 26, 46};
// Tamaños de globo // Tamaños de globo
enum class BalloonSize : Uint8 enum class BalloonSize : Uint8
@@ -30,7 +31,7 @@ enum class BalloonSize : Uint8
enum class BalloonType : Uint8 enum class BalloonType : Uint8
{ {
BALLOON = 0, BALLOON = 0,
HEXAGON = 1, FLOATER = 1,
POWERBALL = 2, POWERBALL = 2,
}; };
@@ -50,12 +51,6 @@ constexpr float BALLOON_SPEED_3 = 0.80f;
constexpr float BALLOON_SPEED_4 = 0.90f; constexpr float BALLOON_SPEED_4 = 0.90f;
constexpr float BALLOON_SPEED_5 = 1.00f; 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 // PowerBall
constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10; constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10;
constexpr int POWERBALL_COUNTER = 8; constexpr int POWERBALL_COUNTER = 8;
@@ -112,7 +107,7 @@ private:
Bouncing bouncing_; // Contiene las variables para el efecto de rebote Bouncing bouncing_; // Contiene las variables para el efecto de rebote
// Alinea el circulo de colisión con la posición del objeto globo // Alinea el circulo de colisión con la posición del objeto globo
void updateColliders(); void shiftColliders();
// Activa el efecto // Activa el efecto
void bounceStart(); void bounceStart();

View File

@@ -16,20 +16,20 @@ void BalloonFormations::initBalloonFormations()
{ {
constexpr int y4 = -BLOCK; constexpr int y4 = -BLOCK;
const int x4_0 = param.game.play_area.rect.x; 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; constexpr int y3 = -BLOCK;
const int x3_0 = param.game.play_area.rect.x; 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; constexpr int y2 = -BLOCK;
const int x2_0 = param.game.play_area.rect.x; 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; constexpr int y1 = -BLOCK;
const int x1_0 = param.game.play_area.rect.x; 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_50 = param.game.play_area.center_x - (BALLOON_SIZE[0] / 2);
const int x1_100 = param.game.play_area.rect.w - BALLOON_WIDTH_1; const int x1_100 = param.game.play_area.rect.w - BALLOON_SIZE[0];
// Inicializa a cero las variables // Inicializa a cero las variables
for (int j = 0; j < NUMBER_OF_BALLOON_FORMATIONS; ++j) for (int j = 0; j < NUMBER_OF_BALLOON_FORMATIONS; ++j)
@@ -67,7 +67,7 @@ void BalloonFormations::initBalloonFormations()
inc_time = 0; inc_time = 0;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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].y = y4;
balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1); balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1);
balloon_formation_[j].init[i].size = BalloonSize::SIZE4; 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 // #02 - Cuatro enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro
j = 2; j = 2;
balloon_formation_[j].number_of_balloons = 4; balloon_formation_[j].number_of_balloons = 4;
inc_x = BALLOON_WIDTH_2 + 1; inc_x = BALLOON_SIZE[1] + 1;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #03 - Cuatro enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro
j = 3; j = 3;
balloon_formation_[j].number_of_balloons = 4; balloon_formation_[j].number_of_balloons = 4;
inc_x = BALLOON_WIDTH_2 + 1; inc_x = BALLOON_SIZE[1] + 1;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #04 - Tres enemigos BALLOON3. 0, 25, 50. Hacia la derecha
j = 4; j = 4;
balloon_formation_[j].number_of_balloons = 3; balloon_formation_[j].number_of_balloons = 3;
inc_x = BALLOON_WIDTH_3 * 2; inc_x = BALLOON_SIZE[2] * 2;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #05 - Tres enemigos BALLOON3. 50, 75, 100. Hacia la izquierda
j = 5; j = 5;
balloon_formation_[j].number_of_balloons = 3; balloon_formation_[j].number_of_balloons = 3;
inc_x = BALLOON_WIDTH_3 * 2; inc_x = BALLOON_SIZE[2] * 2;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #06 - Tres enemigos BALLOON3. 0, 0, 0. Hacia la derecha
j = 6; j = 6;
balloon_formation_[j].number_of_balloons = 3; balloon_formation_[j].number_of_balloons = 3;
inc_x = BALLOON_WIDTH_3 + 1; inc_x = BALLOON_SIZE[2] + 1;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #07 - Tres enemigos BALLOON3. 100, 100, 100. Hacia la izquierda
j = 7; j = 7;
balloon_formation_[j].number_of_balloons = 3; balloon_formation_[j].number_of_balloons = 3;
inc_x = BALLOON_WIDTH_3 + 1; inc_x = BALLOON_SIZE[2] + 1;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #08 - Seis enemigos BALLOON1. 0, 0, 0, 0, 0, 0. Hacia la derecha
j = 8; j = 8;
balloon_formation_[j].number_of_balloons = 6; balloon_formation_[j].number_of_balloons = 6;
inc_x = BALLOON_WIDTH_1 + 1; inc_x = BALLOON_SIZE[0] + 1;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #09 - Seis enemigos BALLOON1. 100, 100, 100, 100, 100, 100. Hacia la izquierda
j = 9; j = 9;
balloon_formation_[j].number_of_balloons = 6; balloon_formation_[j].number_of_balloons = 6;
inc_x = BALLOON_WIDTH_1 + 1; inc_x = BALLOON_SIZE[0] + 1;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #10 - Tres enemigos BALLOON4 seguidos desde la izquierda
j = 10; j = 10;
balloon_formation_[j].number_of_balloons = 3; balloon_formation_[j].number_of_balloons = 3;
inc_x = BALLOON_WIDTH_4 + 1; inc_x = BALLOON_SIZE[3] + 1;
inc_time = 15; inc_time = 15;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #11 - Tres enemigos BALLOON4 seguidos desde la derecha
j = 11; j = 11;
balloon_formation_[j].number_of_balloons = 3; balloon_formation_[j].number_of_balloons = 3;
inc_x = BALLOON_WIDTH_4 + 1; inc_x = BALLOON_SIZE[3] + 1;
inc_time = 15; inc_time = 15;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #12 - Seis enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro
j = 12; j = 12;
balloon_formation_[j].number_of_balloons = 6; balloon_formation_[j].number_of_balloons = 6;
inc_x = BALLOON_WIDTH_2 + 1; inc_x = BALLOON_SIZE[1] + 1;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #13 - Seis enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro
j = 13; j = 13;
balloon_formation_[j].number_of_balloons = 6; balloon_formation_[j].number_of_balloons = 6;
inc_x = BALLOON_WIDTH_2 + 1; inc_x = BALLOON_SIZE[1] + 1;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #14 - Cinco enemigos BALLOON3. Hacia la derecha. Separados
j = 14; j = 14;
balloon_formation_[j].number_of_balloons = 5; balloon_formation_[j].number_of_balloons = 5;
inc_x = BALLOON_WIDTH_3 * 2; inc_x = BALLOON_SIZE[2] * 2;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #15 - Cinco enemigos BALLOON3. Hacia la izquierda. Separados
j = 15; j = 15;
balloon_formation_[j].number_of_balloons = 5; balloon_formation_[j].number_of_balloons = 5;
inc_x = BALLOON_WIDTH_3 * 2; inc_x = BALLOON_SIZE[2] * 2;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #16 - Cinco enemigos BALLOON3. Hacia la derecha. Juntos
j = 16; j = 16;
balloon_formation_[j].number_of_balloons = 5; balloon_formation_[j].number_of_balloons = 5;
inc_x = BALLOON_WIDTH_3 + 1; inc_x = BALLOON_SIZE[2] + 1;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #17 - Cinco enemigos BALLOON3. Hacia la izquierda. Juntos
j = 17; j = 17;
balloon_formation_[j].number_of_balloons = 5; balloon_formation_[j].number_of_balloons = 5;
inc_x = BALLOON_WIDTH_3 + 1; inc_x = BALLOON_SIZE[2] + 1;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #18 - Doce enemigos BALLOON1. Hacia la derecha. Juntos
j = 18; j = 18;
balloon_formation_[j].number_of_balloons = 12; balloon_formation_[j].number_of_balloons = 12;
inc_x = BALLOON_WIDTH_1 + 1; inc_x = BALLOON_SIZE[0] + 1;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #19 - Doce enemigos BALLOON1. Hacia la izquierda. Juntos
j = 19; j = 19;
balloon_formation_[j].number_of_balloons = 12; balloon_formation_[j].number_of_balloons = 12;
inc_x = BALLOON_WIDTH_1 + 1; inc_x = BALLOON_SIZE[0] + 1;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #20 - Dos enemigos BALLOON4 seguidos desde la izquierda/derecha. Simetricos
j = 20; j = 20;
balloon_formation_[j].number_of_balloons = 4; balloon_formation_[j].number_of_balloons = 4;
inc_x = BALLOON_WIDTH_4 + 1; inc_x = BALLOON_SIZE[3] + 1;
inc_time = 0; inc_time = 0;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #21 - Diez enemigos BALLOON2 uno detras del otro. Izquierda/derecha. Simetricos
j = 21; j = 21;
balloon_formation_[j].number_of_balloons = 10; balloon_formation_[j].number_of_balloons = 10;
inc_x = BALLOON_WIDTH_2 + 1; inc_x = BALLOON_SIZE[1] + 1;
inc_time = 3; inc_time = 3;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #22 - Diez enemigos BALLOON3. Hacia la derecha/izquierda. Separados. Simetricos
j = 22; j = 22;
balloon_formation_[j].number_of_balloons = 10; balloon_formation_[j].number_of_balloons = 10;
inc_x = BALLOON_WIDTH_3 * 2; inc_x = BALLOON_SIZE[2] * 2;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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 // #23 - Diez enemigos BALLOON3. Hacia la derecha. Juntos. Simetricos
j = 23; j = 23;
balloon_formation_[j].number_of_balloons = 10; balloon_formation_[j].number_of_balloons = 10;
inc_x = BALLOON_WIDTH_3 + 1; inc_x = BALLOON_SIZE[2] + 1;
inc_time = 10; inc_time = 10;
for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) 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].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].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].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;
} }
} }

View File

@@ -448,8 +448,8 @@ void Game::createPowerBall()
constexpr int creation_time = 300; constexpr int creation_time = 300;
const auto left = param.game.play_area.rect.x; const auto left = param.game.play_area.rect.x;
const auto center = param.game.play_area.center_x - (BALLOON_WIDTH_4 / 2); const auto center = param.game.play_area.center_x - (BALLOON_SIZE[3] / 2);
const auto right = param.game.play_area.rect.w - BALLOON_WIDTH_4; const auto right = param.game.play_area.rect.w - BALLOON_SIZE[3];
const auto luck = rand() % values; const auto luck = rand() % values;
const int x[values] = {left, left, center, center, right, right}; const int x[values] = {left, left, center, center, right, right};
@@ -560,19 +560,19 @@ void Game::destroyBalloon(std::shared_ptr<Balloon> &balloon)
switch (balloon->getSize()) switch (balloon->getSize())
{ {
case BalloonSize::SIZE4: 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; break;
case BalloonSize::SIZE3: 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; break;
case BalloonSize::SIZE2: case BalloonSize::SIZE2:
score = BALLOON_SCORE_2 + (2 * BALLOON_SCORE_1); score = BALLOON_SCORE[1] + (2 * BALLOON_SCORE[0]);
break; break;
case BalloonSize::SIZE1: case BalloonSize::SIZE1:
score = BALLOON_SCORE_1; score = BALLOON_SCORE[0];
break; break;
default: default:
@@ -764,8 +764,8 @@ void Game::checkBulletBalloonCollision()
{ {
return; return;
} }
player->incScoreMultiplier();
player->addScore(balloon->getScore() * player->getScoreMultiplier() * difficulty_score_multiplier_); player->addScore(balloon->getScore() * player->getScoreMultiplier() * difficulty_score_multiplier_);
player->incScoreMultiplier();
updateHiScore(); updateHiScore();
// Suelta el item si se da el caso // Suelta el item si se da el caso

View File

@@ -43,18 +43,14 @@ void initParam()
param.title.title_c_c_position = 11; param.title.title_c_c_position = 11;
// BACKGROUND // BACKGROUND
param.background.attenuate_color = (Color){255, 255, 255}; param.background.attenuate_color = Color(255, 255, 255);
param.background.attenuate_alpha = 32; param.background.attenuate_alpha = 32;
// BALLOONS // BALLOONS
param.balloon_1.vel = 2.60f; param.balloon.emplace_back(0.09f, 2.60f);
param.balloon_1.grav = 0.09f; param.balloon.emplace_back(0.10f, 3.50f);
param.balloon_2.vel = 3.50f; param.balloon.emplace_back(0.10f, 4.50f);
param.balloon_2.grav = 0.10f; param.balloon.emplace_back(0.10f, 4.95f);
param.balloon_3.vel = 4.50f;
param.balloon_3.grav = 0.10f;
param.balloon_4.vel = 4.95f;
param.balloon_4.grav = 0.10f;
// NOTIFICATION // NOTIFICATION
param.notification.pos_v = NotifyPosition::TOP; param.notification.pos_v = NotifyPosition::TOP;
@@ -249,42 +245,42 @@ bool setParams(const std::string &var, const std::string &value)
// BALLOON // BALLOON
else if (var == "balloon_1.vel") 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") 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") 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") 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") 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") 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") 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") else if (var == "balloon_4.grav")
{ {
param.balloon_4.grav = std::stof(value); param.balloon.at(3).grav = std::stof(value);
} }
// NOTIFICACIONES // NOTIFICACIONES

View File

@@ -235,11 +235,14 @@ struct ParamBackground
int attenuate_alpha; int attenuate_alpha;
}; };
// Estructura para guardar los parametros de un globo
struct ParamBalloon struct ParamBalloon
{ {
float grav; // Aceleración en el eje Y. Modifica la velocidad float grav; // Aceleración en el eje Y. Modifica la velocidad
float vel; // Velocidad inicial que tienen al rebotar contra el suelo 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 // Estructura para las opciones de las notificaciones
@@ -254,13 +257,18 @@ struct ParamNotification
// Estructura para almacenar todos los parámetros del juego // Estructura para almacenar todos los parámetros del juego
struct Param struct Param
{ {
ParamGame game; // Parametros relacionados con el juego ParamGame game; // Parametros relacionados con el juego
ParamFade fade; // Parametros para ajustar el fade ParamFade fade; // Parametros para ajustar el fade
SDL_Rect scoreboard; // Posición y tamaño del marcador SDL_Rect scoreboard; // Posición y tamaño del marcador
ParamTitle title; // Parametros con ajustes para la sección Title ParamTitle title; // Parametros con ajustes para la sección Title
ParamBackground background; // Parametros que afectan a la clase Background 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 std::vector<ParamBalloon> balloon; // Parametros de velocidad y gravedad de cada tipo de globo
ParamNotification notification; // Opciones para las notificaciones ParamNotification notification; // Opciones para las notificaciones
Param()
{
balloon.reserve(4); // Reservar espacio para 4 elementos
}
}; };
// Calcula el cuadrado de la distancia entre dos puntos // Calcula el cuadrado de la distancia entre dos puntos