From 79d25fb8122380706db2f3b89caa1a6c1f185d3a Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 16 Nov 2024 12:13:00 +0100 Subject: [PATCH] Nous grafics per a la powerball Nou comportament per a la powerball --- data/gfx/balloon/powerball.png | Bin 1218 -> 1526 bytes source/balloon.cpp | 66 +++++++++++++++++++++------------ source/balloon.h | 2 +- source/balloon_manager.cpp | 12 +++--- source/moving_sprite.cpp | 41 +++----------------- source/moving_sprite.h | 13 ++++--- 6 files changed, 62 insertions(+), 72 deletions(-) diff --git a/data/gfx/balloon/powerball.png b/data/gfx/balloon/powerball.png index cee356f9454648c0562979037249a3401e486a1e..0f80fb25c0d7791511940d22425489d695bbdf55 100644 GIT binary patch literal 1526 zcmVPx)ut`KgRCt{2oK0vOM;L}*c`L2!q*ck!!T1ndXijzniO5~lxd(jk!6qajH(vtj zL6Eb+G(Gf^n+d`=haLhw(ZuI#Le4Sc!vT%pZ+s7+EZR;ivf z5dbQIkJJA0IskJZ)<_!yT1> zfBC5(V+cfXFq98C3jnN=0_iv0k^Ac}Sf2mNFBlU9A{h*&104qhB2yRy0st&uxdaq1 zX|@0J?sp~8vg`GCO#t}*%6WhNm)&65&-;H%*DHb%JD?jU1hW0asY(%oEcl#yw*X+L zef$%>>|yz0EDWAzv|F43(Qbe{tJFpn!l`bZeqXz@bYX{G_^^CY*s$Ds&YeP$o@q(l z@U*%S{NCK!O|mNG6cvGRVLp^Pcrt}R7w)u=@30kR&R|oN&=EEu+<)B0z2g?{KW>Mh zm`HnnP9em}5JE&eXOL@%ic(EYqemm;ivx@vWpkMcxj{ji5MsrHArhOSxFBq~fmWuj zaA$$Sm%*Q{4_>5-1qcVcLIQ)gO_@@21nYvdT@i7^`EP`EEjmF2;|G<-v@0SY(r^P& zCa#F-CD~3#h{8AkfG3rCB^X4hIAUg{pjB>NR9d2C0m3Um`2qC_^rSMcyglPPbfPnR zb)hS5x4O^;1Z|UcaRYJEl5WnH=oKWrC#IgVLLgMr($ne&9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ryUrm%}Ur3-<8pd-pU5lWI&9k6xz z)+v#1Zb`{%J`N)NQwMCG?^%?VxOIg|FNe%%p?d8fcrCyM)sx+`mxgeib z){ZnuqD%eA2`$~D7oNTzs$%r@*kDw-J~l|J2oIR1Q4xG+`bCpILd^~}Kgy%uI(=)e gm(r7c{c{8S2eo$g|I=}nIRF3v07*qoM6N<$f(GhBZ2$lO diff --git a/source/balloon.cpp b/source/balloon.cpp index 28e8444..9c98c6e 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -56,7 +56,7 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel case BalloonType::POWERBALL: { const int index = 3; - h_ = w_ = BALLOON_SIZE[index]; + h_ = w_ = BALLOON_SIZE[4]; power_ = score_ = menace_ = 0; vy_ = 0; @@ -100,32 +100,42 @@ void Balloon::alignTo(int x) // Pinta el globo en la pantalla void Balloon::render() { - if (isBeingCreated()) + if (type_ == BalloonType::POWERBALL) { - // Aplica alpha blending - sprite_->getTexture()->setAlpha(255 - (int)((float)creation_counter_ * (255.0f / (float)creation_counter_ini_))); + // Renderizado para la PowerBall + SDL_Point p = {24, 24}; + sprite_->setRotatingCenter(&p); sprite_->render(); - sprite_->getTexture()->setAlpha(255); + // Añade la máscara del borde y los reflejos + auto sp = std::make_unique(sprite_->getTexture(), sprite_->getPosition()); + sp->setSpriteClip(BALLOON_SIZE[4], 0, BALLOON_SIZE[4], BALLOON_SIZE[4]); + sp->render(); } else { - if (bouncing_.enabled) + // Renderizado para el resto de globos + if (isBeingCreated()) { - // Aplica efecto de bouncing - sprite_->setPos(x_ + bouncing_.despX, y_ + bouncing_.despY); + // Renderizado con transparencia + sprite_->getTexture()->setAlpha(255 - (int)((float)creation_counter_ * (255.0f / (float)creation_counter_ini_))); sprite_->render(); - sprite_->setPos(x_ - bouncing_.despX, y_ - bouncing_.despY); + sprite_->getTexture()->setAlpha(255); } else - sprite_->render(); - } - - // Añade la máscara del borde a la PowerBall - if (type_ == BalloonType::POWERBALL && !isBeingCreated()) - { - auto sp = std::make_unique(sprite_->getTexture(), sprite_->getPosition()); - sp->setSpriteClip(BALLOON_SIZE[3], 0, BALLOON_SIZE[3], BALLOON_SIZE[3]); - sp->render(); + { + if (bouncing_.enabled) + { + // Renderizado con efecto de bouncing + sprite_->setPos(x_ + bouncing_.despX, y_ + bouncing_.despY); + sprite_->render(); + // sprite_->setPos(x_ - bouncing_.despX, y_ - bouncing_.despY); + } + else + { + // Renderizado normal + sprite_->render(); + } + } } } @@ -148,22 +158,28 @@ void Balloon::move() vx_ = -vx_; // Activa el efecto de rebote o invierte la rotación if (type_ == BalloonType::POWERBALL) + { sprite_->switchRotate(); + } else + { enableBounce(); + } } // Mueve el globo en vertical y_ += vy_ * speed_; - // Colisión en la parte superior de la zona de juego - const int min_y = param.game.play_area.rect.y; - if (y_ < min_y) + // Colisión en la parte superior de la zona de juego excepto para la PowerBall + if (type_ != BalloonType::POWERBALL) { - y_ = min_y; - vy_ = -vy_; - if (type_ != BalloonType::POWERBALL) + const int min_y = param.game.play_area.rect.y; + if (y_ < min_y) + { + y_ = min_y; + vy_ = -vy_; enableBounce(); + } } // Colisión en la parte inferior de la zona de juego @@ -173,7 +189,9 @@ void Balloon::move() y_ = max_y; vy_ = -default_vy_; if (type_ != BalloonType::POWERBALL) + { enableBounce(); + } } /* diff --git a/source/balloon.h b/source/balloon.h index 04d9806..372d26b 100644 --- a/source/balloon.h +++ b/source/balloon.h @@ -15,7 +15,7 @@ constexpr int MAX_BOUNCE = 10; constexpr int BALLOON_SCORE[] = {50, 100, 200, 400}; constexpr int BALLOON_POWER[] = {1, 3, 7, 15}; constexpr int BALLOON_MENACE[] = {1, 2, 4, 8}; -constexpr int BALLOON_SIZE[] = {10, 16, 26, 46}; +constexpr int BALLOON_SIZE[] = {10, 16, 26, 48, 49}; // Tamaños de globo enum class BalloonSize : Uint8 diff --git a/source/balloon_manager.cpp b/source/balloon_manager.cpp index 6fc8ad6..a56e2fc 100644 --- a/source/balloon_manager.cpp +++ b/source/balloon_manager.cpp @@ -88,7 +88,7 @@ void BalloonManager::deployBalloonFormation(int stage) createPowerBall(); // Da un poco de margen para que se creen mas enemigos - balloon_deploy_counter_ = 300; + balloon_deploy_counter_ = 10; } else { @@ -171,13 +171,13 @@ void BalloonManager::createChildBalloon(const std::shared_ptr &balloon, // Crea una PowerBall void BalloonManager::createPowerBall() { - constexpr auto values = 6; - constexpr auto pos_y = -BLOCK; - constexpr int creation_time = 300; + constexpr int values = 6; + constexpr int pos_y = -BALLOON_SIZE[4]; + constexpr int creation_time = 0; const auto left = param.game.play_area.rect.x; - const auto center = param.game.play_area.center_x - (BALLOON_SIZE[3] / 2); - const auto right = param.game.play_area.rect.w - BALLOON_SIZE[3]; + const auto center = param.game.play_area.center_x - (BALLOON_SIZE[4] / 2); + const auto right = param.game.play_area.rect.w - BALLOON_SIZE[4]; const auto luck = rand() % values; const int x[values] = {left, left, center, center, right, right}; diff --git a/source/moving_sprite.cpp b/source/moving_sprite.cpp index ac83121..736d73f 100644 --- a/source/moving_sprite.cpp +++ b/source/moving_sprite.cpp @@ -96,6 +96,12 @@ void MovingSprite::setAngle(double value) rotate_.angle = value; } +// Establece el valor de la variable +void MovingSprite::setRotatingCenter(SDL_Point *point) +{ + rotate_.center = point; +} + // Incrementa el valor del ángulo void MovingSprite::updateAngle() { @@ -172,41 +178,6 @@ SDL_RendererFlip MovingSprite::getFlip() return flip_; } -// Obtiene el valor de la variable -float MovingSprite::getPosX() const -{ - return x_; -} - -// Obtiene el valor de la variable -float MovingSprite::getPosY() const -{ - return y_; -} - -// Obtiene el valor de la variable -float MovingSprite::getVelX() const -{ - return vx_; -} - -// Obtiene el valor de la variable -float MovingSprite::getVelY() const -{ - return vy_; -} - -// Obtiene el valor de la variable -float MovingSprite::getAccelX() const -{ - return ax_; -} - -// Obtiene el valor de la variable -float MovingSprite::getAccelY() const -{ - return ay_; -} // Establece la posición y_ el tamaño del objeto void MovingSprite::setPos(SDL_Rect rect) diff --git a/source/moving_sprite.h b/source/moving_sprite.h index b6fc4da..ab3bcca 100644 --- a/source/moving_sprite.h +++ b/source/moving_sprite.h @@ -65,12 +65,12 @@ public: void render() override; // Obtiene la variable - float getPosX() const; - float getPosY() const; - float getVelX() const; - float getVelY() const; - float getAccelX() const; - float getAccelY() const; + float getPosX() const { return x_; } + float getPosY() const { return y_; } + float getVelX() const { return vx_; } + float getVelY() const { return vy_; } + float getAccelX() const { return ax_; } + float getAccelY() const { return ay_; } // Establece la variable void setVelX(float value); @@ -87,6 +87,7 @@ public: // Establece el valor de la variable void setAngle(double vaue); + void setRotatingCenter(SDL_Point *point); // Activa o desactiva el efecto derotación void enableRotate();