Nous grafics per a la powerball

Nou comportament per a la powerball
This commit is contained in:
2024-11-16 12:13:00 +01:00
parent 6262b5814d
commit 79d25fb812
6 changed files with 62 additions and 72 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -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,9 +100,23 @@ void Balloon::alignTo(int x)
// Pinta el globo en la pantalla
void Balloon::render()
{
if (type_ == BalloonType::POWERBALL)
{
// Renderizado para la PowerBall
SDL_Point p = {24, 24};
sprite_->setRotatingCenter(&p);
sprite_->render();
// Añade la máscara del borde y los reflejos
auto sp = std::make_unique<Sprite>(sprite_->getTexture(), sprite_->getPosition());
sp->setSpriteClip(BALLOON_SIZE[4], 0, BALLOON_SIZE[4], BALLOON_SIZE[4]);
sp->render();
}
else
{
// Renderizado para el resto de globos
if (isBeingCreated())
{
// Aplica alpha blending
// Renderizado con transparencia
sprite_->getTexture()->setAlpha(255 - (int)((float)creation_counter_ * (255.0f / (float)creation_counter_ini_)));
sprite_->render();
sprite_->getTexture()->setAlpha(255);
@@ -111,21 +125,17 @@ void Balloon::render()
{
if (bouncing_.enabled)
{
// Aplica efecto de bouncing
// Renderizado con efecto de bouncing
sprite_->setPos(x_ + bouncing_.despX, y_ + bouncing_.despY);
sprite_->render();
sprite_->setPos(x_ - bouncing_.despX, y_ - bouncing_.despY);
// sprite_->setPos(x_ - bouncing_.despX, y_ - bouncing_.despY);
}
else
{
// Renderizado normal
sprite_->render();
}
// Añade la máscara del borde a la PowerBall
if (type_ == BalloonType::POWERBALL && !isBeingCreated())
{
auto sp = std::make_unique<Sprite>(sprite_->getTexture(), sprite_->getPosition());
sp->setSpriteClip(BALLOON_SIZE[3], 0, BALLOON_SIZE[3], BALLOON_SIZE[3]);
sp->render();
}
}
}
@@ -148,23 +158,29 @@ 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
// Colisión en la parte superior de la zona de juego excepto para la PowerBall
if (type_ != BalloonType::POWERBALL)
{
const int min_y = param.game.play_area.rect.y;
if (y_ < min_y)
{
y_ = min_y;
vy_ = -vy_;
if (type_ != BalloonType::POWERBALL)
enableBounce();
}
}
// Colisión en la parte inferior de la zona de juego
const int max_y = param.game.play_area.rect.h - h_;
@@ -173,8 +189,10 @@ void Balloon::move()
y_ = max_y;
vy_ = -default_vy_;
if (type_ != BalloonType::POWERBALL)
{
enableBounce();
}
}
/*

View File

@@ -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

View File

@@ -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> &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};

View File

@@ -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)

View File

@@ -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();