Player: canviat id de int a enum migrant input: eliminat Device, keyboard separat de la llista de mandos, llig i guarda configuracions de mandos falta: definir botons, asignar mandos a jugadors i guardar la asignació
74 lines
2.7 KiB
C++
74 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 "player.h" // Para Player
|
|
#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, Player::Id 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 -> Player::Id; // 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
|
|
Player::Id 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
|
|
};
|