Files
coffee_crisis_arcade_edition/source/bullet.h
Sergio ec008ef5dd iwyu
clang-format
2025-07-23 20:55:50 +02:00

73 lines
2.7 KiB
C++

#pragma once
#include <SDL3/SDL.h> // Para Uint8
#include <memory> // Para unique_ptr
#include <string> // Para string
#include "animated_sprite.h" // Para AnimatedSprite
#include "utils.h" // Para Circle
// Tipos de balas
enum class BulletType : Uint8 {
UP,
LEFT,
RIGHT,
NONE
};
// Resultado del movimiento de la bala
enum class BulletMoveStatus : Uint8 {
OK = 0,
OUT = 1
};
// Clase Bullet
class Bullet {
public:
// Constantes
static constexpr float WIDTH = 12.0F;
static constexpr float HEIGHT = 12.0F;
// Constructor y Destructor
Bullet(float x, float y, BulletType bullet_type, bool powered, int owner);
~Bullet() = default;
// Métodos principales
void render(); // Dibuja la bala en pantalla
auto update() -> BulletMoveStatus; // Actualiza el estado del objeto
// Estado de la bala
[[nodiscard]] auto isEnabled() const -> bool; // Comprueba si está activa
void disable(); // Desactiva la bala
// Getters
[[nodiscard]] auto getOwner() const -> int; // Devuelve el identificador del dueño
auto getCollider() -> Circle &; // Devuelve el círculo de colisión
private:
// Constantes
static constexpr float VEL_Y = -3.0F;
static constexpr float VEL_X_LEFT = -2.0F;
static constexpr float VEL_X_RIGHT = 2.0F;
static constexpr float VEL_X_CENTER = 0.0F;
// Propiedades
std::unique_ptr<AnimatedSprite> sprite_; // Sprite con los gráficos
float pos_x_; // Posición en el eje X
float pos_y_; // Posición en el eje Y
float vel_x_; // Velocidad en el eje X
BulletType bullet_type_; // Tipo de bala
int owner_; // Identificador del dueño
Circle collider_; // Círculo de colisión
// Métodos internos
void shiftColliders(); // Ajusta el círculo de colisión
void shiftSprite(); // Ajusta el sprite
auto move() -> BulletMoveStatus; // Mueve la bala y devuelve su estado
static auto calculateVelocity(BulletType bullet_type) -> float; // Calcula la velocidad horizontal de la bala basada en su tipo
static auto buildAnimationString(BulletType bullet_type, bool powered) -> std::string; // Construye el string de animación basado en el tipo de bala y si está potenciada
};