corregida la llista de inicialització en clang-format
creat Balloon::Config per a inicialitzar globos
This commit is contained in:
@@ -11,20 +11,21 @@
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// Constructor
|
||||
Balloon::Balloon(float x, float y, Type type, Size size, float vel_x, float speed, Uint16 creation_timer, SDL_FRect play_area, const std::shared_ptr<Texture> &texture, const std::vector<std::string> &animation)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(texture, animation)),
|
||||
x_(x),
|
||||
y_(y),
|
||||
vx_(vel_x),
|
||||
being_created_(creation_timer > 0),
|
||||
invulnerable_(creation_timer > 0),
|
||||
stopped_(creation_timer > 0),
|
||||
creation_counter_(creation_timer),
|
||||
creation_counter_ini_(creation_timer),
|
||||
type_(type),
|
||||
size_(size),
|
||||
speed_(speed),
|
||||
play_area_(play_area) {
|
||||
Balloon::Balloon(const Config& config)
|
||||
: sprite_(std::make_unique<AnimatedSprite>(config.texture, config.animation)),
|
||||
x_(config.x),
|
||||
y_(config.y),
|
||||
vx_(config.vel_x),
|
||||
being_created_(config.creation_counter > 0),
|
||||
invulnerable_(config.creation_counter > 0),
|
||||
stopped_(config.creation_counter > 0),
|
||||
creation_counter_(config.creation_counter),
|
||||
creation_counter_ini_(config.creation_counter),
|
||||
type_(config.type),
|
||||
size_(config.size),
|
||||
speed_(config.speed),
|
||||
play_area_(config.play_area),
|
||||
sound_(config.sound) {
|
||||
switch (type_) {
|
||||
case Type::BALLOON: {
|
||||
vy_ = 0;
|
||||
@@ -37,9 +38,8 @@ Balloon::Balloon(float x, float y, Type type, Size size, float vel_x, float spee
|
||||
power_ = POWER.at(INDEX);
|
||||
menace_ = MENACE.at(INDEX);
|
||||
score_ = SCORE.at(INDEX);
|
||||
bouncing_sound_ = BOUNCING_SOUND.at(INDEX);
|
||||
popping_sound_ = POPPING_SOUND.at(INDEX);
|
||||
|
||||
sound_.bouncing_file = BOUNCING_SOUND.at(INDEX);
|
||||
sound_.popping_file = POPPING_SOUND.at(INDEX);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -52,17 +52,16 @@ Balloon::Balloon(float x, float y, Type type, Size size, float vel_x, float spee
|
||||
power_ = POWER.at(INDEX);
|
||||
menace_ = MENACE.at(INDEX);
|
||||
score_ = SCORE.at(INDEX);
|
||||
bouncing_sound_ = BOUNCING_SOUND.at(INDEX);
|
||||
popping_sound_ = POPPING_SOUND.at(INDEX);
|
||||
|
||||
sound_.bouncing_file = BOUNCING_SOUND.at(INDEX);
|
||||
sound_.popping_file = POPPING_SOUND.at(INDEX);
|
||||
break;
|
||||
}
|
||||
|
||||
case Type::POWERBALL: {
|
||||
constexpr int INDEX = 3;
|
||||
h_ = w_ = WIDTH.at(4);
|
||||
bouncing_sound_ = BOUNCING_SOUND.at(3);
|
||||
popping_sound_ = "power_ball_explosion.wav";
|
||||
sound_.bouncing_file = BOUNCING_SOUND.at(3);
|
||||
sound_.popping_file = "power_ball_explosion.wav";
|
||||
power_ = score_ = menace_ = 0;
|
||||
|
||||
vy_ = 0;
|
||||
@@ -70,9 +69,8 @@ Balloon::Balloon(float x, float y, Type type, Size size, float vel_x, float spee
|
||||
gravity_ = param.balloon.settings.at(INDEX).grav;
|
||||
default_vy_ = param.balloon.settings.at(INDEX).vel;
|
||||
|
||||
sprite_->setRotate(creation_timer <= 0);
|
||||
sprite_->setRotate(config.creation_counter <= 0);
|
||||
sprite_->setRotateAmount(vx_ > 0.0F ? 2.0 : -2.0);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -233,8 +231,14 @@ void Balloon::applyGravity() {
|
||||
}
|
||||
|
||||
void Balloon::playBouncingSound() {
|
||||
if (bouncing_sound_enabled_) {
|
||||
playSound(bouncing_sound_);
|
||||
if (sound_.enabled && sound_.bouncing_enabled) {
|
||||
Audio::get()->playSound(sound_.bouncing_file);
|
||||
}
|
||||
}
|
||||
|
||||
void Balloon::playPoppingSound() {
|
||||
if (sound_.enabled && sound_.poping_enabled) {
|
||||
Audio::get()->playSound(sound_.popping_file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -368,23 +372,8 @@ void Balloon::useNormalColor() {
|
||||
setAnimation();
|
||||
}
|
||||
|
||||
// Reproduce sonido
|
||||
void Balloon::playSound(const std::string &name) const {
|
||||
if (!sound_enabled_) {
|
||||
return;
|
||||
}
|
||||
|
||||
static auto *audio_ = Audio::get();
|
||||
audio_->playSound(name);
|
||||
}
|
||||
|
||||
// Explota el globo
|
||||
void Balloon::pop(bool should_sound) {
|
||||
if (should_sound) {
|
||||
if (poping_sound_enabled_) {
|
||||
playSound(popping_sound_);
|
||||
}
|
||||
}
|
||||
|
||||
if (should_sound) { playPoppingSound(); }
|
||||
enabled_ = false;
|
||||
}
|
||||
Reference in New Issue
Block a user