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; gravity_ = param.balloon.at(index).grav;
default_vy_ = param.balloon.at(index).vel; default_vy_ = param.balloon.at(index).vel;
sprite_->disableRotate(); sprite_->setRotate(creation_timer <= 0);
sprite_->setRotateSpeed(0);
sprite_->setRotateAmount(vx_ > 0.0f ? 2.0 : -2.0); sprite_->setRotateAmount(vx_ > 0.0f ? 2.0 : -2.0);
break; break;
@@ -312,16 +311,20 @@ void Balloon::setAnimation()
void Balloon::stop() void Balloon::stop()
{ {
stopped_ = true; stopped_ = true;
if (type_ == BalloonType::POWERBALL) if (isPowerBall())
sprite_->disableRotate(); {
sprite_->setRotate(!stopped_);
}
} }
// Pone el globo en movimiento // Pone el globo en movimiento
void Balloon::start() void Balloon::start()
{ {
stopped_ = false; stopped_ = false;
if (type_ == BalloonType::POWERBALL) if (isPowerBall())
sprite_->enableRotate(); {
sprite_->setRotate(!stopped_);
}
} }
// 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
@@ -396,27 +399,4 @@ void Balloon::useNormalColor()
{ {
use_reversed_colors_ = false; use_reversed_colors_ = false;
setAnimation(); 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(); void useNormalColor();
// Getters // Getters
float getPosX() const; float getPosX() const { return x_; }
float getPosY() const; float getPosY() const { return y_; }
int getWidth() const; int getWidth() const { return w_; }
int getHeight() const; int getHeight() const { return h_; }
BalloonSize getSize() const; BalloonSize getSize() const { return size_; }
BalloonType getType() const; BalloonType getType() const { return type_; }
Uint16 getScore() const; Uint16 getScore() const { return score_; }
Circle &getCollider(); Circle &getCollider() { return collider_; }
Uint8 getMenace() const; Uint8 getMenace() const { return isEnabled() ? menace_ : 0; }
Uint8 getPower() const; Uint8 getPower() const { return power_; }
bool isStopped() const; bool isStopped() const { return stopped_; }
bool isInvulnerable() const; bool isPowerBall() const { return type_ == BalloonType::POWERBALL; }
bool isBeingCreated() const; bool isInvulnerable() const { return invulnerable_; }
bool isEnabled() const; bool isBeingCreated() const { return being_created_; }
bool isUsingReversedColor(); bool isEnabled() const { return enabled_; }
bool canBePopped() const; bool isUsingReversedColor() { return use_reversed_colors_; }
bool canBePopped() const { return !isBeingCreated(); }
// Setters // Setters
void setVelY(float vel_y); void setVelY(float vel_y) { vy_ = vel_y; }
void setSpeed(float speed); void setSpeed(float speed) { speed_ = speed; }
void setInvulnerable(bool value); 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()) for (auto &balloon : balloon_manager_->getBalloons())
{ {
if (!balloon->isStopped() && !balloon->isInvulnerable()) if (!balloon->isStopped() && !balloon->isInvulnerable() && !balloon->isPowerBall())
{ {
if (checkCollision(player->getCollider(), balloon->getCollider())) 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()->setEnabled(true);
smart_sprites_.back()->setFinishedCounter(1); 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()->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()->setRotateSpeed(10);
smart_sprites_.back()->setRotateAmount(90.0); smart_sprites_.back()->setRotateAmount(90.0);
} }

View File

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

View File

@@ -19,7 +19,7 @@ public:
float amount; // Cantidad de grados a girar en cada iteración float amount; // Cantidad de grados a girar en cada iteración
SDL_Point *center; // Centro de rotació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: protected:
@@ -89,9 +89,8 @@ public:
void setAngle(double vaue); void setAngle(double vaue);
void setRotatingCenter(SDL_Point *point); void setRotatingCenter(SDL_Point *point);
// Activa o desactiva el efecto derotación // Activa o desactiva el efecto de rotación
void enableRotate(); void setRotate(bool enable);
void disableRotate();
// Establece el valor de la variable // Establece el valor de la variable
void setRotateSpeed(int value); void setRotateSpeed(int value);