Redissenyat el time stopper

This commit is contained in:
2024-10-27 13:36:00 +01:00
parent ddfb3672ea
commit 71f76fda05
12 changed files with 233 additions and 398 deletions

View File

@@ -15,6 +15,7 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
vx_(vel_x),
being_created_(creation_timer > 0),
invulnerable_(creation_timer > 0),
stopped_(creation_timer > 0),
creation_counter_(creation_timer),
creation_counter_ini_(creation_timer),
type_(type),
@@ -83,6 +84,9 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
// Alinea el circulo de colisión con el objeto
collider_.r = w_ / 2;
shiftColliders();
// Establece la animación a usar
setAnimation();
}
// Centra el globo en la posición X
@@ -213,7 +217,6 @@ void Balloon::pop()
void Balloon::update()
{
move();
updateAnimation();
updateState();
updateBounce();
shiftSprite();
@@ -229,7 +232,7 @@ void Balloon::updateState()
if (isBeingCreated())
{
// Actualiza el valor de las variables
setStop(true);
stop();
setInvulnerable(true);
if (creation_counter_ > 0)
@@ -258,34 +261,15 @@ void Balloon::updateState()
{
// El contador ha llegado a cero
being_created_ = false;
// visible_ = true;
setStop(false);
start();
setInvulnerable(false);
if (type_ == BalloonType::POWERBALL)
sprite_->enableRotate();
}
}
else if (isStopped())
{
// Solo comprueba el estado detenido cuando no se está creando
if (type_ == BalloonType::POWERBALL)
sprite_->disableRotate();
// Reduce el contador
if (stopped_counter_ > 0)
--stopped_counter_;
else
{
// Si el contador ha llegado a cero
setStop(false);
if (type_ == BalloonType::POWERBALL)
sprite_->enableRotate();
setAnimation();
}
}
}
// Establece la animación correspondiente al estado
void Balloon::updateAnimation()
void Balloon::setAnimation()
{
std::string creating_animation;
std::string normal_animation;
@@ -307,7 +291,10 @@ void Balloon::updateAnimation()
}
// Establece el frame de animación
sprite_->setCurrentAnimation(isBeingCreated() ? creating_animation : normal_animation);
if (use_reversed_colors_)
sprite_->setCurrentAnimation(creating_animation);
else
sprite_->setCurrentAnimation(isBeingCreated() ? creating_animation : normal_animation);
}
// Comprueba si el globo está habilitado
@@ -364,10 +351,20 @@ BalloonType Balloon::getType() const
return type_;
}
// Establece el valor de la variable
void Balloon::setStop(bool state)
// Detiene el globo
void Balloon::stop()
{
stopped_ = state;
stopped_ = true;
if (type_ == BalloonType::POWERBALL)
sprite_->disableRotate();
}
// Pone el globo en movimiento
void Balloon::start()
{
stopped_ = false;
if (type_ == BalloonType::POWERBALL)
sprite_->enableRotate();
}
// Obtiene del valor de la variable
@@ -376,18 +373,6 @@ bool Balloon::isStopped() const
return stopped_;
}
// Establece el valor de la variable
void Balloon::setBlink(bool value)
{
blinking_ = value;
}
// Obtiene del valor de la variable
bool Balloon::isBlinking() const
{
return blinking_;
}
// Establece el valor de la variable
void Balloon::setInvulnerable(bool value)
{
@@ -406,18 +391,6 @@ bool Balloon::isBeingCreated() const
return being_created_;
}
// Establece el valor de la variable
void Balloon::setStoppedTimer(Uint16 time)
{
stopped_counter_ = time;
}
// Obtiene del valor de la variable
Uint16 Balloon::getStoppedTimer() const
{
return stopped_counter_;
}
// Obtiene del valor de la variable
Uint16 Balloon::getScore() const
{
@@ -509,4 +482,27 @@ bool Balloon::canBePopped() const
bool Balloon::canBeDestroyed() const
{
return isEnabled();
}
// Pone el color alternativo en el globo
void Balloon::useReverseColor()
{
if (!isBeingCreated())
{
use_reversed_colors_ = true;
setAnimation();
}
}
// Pone el color normal en el globo
void Balloon::useNormalColor()
{
use_reversed_colors_ = false;
setAnimation();
}
// Indica si está usando el color alternativo
bool Balloon::isUsingReversedColor()
{
return use_reversed_colors_;
}