balloon: millor empaquetada la estructura BounceEffect

This commit is contained in:
2025-07-24 14:16:16 +02:00
parent c23e779b9c
commit 2932664b9f
2 changed files with 90 additions and 48 deletions

View File

@@ -343,43 +343,16 @@ void Balloon::shiftSprite() {
sprite_->setPosY(y_);
}
// Aplica la deformación visual causada por el efecto de rebote
void Balloon::applyBounceEffect() {
sprite_->setHorizontalZoom(bounce_effect_.horizontal_zoom);
sprite_->setVerticalZoom(bounce_effect_.verical_zoom);
}
// Activa el efecto
void Balloon::enableBounceEffect() {
// Los globos pequeños no tienen efecto de rebote
if (size_ == Size::SMALL) {
return;
}
bounce_effect_.enabled = true;
bounce_effect_.reset();
applyBounceEffect();
bounce_effect_.enable(sprite_.get(), size_);
}
// Detiene el efecto
void Balloon::disableBounceEffect() {
bounce_effect_.enabled = false;
bounce_effect_.reset();
applyBounceEffect();
bounce_effect_.disable(sprite_.get());
}
// Aplica el efecto
void Balloon::updateBounceEffect() {
if (bounce_effect_.enabled) {
const int INDEX = bounce_effect_.counter / bounce_effect_.speed;
bounce_effect_.horizontal_zoom = bounce_effect_.horizontal_zoom_values.at(INDEX);
bounce_effect_.verical_zoom = bounce_effect_.vertical_zoom_values.at(INDEX);
applyBounceEffect();
if (++bounce_effect_.counter / bounce_effect_.speed >= MAX_BOUNCE) {
disableBounceEffect();
}
}
bounce_effect_.update(sprite_.get());
}
// Pone el color alternativo en el globo