La powerball ja no mata

La powerball no pillava la rotació si es creava amb el rellotge actiu
This commit is contained in:
2024-11-16 12:45:58 +01:00
parent 065336c310
commit da74b8dfce
5 changed files with 38 additions and 65 deletions

View File

@@ -64,8 +64,7 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
gravity_ = param.balloon.at(index).grav;
default_vy_ = param.balloon.at(index).vel;
sprite_->disableRotate();
sprite_->setRotateSpeed(0);
sprite_->setRotate(creation_timer <= 0);
sprite_->setRotateAmount(vx_ > 0.0f ? 2.0 : -2.0);
break;
@@ -312,16 +311,20 @@ void Balloon::setAnimation()
void Balloon::stop()
{
stopped_ = true;
if (type_ == BalloonType::POWERBALL)
sprite_->disableRotate();
if (isPowerBall())
{
sprite_->setRotate(!stopped_);
}
}
// Pone el globo en movimiento
void Balloon::start()
{
stopped_ = false;
if (type_ == BalloonType::POWERBALL)
sprite_->enableRotate();
if (isPowerBall())
{
sprite_->setRotate(!stopped_);
}
}
// Alinea el circulo de colisión con la posición del objeto globo
@@ -396,27 +399,4 @@ void Balloon::useNormalColor()
{
use_reversed_colors_ = false;
setAnimation();
}
// Getters
float Balloon::getPosX() const { return x_; }
float Balloon::getPosY() const { return y_; }
int Balloon::getWidth() const { return w_; }
int Balloon::getHeight() const { return h_; }
BalloonSize Balloon::getSize() const { return size_; }
BalloonType Balloon::getType() const { return type_; }
Uint16 Balloon::getScore() const { return score_; }
Circle &Balloon::getCollider() { return collider_; }
Uint8 Balloon::getMenace() const { return isEnabled() ? menace_ : 0; }
Uint8 Balloon::getPower() const { return power_; }
bool Balloon::isStopped() const { return stopped_; }
bool Balloon::isInvulnerable() const { return invulnerable_; }
bool Balloon::isBeingCreated() const { return being_created_; }
bool Balloon::isEnabled() const { return enabled_; }
bool Balloon::isUsingReversedColor() { return use_reversed_colors_; }
bool Balloon::canBePopped() const { return !isBeingCreated(); }
// Setters
void Balloon::setVelY(float vel_y) { vy_ = vel_y; }
void Balloon::setSpeed(float speed) { speed_ = speed; }
void Balloon::setInvulnerable(bool value) { invulnerable_ = value; }
}

View File

@@ -174,25 +174,26 @@ public:
void useNormalColor();
// Getters
float getPosX() const;
float getPosY() const;
int getWidth() const;
int getHeight() const;
BalloonSize getSize() const;
BalloonType getType() const;
Uint16 getScore() const;
Circle &getCollider();
Uint8 getMenace() const;
Uint8 getPower() const;
bool isStopped() const;
bool isInvulnerable() const;
bool isBeingCreated() const;
bool isEnabled() const;
bool isUsingReversedColor();
bool canBePopped() const;
float getPosX() const { return x_; }
float getPosY() const { return y_; }
int getWidth() const { return w_; }
int getHeight() const { return h_; }
BalloonSize getSize() const { return size_; }
BalloonType getType() const { return type_; }
Uint16 getScore() const { return score_; }
Circle &getCollider() { return collider_; }
Uint8 getMenace() const { return isEnabled() ? menace_ : 0; }
Uint8 getPower() const { return power_; }
bool isStopped() const { return stopped_; }
bool isPowerBall() const { return type_ == BalloonType::POWERBALL; }
bool isInvulnerable() const { return invulnerable_; }
bool isBeingCreated() const { return being_created_; }
bool isEnabled() const { return enabled_; }
bool isUsingReversedColor() { return use_reversed_colors_; }
bool canBePopped() const { return !isBeingCreated(); }
// Setters
void setVelY(float vel_y);
void setSpeed(float speed);
void setInvulnerable(bool value);
void setVelY(float vel_y) { vy_ = vel_y; }
void setSpeed(float speed) { speed_ = speed; }
void setInvulnerable(bool value) { invulnerable_ = value; }
};

View File

@@ -385,7 +385,7 @@ bool Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player)
{
for (auto &balloon : balloon_manager_->getBalloons())
{
if (!balloon->isStopped() && !balloon->isInvulnerable())
if (!balloon->isStopped() && !balloon->isInvulnerable() && !balloon->isPowerBall())
{
if (checkCollision(player->getCollider(), balloon->getCollider()))
{
@@ -753,7 +753,7 @@ void Game::throwCoffee(int x, int y)
smart_sprites_.back()->setEnabled(true);
smart_sprites_.back()->setFinishedCounter(1);
smart_sprites_.back()->setSpriteClip(0, param.game.item_size, param.game.item_size, param.game.item_size);
smart_sprites_.back()->enableRotate();
smart_sprites_.back()->setRotate(true);
smart_sprites_.back()->setRotateSpeed(10);
smart_sprites_.back()->setRotateAmount(90.0);
}

View File

@@ -128,17 +128,10 @@ void MovingSprite::rotate()
}
}
// Establece el valor de la variable
void MovingSprite::enableRotate()
// Activa o desactiva el efecto de rotación
void MovingSprite::setRotate(bool enable)
{
rotate_.enabled = true;
rotate_.counter = 0;
}
// Establece el valor de la variable
void MovingSprite::disableRotate()
{
rotate_.enabled = false;
rotate_.enabled = enable;
rotate_.counter = 0;
}

View File

@@ -19,7 +19,7 @@ public:
float amount; // Cantidad de grados a girar en cada iteración
SDL_Point *center; // Centro de rotación
Rotate() : enabled(false), counter(0), speed(0), angle(0.0), amount(0.0f), center(nullptr) {}
Rotate() : enabled(false), counter(0), speed(1), angle(0.0), amount(0.0f), center(nullptr) {}
};
protected:
@@ -89,9 +89,8 @@ public:
void setAngle(double vaue);
void setRotatingCenter(SDL_Point *point);
// Activa o desactiva el efecto derotación
void enableRotate();
void disableRotate();
// Activa o desactiva el efecto de rotación
void setRotate(bool enable);
// Establece el valor de la variable
void setRotateSpeed(int value);