clang-tidy modernize
This commit is contained in:
249
source/balloon.h
249
source/balloon.h
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <SDL3/SDL.h> // Para Uint8, Uint16, SDL_FRect, Uint32
|
||||
|
||||
#include <array>
|
||||
#include <memory> // Para shared_ptr, unique_ptr
|
||||
#include <string> // Para basic_string, string
|
||||
#include <vector> // Para vector
|
||||
@@ -14,12 +15,16 @@ class Texture;
|
||||
// --- Constantes relacionadas con globos ---
|
||||
constexpr int MAX_BOUNCE = 10; // Cantidad de elementos del vector de deformación
|
||||
|
||||
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, 48, 49};
|
||||
const std::string BALLOON_BOUNCING_SOUND[] = {"bubble1.wav", "bubble2.wav", "bubble3.wav", "bubble4.wav"};
|
||||
const std::string BALLOON_POPPING_SOUND[] = {"balloon1.wav", "balloon2.wav", "balloon3.wav", "balloon4.wav"};
|
||||
constexpr std::array<int, 4> BALLOON_SCORE = {50, 100, 200, 400};
|
||||
constexpr std::array<int, 4> BALLOON_POWER = {1, 3, 7, 15};
|
||||
constexpr std::array<int, 4> BALLOON_MENACE = {1, 2, 4, 8};
|
||||
constexpr std::array<int, 5> BALLOON_SIZE = {10, 16, 26, 48, 49};
|
||||
|
||||
const std::array<std::string, 4> BALLOON_BOUNCING_SOUND = {
|
||||
"bubble1.wav", "bubble2.wav", "bubble3.wav", "bubble4.wav"};
|
||||
|
||||
const std::array<std::string, 4> BALLOON_POPPING_SOUND = {
|
||||
"balloon1.wav", "balloon2.wav", "balloon3.wav", "balloon4.wav"};
|
||||
|
||||
enum class BalloonSize : Uint8 {
|
||||
SIZE1 = 0,
|
||||
@@ -41,136 +46,136 @@ constexpr int BALLOON_MOVING_ANIMATION = 0;
|
||||
constexpr int BALLOON_POP_ANIMATION = 1;
|
||||
constexpr int BALLOON_BORN_ANIMATION = 2;
|
||||
|
||||
constexpr float BALLOON_SPEED[] = {0.60f, 0.70f, 0.80f, 0.90f, 1.00f};
|
||||
constexpr std::array<float, 5> BALLOON_SPEED = {0.60f, 0.70f, 0.80f, 0.90f, 1.00f};
|
||||
|
||||
constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10;
|
||||
constexpr int POWERBALL_COUNTER = 8;
|
||||
|
||||
// --- Clase Balloon ---
|
||||
class Balloon {
|
||||
public:
|
||||
// --- Constructores y destructor ---
|
||||
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() = default;
|
||||
public:
|
||||
// --- Constructores y destructor ---
|
||||
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() = default;
|
||||
|
||||
// --- Métodos principales ---
|
||||
void alignTo(int x); // Centra el globo en la posición X
|
||||
void render(); // Pinta el globo en la pantalla
|
||||
void move(); // Actualiza la posición y estados del globo
|
||||
void update(); // Actualiza el globo (posición, animación, contadores)
|
||||
void stop(); // Detiene el globo
|
||||
void start(); // Pone el globo en movimiento
|
||||
void pop(bool should_sound = false); // Explota el globo
|
||||
// --- Métodos principales ---
|
||||
void alignTo(int x); // Centra el globo en la posición X
|
||||
void render(); // Pinta el globo en la pantalla
|
||||
void move(); // Actualiza la posición y estados del globo
|
||||
void update(); // Actualiza el globo (posición, animación, contadores)
|
||||
void stop(); // Detiene el globo
|
||||
void start(); // Pone el globo en movimiento
|
||||
void pop(bool should_sound = false); // Explota el globo
|
||||
|
||||
// --- Métodos de color ---
|
||||
void useReverseColor(); // Pone el color alternativo en el globo
|
||||
void useNormalColor(); // Pone el color normal en el globo
|
||||
// --- Métodos de color ---
|
||||
void useReverseColor(); // Pone el color alternativo en el globo
|
||||
void useNormalColor(); // Pone el color normal en el globo
|
||||
|
||||
// --- Getters ---
|
||||
[[nodiscard]] auto getPosX() const -> float { return x_; }
|
||||
[[nodiscard]] auto getPosY() const -> float { return y_; }
|
||||
[[nodiscard]] auto getWidth() const -> int { return w_; }
|
||||
[[nodiscard]] auto getHeight() const -> int { return h_; }
|
||||
[[nodiscard]] auto getSize() const -> BalloonSize { return size_; }
|
||||
[[nodiscard]] auto getType() const -> BalloonType { return type_; }
|
||||
[[nodiscard]] auto getScore() const -> Uint16 { return score_; }
|
||||
auto getCollider() -> Circle & { return collider_; }
|
||||
[[nodiscard]] auto getMenace() const -> Uint8 { return isEnabled() ? menace_ : 0; }
|
||||
[[nodiscard]] auto getPower() const -> Uint8 { return power_; }
|
||||
[[nodiscard]] auto isStopped() const -> bool { return stopped_; }
|
||||
[[nodiscard]] auto isPowerBall() const -> bool { return type_ == BalloonType::POWERBALL; }
|
||||
[[nodiscard]] auto isInvulnerable() const -> bool { return invulnerable_; }
|
||||
[[nodiscard]] auto isBeingCreated() const -> bool { return being_created_; }
|
||||
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; }
|
||||
auto isUsingReversedColor() -> bool { return use_reversed_colors_; }
|
||||
[[nodiscard]] auto canBePopped() const -> bool { return !isBeingCreated(); }
|
||||
// --- Getters ---
|
||||
[[nodiscard]] auto getPosX() const -> float { return x_; }
|
||||
[[nodiscard]] auto getPosY() const -> float { return y_; }
|
||||
[[nodiscard]] auto getWidth() const -> int { return w_; }
|
||||
[[nodiscard]] auto getHeight() const -> int { return h_; }
|
||||
[[nodiscard]] auto getSize() const -> BalloonSize { return size_; }
|
||||
[[nodiscard]] auto getType() const -> BalloonType { return type_; }
|
||||
[[nodiscard]] auto getScore() const -> Uint16 { return score_; }
|
||||
auto getCollider() -> Circle & { return collider_; }
|
||||
[[nodiscard]] auto getMenace() const -> Uint8 { return isEnabled() ? menace_ : 0; }
|
||||
[[nodiscard]] auto getPower() const -> Uint8 { return power_; }
|
||||
[[nodiscard]] auto isStopped() const -> bool { return stopped_; }
|
||||
[[nodiscard]] auto isPowerBall() const -> bool { return type_ == BalloonType::POWERBALL; }
|
||||
[[nodiscard]] auto isInvulnerable() const -> bool { return invulnerable_; }
|
||||
[[nodiscard]] auto isBeingCreated() const -> bool { return being_created_; }
|
||||
[[nodiscard]] auto isEnabled() const -> bool { return enabled_; }
|
||||
auto isUsingReversedColor() -> bool { return use_reversed_colors_; }
|
||||
[[nodiscard]] auto canBePopped() const -> bool { return !isBeingCreated(); }
|
||||
|
||||
// --- Setters ---
|
||||
void setVelY(float vel_y) { vy_ = vel_y; }
|
||||
void setSpeed(float speed) { speed_ = speed; }
|
||||
void setInvulnerable(bool value) { invulnerable_ = value; }
|
||||
void setBouncingSound(bool value) { bouncing_sound_enabled_ = value; }
|
||||
void setPoppingSound(bool value) { poping_sound_enabled_ = value; }
|
||||
void setSound(bool value) { sound_enabled_ = value; }
|
||||
// --- Setters ---
|
||||
void setVelY(float vel_y) { vy_ = vel_y; }
|
||||
void setSpeed(float speed) { speed_ = speed; }
|
||||
void setInvulnerable(bool value) { invulnerable_ = value; }
|
||||
void setBouncingSound(bool value) { bouncing_sound_enabled_ = value; }
|
||||
void setPoppingSound(bool value) { poping_sound_enabled_ = value; }
|
||||
void setSound(bool value) { sound_enabled_ = value; }
|
||||
|
||||
private:
|
||||
// --- Estructura para el efecto de rebote ---
|
||||
struct Bouncing {
|
||||
bool enabled = false; // Si el efecto está activo
|
||||
Uint8 counter = 0; // Contador para el efecto
|
||||
Uint8 speed = 2; // Velocidad del efecto
|
||||
float zoom_w = 1.0f; // Zoom en anchura
|
||||
float zoom_h = 1.0f; // Zoom en altura
|
||||
float desp_x = 0.0f; // Desplazamiento X antes de pintar
|
||||
float desp_y = 0.0f; // Desplazamiento Y antes de pintar
|
||||
private:
|
||||
// --- Estructura para el efecto de rebote ---
|
||||
struct Bouncing {
|
||||
bool enabled = false; // Si el efecto está activo
|
||||
Uint8 counter = 0; // Contador para el efecto
|
||||
Uint8 speed = 2; // Velocidad del efecto
|
||||
float horizontal_zoom = 1.0f; // Zoom en anchura
|
||||
float verical_zoom = 1.0f; // Zoom en altura
|
||||
float desp_x = 0.0f; // Desplazamiento X antes de pintar
|
||||
float desp_y = 0.0f; // Desplazamiento Y antes de pintar
|
||||
|
||||
float w[MAX_BOUNCE] = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f}; // Zoom ancho
|
||||
float h[MAX_BOUNCE] = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f}; // Zoom alto
|
||||
std::array<float, MAX_BOUNCE> horizontal_zoom_values = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f}; // Zoom ancho
|
||||
std::array<float, MAX_BOUNCE> vertical_zoom_values = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f}; // Zoom alto
|
||||
|
||||
Bouncing() = default;
|
||||
void reset() {
|
||||
counter = 0;
|
||||
zoom_w = 1.0f;
|
||||
zoom_h = 1.0f;
|
||||
desp_x = 0.0f;
|
||||
desp_y = 0.0f;
|
||||
}
|
||||
} bouncing_;
|
||||
Bouncing() = default;
|
||||
void reset() {
|
||||
counter = 0;
|
||||
horizontal_zoom = 1.0f;
|
||||
verical_zoom = 1.0f;
|
||||
desp_x = 0.0f;
|
||||
desp_y = 0.0f;
|
||||
}
|
||||
} bouncing_;
|
||||
|
||||
// --- Objetos y punteros ---
|
||||
std::unique_ptr<AnimatedSprite> sprite_; // Sprite del objeto globo
|
||||
// --- Objetos y punteros ---
|
||||
std::unique_ptr<AnimatedSprite> sprite_; // Sprite del objeto globo
|
||||
|
||||
// --- Variables de estado y físicas ---
|
||||
float x_; // Posición X
|
||||
float y_; // Posición Y
|
||||
float w_; // Ancho
|
||||
float h_; // Alto
|
||||
float vx_; // Velocidad X
|
||||
float vy_; // Velocidad Y
|
||||
float gravity_; // Aceleración en Y
|
||||
float default_vy_; // Velocidad inicial al rebotar
|
||||
float max_vy_; // Máxima velocidad en Y
|
||||
bool being_created_; // Si el globo se está creando
|
||||
bool enabled_ = true; // Si el globo está activo
|
||||
bool invulnerable_; // Si el globo es invulnerable
|
||||
bool stopped_; // Si el globo está parado
|
||||
bool use_reversed_colors_ = false; // Si se usa el color alternativo
|
||||
Circle collider_; // Círculo de colisión
|
||||
Uint16 creation_counter_; // Temporizador de creación
|
||||
Uint16 creation_counter_ini_; // Valor inicial del temporizador de creación
|
||||
Uint16 score_; // Puntos al destruir el globo
|
||||
BalloonType type_; // Tipo de globo
|
||||
BalloonSize size_; // Tamaño de globo
|
||||
Uint8 menace_; // Amenaza que genera el globo
|
||||
Uint32 counter_ = 0; // Contador interno
|
||||
float travel_y_ = 1.0f; // Distancia a recorrer en Y antes de aplicar gravedad
|
||||
float speed_; // Velocidad del globo
|
||||
Uint8 power_; // Poder que alberga el globo
|
||||
SDL_FRect play_area_; // Zona de movimiento del globo
|
||||
std::string bouncing_sound_; // Archivo de sonido al rebotar
|
||||
std::string popping_sound_; // Archivo de sonido al explotar
|
||||
bool bouncing_sound_enabled_ = false; // Si debe sonar el globo al rebotar
|
||||
bool poping_sound_enabled_ = true; // Si debe sonar el globo al explotar
|
||||
bool sound_enabled_ = true; // Indica si los globos deben hacer algun sonido
|
||||
// --- Variables de estado y físicas ---
|
||||
float x_; // Posición X
|
||||
float y_; // Posición Y
|
||||
float w_; // Ancho
|
||||
float h_; // Alto
|
||||
float vx_; // Velocidad X
|
||||
float vy_; // Velocidad Y
|
||||
float gravity_; // Aceleración en Y
|
||||
float default_vy_; // Velocidad inicial al rebotar
|
||||
float max_vy_; // Máxima velocidad en Y
|
||||
bool being_created_; // Si el globo se está creando
|
||||
bool enabled_ = true; // Si el globo está activo
|
||||
bool invulnerable_; // Si el globo es invulnerable
|
||||
bool stopped_; // Si el globo está parado
|
||||
bool use_reversed_colors_ = false; // Si se usa el color alternativo
|
||||
Circle collider_; // Círculo de colisión
|
||||
Uint16 creation_counter_; // Temporizador de creación
|
||||
Uint16 creation_counter_ini_; // Valor inicial del temporizador de creación
|
||||
Uint16 score_; // Puntos al destruir el globo
|
||||
BalloonType type_; // Tipo de globo
|
||||
BalloonSize size_; // Tamaño de globo
|
||||
Uint8 menace_; // Amenaza que genera el globo
|
||||
Uint32 counter_ = 0; // Contador interno
|
||||
float travel_y_ = 1.0f; // Distancia a recorrer en Y antes de aplicar gravedad
|
||||
float speed_; // Velocidad del globo
|
||||
Uint8 power_; // Poder que alberga el globo
|
||||
SDL_FRect play_area_; // Zona de movimiento del globo
|
||||
std::string bouncing_sound_; // Archivo de sonido al rebotar
|
||||
std::string popping_sound_; // Archivo de sonido al explotar
|
||||
bool bouncing_sound_enabled_ = false; // Si debe sonar el globo al rebotar
|
||||
bool poping_sound_enabled_ = true; // Si debe sonar el globo al explotar
|
||||
bool sound_enabled_ = true; // Indica si los globos deben hacer algun sonido
|
||||
|
||||
// --- Métodos internos ---
|
||||
void shiftColliders(); // Alinea el círculo de colisión
|
||||
void shiftSprite(); // Alinea el sprite
|
||||
void zoomSprite(); // Establece el nivel de zoom del sprite
|
||||
void enableBounce(); // Activa el efecto de rebote
|
||||
void disableBounce(); // Detiene el efecto de rebote
|
||||
void updateBounce(); // Aplica el efecto de rebote
|
||||
void updateState(); // Actualiza los estados del globo
|
||||
void setAnimation(); // Establece la animación correspondiente
|
||||
void playSound(const std::string &name); // Reproduce sonido
|
||||
// --- Métodos internos ---
|
||||
void shiftColliders(); // Alinea el círculo de colisión
|
||||
void shiftSprite(); // Alinea el sprite
|
||||
void zoomSprite(); // Establece el nivel de zoom del sprite
|
||||
void enableBounce(); // Activa el efecto de rebote
|
||||
void disableBounce(); // Detiene el efecto de rebote
|
||||
void updateBounce(); // Aplica el efecto de rebote
|
||||
void updateState(); // Actualiza los estados del globo
|
||||
void setAnimation(); // Establece la animación correspondiente
|
||||
void playSound(const std::string &name); // Reproduce sonido
|
||||
};
|
||||
Reference in New Issue
Block a user