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:
{
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<int>(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<int>(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<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
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>(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;