estandaritzats els globos a 0, 1, 2 i 3 (en lloc del mix que havia antes amb altres coses a 1, 2, 3 i 4)
balloon: passant const i enum a la part publica
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// Constructor
|
||||
Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel_x, float speed, Uint16 creation_timer, SDL_FRect play_area, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
||||
Balloon::Balloon(float x, float y, Type type, Size size, float vel_x, float speed, Uint16 creation_timer, SDL_FRect play_area, std::shared_ptr<Texture> texture, const std::vector<std::string> &animation)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
|
||||
x_(x),
|
||||
y_(y),
|
||||
@@ -26,42 +26,42 @@ Balloon::Balloon(float x, float y, BalloonType type, BalloonSize size, float vel
|
||||
speed_(speed),
|
||||
play_area_(play_area) {
|
||||
switch (type_) {
|
||||
case BalloonType::BALLOON: {
|
||||
case Type::BALLOON: {
|
||||
vy_ = 0;
|
||||
max_vy_ = 3.0F;
|
||||
|
||||
const int INDEX = static_cast<int>(size_);
|
||||
gravity_ = param.balloon.settings.at(INDEX).grav;
|
||||
default_vy_ = param.balloon.settings.at(INDEX).vel;
|
||||
h_ = w_ = BALLOON_SIZE[INDEX];
|
||||
power_ = BALLOON_POWER[INDEX];
|
||||
menace_ = BALLOON_MENACE[INDEX];
|
||||
score_ = BALLOON_SCORE[INDEX];
|
||||
bouncing_sound_ = BALLOON_BOUNCING_SOUND[INDEX];
|
||||
popping_sound_ = BALLOON_POPPING_SOUND[INDEX];
|
||||
h_ = w_ = SIZE[INDEX];
|
||||
power_ = POWER[INDEX];
|
||||
menace_ = MENACE[INDEX];
|
||||
score_ = SCORE[INDEX];
|
||||
bouncing_sound_ = BOUNCING_SOUND[INDEX];
|
||||
popping_sound_ = POPPING_SOUND[INDEX];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case BalloonType::FLOATER: {
|
||||
case Type::FLOATER: {
|
||||
default_vy_ = max_vy_ = vy_ = fabs(vx_ * 2.0F);
|
||||
gravity_ = 0.00F;
|
||||
|
||||
const int INDEX = static_cast<int>(size_);
|
||||
h_ = w_ = BALLOON_SIZE[INDEX];
|
||||
power_ = BALLOON_POWER[INDEX];
|
||||
menace_ = BALLOON_MENACE[INDEX];
|
||||
score_ = BALLOON_SCORE[INDEX];
|
||||
bouncing_sound_ = BALLOON_BOUNCING_SOUND[INDEX];
|
||||
popping_sound_ = BALLOON_POPPING_SOUND[INDEX];
|
||||
h_ = w_ = SIZE[INDEX];
|
||||
power_ = POWER[INDEX];
|
||||
menace_ = MENACE[INDEX];
|
||||
score_ = SCORE[INDEX];
|
||||
bouncing_sound_ = BOUNCING_SOUND[INDEX];
|
||||
popping_sound_ = POPPING_SOUND[INDEX];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case BalloonType::POWERBALL: {
|
||||
case Type::POWERBALL: {
|
||||
constexpr int INDEX = 3;
|
||||
h_ = w_ = BALLOON_SIZE[4];
|
||||
bouncing_sound_ = BALLOON_BOUNCING_SOUND[3];
|
||||
h_ = w_ = SIZE[4];
|
||||
bouncing_sound_ = BOUNCING_SOUND[3];
|
||||
popping_sound_ = "power_ball_explosion.wav";
|
||||
power_ = score_ = menace_ = 0;
|
||||
|
||||
@@ -103,11 +103,11 @@ void Balloon::alignTo(int x) {
|
||||
|
||||
// Pinta el globo en la pantalla
|
||||
void Balloon::render() {
|
||||
if (type_ == BalloonType::POWERBALL) {
|
||||
if (type_ == Type::POWERBALL) {
|
||||
// Renderiza el fondo azul
|
||||
{
|
||||
auto sp = std::make_unique<Sprite>(sprite_->getTexture(), sprite_->getPosition());
|
||||
sp->setSpriteClip(0, 0, BALLOON_SIZE[4], BALLOON_SIZE[4]);
|
||||
sp->setSpriteClip(0, 0, SIZE[4], SIZE[4]);
|
||||
sp->render();
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ void Balloon::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] * 2, 0, BALLOON_SIZE[4], BALLOON_SIZE[4]);
|
||||
sp->setSpriteClip(SIZE[4] * 2, 0, SIZE[4], SIZE[4]);
|
||||
sp->render();
|
||||
}
|
||||
} else {
|
||||
@@ -180,7 +180,7 @@ void Balloon::handleHorizontalBounce(float min_x, float max_x) {
|
||||
x_ = std::clamp(x_, min_x, max_x);
|
||||
vx_ = -vx_;
|
||||
|
||||
if (type_ == BalloonType::POWERBALL) {
|
||||
if (type_ == Type::POWERBALL) {
|
||||
sprite_->switchRotate();
|
||||
} else {
|
||||
enableBounceEffect();
|
||||
@@ -209,7 +209,7 @@ void Balloon::handleBottomCollision() {
|
||||
y_ = MAX_Y;
|
||||
vy_ = -default_vy_;
|
||||
|
||||
if (type_ != BalloonType::POWERBALL) {
|
||||
if (type_ != Type::POWERBALL) {
|
||||
enableBounceEffect();
|
||||
} else {
|
||||
setInvulnerable(false);
|
||||
@@ -293,11 +293,11 @@ void Balloon::setAnimation() {
|
||||
std::string normal_animation;
|
||||
|
||||
switch (type_) {
|
||||
case BalloonType::POWERBALL:
|
||||
case Type::POWERBALL:
|
||||
creating_animation = "powerball";
|
||||
normal_animation = "powerball";
|
||||
break;
|
||||
case BalloonType::FLOATER:
|
||||
case Type::FLOATER:
|
||||
creating_animation = param.balloon.color.at(2);
|
||||
normal_animation = param.balloon.color.at(3);
|
||||
break;
|
||||
@@ -352,7 +352,7 @@ void Balloon::applyBounceEffect() {
|
||||
// Activa el efecto
|
||||
void Balloon::enableBounceEffect() {
|
||||
// Los globos pequeños no tienen efecto de rebote
|
||||
if (size_ == BalloonSize::SIZE1) {
|
||||
if (size_ == Size::SIZE_0) {
|
||||
return;
|
||||
}
|
||||
bounce_effect_.enabled = true;
|
||||
|
||||
Reference in New Issue
Block a user