180 lines
9.5 KiB
C++
180 lines
9.5 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <string> // for string
|
|
#include <vector> // for vector
|
|
|
|
#include "utils/utils.h" // for Circle
|
|
class AnimatedSprite;
|
|
class Texture;
|
|
|
|
// Clase Balloon
|
|
class Balloon {
|
|
public:
|
|
// Tipos de globo
|
|
static constexpr int BALLOON_1 = 1;
|
|
static constexpr int BALLOON_2 = 2;
|
|
static constexpr int BALLOON_3 = 3;
|
|
static constexpr int BALLOON_4 = 4;
|
|
static constexpr int HEXAGON_1 = 5;
|
|
static constexpr int HEXAGON_2 = 6;
|
|
static constexpr int HEXAGON_3 = 7;
|
|
static constexpr int HEXAGON_4 = 8;
|
|
static constexpr int POWER_BALL = 9;
|
|
|
|
// Puntos de globo
|
|
static constexpr int SCORE_1 = 50;
|
|
static constexpr int SCORE_2 = 100;
|
|
static constexpr int SCORE_3 = 200;
|
|
static constexpr int SCORE_4 = 400;
|
|
|
|
// Tamaños de globo
|
|
static constexpr int SIZE_1 = 1;
|
|
static constexpr int SIZE_2 = 2;
|
|
static constexpr int SIZE_3 = 3;
|
|
static constexpr int SIZE_4 = 4;
|
|
|
|
// Clases de globo
|
|
static constexpr int BALLOON_CLASS = 0;
|
|
static constexpr int HEXAGON_CLASS = 1;
|
|
|
|
// Velocitat horitzontal en px/s (era 0.7 px/frame * 60).
|
|
static constexpr float VELX_POSITIVE = 42.0F;
|
|
static constexpr float VELX_NEGATIVE = -42.0F;
|
|
|
|
// Velocidades a las que se mueven los globos
|
|
static constexpr float SPEED_1 = 0.60F;
|
|
static constexpr float SPEED_2 = 0.70F;
|
|
static constexpr float SPEED_3 = 0.80F;
|
|
static constexpr float SPEED_4 = 0.90F;
|
|
static constexpr float SPEED_5 = 1.00F;
|
|
|
|
// Tamaño de los globos
|
|
static constexpr int WIDTH_1 = 8;
|
|
static constexpr int WIDTH_2 = 13;
|
|
static constexpr int WIDTH_3 = 21;
|
|
static constexpr int WIDTH_4 = 37;
|
|
|
|
// PowerBall
|
|
static constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10;
|
|
static constexpr int POWERBALL_COUNTER = 8;
|
|
|
|
Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, Texture *texture, const std::vector<std::string> *animation, SDL_Renderer *renderer); // Constructor
|
|
~Balloon(); // Destructor
|
|
|
|
Balloon(const Balloon &) = delete;
|
|
auto operator=(const Balloon &) -> Balloon & = delete;
|
|
|
|
void allignTo(int x); // Centra el globo en la posición X
|
|
void render(); // Pinta el globo en la pantalla
|
|
void move(float dt_s); // Actualiza la posición y estados del globo
|
|
void disable(); // Deshabilita el globo y pone a cero todos los valores
|
|
void pop(); // Explosiona el globo
|
|
void update(float dt_s); // Actualiza al globo
|
|
|
|
[[nodiscard]] auto isEnabled() const -> bool; // Comprueba si el globo está habilitado
|
|
[[nodiscard]] auto isStopped() const -> bool; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto isBlinking() const -> bool; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto isVisible() const -> bool; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto isInvulnerable() const -> bool; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto isBeingCreated() const -> bool; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto isPopping() const -> bool; // Obtiene del valor de la variable
|
|
|
|
[[nodiscard]] auto getPosX() const -> float; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto getPosY() const -> float; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto getWidth() const -> int; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto getHeight() const -> int; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto getKind() const -> int; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto getSize() const -> Uint8; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto getClass() const -> Uint8; // Obtiene la clase a la que pertenece el globo
|
|
[[nodiscard]] auto getStoppedTimer() const -> Uint16; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto getScore() const -> Uint16; // Obtiene del valor de la variable
|
|
[[nodiscard]] auto getMenace() const -> Uint8; // Obtiene le valor de la variable
|
|
[[nodiscard]] auto getPower() const -> Uint8; // Obtiene le valor de la variable
|
|
|
|
void setVelY(float vel_y); // Establece el valor de la variable
|
|
void setSpeed(float speed); // Establece el valor de la variable
|
|
void setStop(bool state); // Establece el valor de la variable
|
|
void setBlink(bool value); // Establece el valor de la variable
|
|
void setVisible(bool value); // Establece el valor de la variable
|
|
void setInvulnerable(bool value); // Establece el valor de la variable
|
|
void setPopping(bool value); // Establece el valor de la variable
|
|
void setStoppedTimer(Uint16 time); // Establece el valor de la variable
|
|
|
|
auto getCollider() -> Circle &; // Obtiene el circulo de colisión
|
|
|
|
private:
|
|
// Cantidad de elementos del vector con los valores de la deformación del globo al rebotar
|
|
static constexpr int MAX_BOUNCE = 10;
|
|
|
|
// Time-based: la creació "desplaça" el globus cada 10 frames a 60Hz ⇒ 1/6 s.
|
|
static constexpr float CREATION_STEP_S = 10.0F / 60.0F;
|
|
// Time-based: el bounce avança w/h cada `speed_` frames a 60Hz; mantenim el mateix temps per pas.
|
|
static constexpr float BOUNCE_STEP_S = 1.0F / 60.0F; // 1 frame
|
|
|
|
// Estructura para las variables para el efecto de los rebotes
|
|
struct Bouncing {
|
|
bool enabled; // Si el efecto está activo
|
|
Uint8 counter; // Countador para el efecto
|
|
Uint8 speed; // Velocidad a la que transcurre el efecto
|
|
float zoom_width; // Zoom aplicado a la anchura
|
|
float zoom_height; // Zoom aplicado a la altura
|
|
float desp_x; // Desplazamiento de pixeles en el eje X antes de pintar el objeto con zoom
|
|
float desp_y; // Desplazamiento de pixeles en el eje Y antes de pintar el objeto con zoom
|
|
std::vector<float> w; // Vector con los valores de zoom para el ancho del globo
|
|
std::vector<float> h; // Vector con los valores de zoom para el alto del globo
|
|
};
|
|
|
|
// Objetos y punteros
|
|
AnimatedSprite *sprite_; // Sprite del objeto globo
|
|
|
|
// Variables
|
|
float pos_x_; // Posición en el eje X
|
|
float pos_y_; // Posición en el eje Y
|
|
Uint8 width_; // Ancho
|
|
Uint8 height_; // Alto
|
|
float vel_x_s_{0.0F}; // Velocidad en X (px/s)
|
|
float vel_y_s_{0.0F}; // Velocidad en Y (px/s)
|
|
float gravity_s_{0.0F}; // Aceleración Y (px/s²)
|
|
float default_vel_y_s_{0.0F}; // Velocitat inicial al rebotar (px/s)
|
|
float max_vel_y_s_{0.0F}; // Velocitat màxima en Y (px/s, no aplicada en time-based actual)
|
|
bool being_created_; // Indica si el globo se está creando
|
|
bool blinking_; // Indica si el globo está intermitente
|
|
bool enabled_; // Indica si el globo esta activo
|
|
bool invulnerable_; // Indica si el globo es invulnerable
|
|
bool popping_; // Indica si el globo está explotando
|
|
bool stopped_; // Indica si el globo está parado
|
|
bool visible_; // Indica si el globo es visible
|
|
Circle collider_; // Circulo de colisión del objeto
|
|
Uint16 creation_counter_; // Temporizador (frames, derivat de creation_counter_s_ per a render alpha)
|
|
Uint16 creation_counter_ini_; // Valor inicial del temporizador (frames)
|
|
float creation_counter_s_{0.0F}; // Temporizador (font de veritat, segons)
|
|
float creation_counter_ini_s_{0.0F}; // Valor inicial del temporizador (segons)
|
|
float creation_phase_s_{0.0F}; // Acumulador de fase per als steps de creació
|
|
Uint16 score_; // Puntos que da el globo al ser destruido
|
|
Uint16 stopped_counter_; // Contador (frames, derivat de stopped_counter_s_)
|
|
float stopped_counter_s_{0.0F}; // Contador (font de veritat, segons)
|
|
Uint8 kind_; // Tipo de globo
|
|
Uint8 menace_; // Cantidad de amenaza que genera el globo
|
|
float speed_; // Tempo del joc (multiplicador adimensional)
|
|
Uint8 size_; // Tamaño del globo
|
|
Uint8 power_; // Cantidad de poder que alberga el globo
|
|
Bouncing bouncing_; // Contiene las variables para el efecto de rebote
|
|
float bounce_phase_s_{0.0F}; // Fase del bounce
|
|
|
|
void updateColliders(); // Alinea el circulo de colisión con la posición del objeto globo
|
|
void bounceStart(); // Activa el efecto
|
|
void bounceStop(); // Detiene el efecto
|
|
void updateBounce(float dt_s); // Aplica el efecto
|
|
void updateAnimation(float dt_s); // Establece la animación correspondiente
|
|
void setBeingCreated(bool value); // Establece el valor de la variable
|
|
|
|
void updateState(float dt_s); // Actualiza los estados del globo
|
|
|
|
// Helpers de updateState, uno por cada rama de estado
|
|
void updateStatePopping();
|
|
void updateStateBeingCreated(float dt_s);
|
|
void updateStateStopped(float dt_s);
|
|
};
|