Revisant la classe Balloon
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
#include "texture.h" // para Texture
|
||||
|
||||
// Constructor
|
||||
Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
||||
Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
|
||||
pos_x_(x),
|
||||
pos_y_(y),
|
||||
@@ -16,185 +16,191 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
invulnerable_(creation_timer > 0),
|
||||
creation_counter_(creation_timer),
|
||||
creation_counter_ini_(creation_timer),
|
||||
kind_(kind),
|
||||
type_(type),
|
||||
size_(size),
|
||||
speed_(speed)
|
||||
{
|
||||
|
||||
switch (kind_)
|
||||
switch (type_)
|
||||
{
|
||||
case BALLOON_1:
|
||||
// Alto y ancho del objeto
|
||||
width_ = BALLOON_WIDTH_1;
|
||||
height_ = BALLOON_WIDTH_1;
|
||||
size_ = BALLOON_SIZE_1;
|
||||
power_ = 1;
|
||||
case BalloonType::BALLOON:
|
||||
{
|
||||
switch (size_)
|
||||
{
|
||||
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
|
||||
vel_y_ = 0;
|
||||
max_vel_y_ = 3.0f;
|
||||
gravity_ = param.balloon_1.grav;
|
||||
default_vel_y_ = param.balloon_1.vel;
|
||||
// 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;
|
||||
|
||||
// Puntos que da el globo al ser destruido
|
||||
score_ = BALLOON_SCORE_1;
|
||||
// Puntos que da el globo al ser destruido
|
||||
score_ = BALLOON_SCORE_1;
|
||||
|
||||
// Amenaza que genera el globo
|
||||
menace_ = 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 BALLOON_2:
|
||||
// Alto y ancho del objeto
|
||||
width_ = BALLOON_WIDTH_2;
|
||||
height_ = BALLOON_WIDTH_2;
|
||||
size_ = BALLOON_SIZE_2;
|
||||
power_ = 3;
|
||||
case BalloonType::HEXAGON:
|
||||
{
|
||||
switch (size_)
|
||||
{
|
||||
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
|
||||
vel_y_ = 0;
|
||||
max_vel_y_ = 3.0f;
|
||||
gravity_ = param.balloon_2.grav;
|
||||
default_vel_y_ = param.balloon_2.vel;
|
||||
// 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;
|
||||
// Puntos que da el globo al ser destruido
|
||||
score_ = BALLOON_SCORE_1;
|
||||
|
||||
// Amenaza que genera el globo
|
||||
menace_ = 2;
|
||||
// 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 BALLOON_3:
|
||||
// Alto y ancho del objeto
|
||||
width_ = BALLOON_WIDTH_3;
|
||||
height_ = BALLOON_WIDTH_3;
|
||||
size_ = BALLOON_SIZE_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 BALLOON_4:
|
||||
case BalloonType::POWERBALL:
|
||||
{
|
||||
// Alto y ancho del objeto
|
||||
width_ = BALLOON_WIDTH_4;
|
||||
height_ = BALLOON_WIDTH_4;
|
||||
size_ = BALLOON_SIZE_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;
|
||||
|
||||
case HEXAGON_1:
|
||||
// Alto y ancho del objeto
|
||||
width_ = BALLOON_WIDTH_1;
|
||||
height_ = BALLOON_WIDTH_1;
|
||||
size_ = BALLOON_SIZE_1;
|
||||
power_ = 1;
|
||||
|
||||
// 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_1;
|
||||
|
||||
// Amenaza que genera el globo
|
||||
menace_ = 1;
|
||||
|
||||
break;
|
||||
|
||||
case HEXAGON_2:
|
||||
// Alto y ancho del objeto
|
||||
width_ = BALLOON_WIDTH_2;
|
||||
height_ = BALLOON_WIDTH_2;
|
||||
size_ = BALLOON_SIZE_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 HEXAGON_3:
|
||||
// Alto y ancho del objeto
|
||||
width_ = BALLOON_WIDTH_3;
|
||||
height_ = BALLOON_WIDTH_3;
|
||||
size_ = BALLOON_SIZE_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 HEXAGON_4:
|
||||
// Alto y ancho del objeto
|
||||
width_ = BALLOON_WIDTH_4;
|
||||
height_ = BALLOON_WIDTH_4;
|
||||
size_ = BALLOON_SIZE_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;
|
||||
|
||||
case POWER_BALL:
|
||||
// Alto y ancho del objeto
|
||||
width_ = BALLOON_WIDTH_4;
|
||||
height_ = BALLOON_WIDTH_4;
|
||||
size_ = 4;
|
||||
power_ = 0;
|
||||
|
||||
// Inicializa los valores de velocidad y gravedad
|
||||
@@ -213,8 +219,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16
|
||||
sprite_->disableRotate();
|
||||
sprite_->setRotateSpeed(0);
|
||||
vel_x_ > 0.0f ? sprite_->setRotateAmount(2.0) : sprite_->setRotateAmount(-2.0);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
@@ -270,7 +276,7 @@ void Balloon::render()
|
||||
{
|
||||
if (bouncing_.enabled)
|
||||
{
|
||||
if (kind_ != POWER_BALL)
|
||||
if (type_ != BalloonType::POWERBALL)
|
||||
{
|
||||
// Aplica desplazamiento para el zoom
|
||||
sprite_->setPosX(getPosX() + bouncing_.despX);
|
||||
@@ -292,7 +298,7 @@ void Balloon::render()
|
||||
sprite_->render();
|
||||
}
|
||||
|
||||
if (kind_ == POWER_BALL && !isBeingCreated())
|
||||
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);
|
||||
@@ -323,7 +329,7 @@ void Balloon::move()
|
||||
sprite_->switchRotate();
|
||||
|
||||
// Activa el efecto de rebote
|
||||
if (kind_ != POWER_BALL)
|
||||
if (type_ != BalloonType::POWERBALL)
|
||||
{
|
||||
bounceStart();
|
||||
}
|
||||
@@ -342,7 +348,7 @@ void Balloon::move()
|
||||
vel_y_ = -vel_y_;
|
||||
|
||||
// Activa el efecto de rebote
|
||||
if (kind_ != POWER_BALL)
|
||||
if (type_ != BalloonType::POWERBALL)
|
||||
{
|
||||
bounceStart();
|
||||
}
|
||||
@@ -358,7 +364,7 @@ void Balloon::move()
|
||||
vel_y_ = -default_vel_y_;
|
||||
|
||||
// Activa el efecto de rebote
|
||||
if (kind_ != POWER_BALL)
|
||||
if (type_ != BalloonType::POWERBALL)
|
||||
{
|
||||
bounceStart();
|
||||
}
|
||||
@@ -408,14 +414,12 @@ void Balloon::disable()
|
||||
gravity_ = 0.0f;
|
||||
height_ = 0;
|
||||
invulnerable_ = false;
|
||||
kind_ = 0;
|
||||
max_vel_y_ = 0.0f;
|
||||
menace_ = 0;
|
||||
pos_x_ = 0.0f;
|
||||
pos_y_ = 0.0f;
|
||||
power_ = 0;
|
||||
score_ = 0;
|
||||
size_ = 0;
|
||||
speed_ = 0;
|
||||
stopped_ = false;
|
||||
stopped_counter_ = 0;
|
||||
@@ -492,7 +496,7 @@ void Balloon::updateState()
|
||||
setStop(false);
|
||||
setVisible(true);
|
||||
setInvulnerable(false);
|
||||
if (kind_ == POWER_BALL)
|
||||
if (type_ == BalloonType::POWERBALL)
|
||||
{
|
||||
sprite_->enableRotate();
|
||||
}
|
||||
@@ -502,7 +506,7 @@ void Balloon::updateState()
|
||||
else if (isStopped())
|
||||
{
|
||||
// Si es una powerball deja de rodar
|
||||
if (kind_ == POWER_BALL)
|
||||
if (type_ == BalloonType::POWERBALL)
|
||||
{
|
||||
sprite_->disableRotate();
|
||||
}
|
||||
@@ -518,7 +522,7 @@ void Balloon::updateState()
|
||||
setStop(false);
|
||||
|
||||
// Si es una powerball vuelve a rodar
|
||||
if (kind_ == POWER_BALL)
|
||||
if (type_ == BalloonType::POWERBALL)
|
||||
{
|
||||
sprite_->enableRotate();
|
||||
}
|
||||
@@ -532,27 +536,19 @@ void Balloon::updateAnimation()
|
||||
std::string creating_animation = "blue";
|
||||
std::string normal_animation = "orange";
|
||||
|
||||
if (kind_ == POWER_BALL)
|
||||
if (type_ == BalloonType::POWERBALL)
|
||||
{
|
||||
creating_animation = "powerball";
|
||||
normal_animation = "powerball";
|
||||
}
|
||||
else if (getClass() == HEXAGON_CLASS)
|
||||
else if (type_ == BalloonType::HEXAGON)
|
||||
{
|
||||
creating_animation = "red";
|
||||
normal_animation = "green";
|
||||
}
|
||||
|
||||
// Establece el frame de animación
|
||||
if (isBeingCreated())
|
||||
{
|
||||
sprite_->setCurrentAnimation(creating_animation);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite_->setCurrentAnimation(normal_animation);
|
||||
}
|
||||
|
||||
sprite_->setCurrentAnimation(isBeingCreated() ? creating_animation : normal_animation);
|
||||
sprite_->update();
|
||||
}
|
||||
|
||||
@@ -604,32 +600,16 @@ void Balloon::setSpeed(float speed)
|
||||
speed_ = speed;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
int Balloon::getKind() const
|
||||
{
|
||||
return kind_;
|
||||
}
|
||||
|
||||
// Obtiene del valor de la variable
|
||||
Uint8 Balloon::getSize() const
|
||||
// Obtiene el tamaño del globo
|
||||
BalloonSize Balloon::getSize() const
|
||||
{
|
||||
return size_;
|
||||
}
|
||||
|
||||
// Obtiene la clase a la que pertenece el globo
|
||||
Uint8 Balloon::getClass() const
|
||||
// Obtiene el tipo de globo
|
||||
BalloonType Balloon::getType() const
|
||||
{
|
||||
if ((kind_ >= BALLOON_1) && (kind_ <= BALLOON_4))
|
||||
{
|
||||
return BALLOON_CLASS;
|
||||
}
|
||||
|
||||
else if ((kind_ >= HEXAGON_1) && (kind_ <= HEXAGON_4))
|
||||
{
|
||||
return HEXAGON_CLASS;
|
||||
}
|
||||
|
||||
return BALLOON_CLASS;
|
||||
return type_;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
|
||||
Reference in New Issue
Block a user