claude: arreglos d'estil
This commit is contained in:
65
source/hit.h
65
source/hit.h
@@ -7,55 +7,44 @@
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "texture.h" // Para Texture
|
||||
|
||||
// Estructura que representa una colisión o impacto visual
|
||||
// --- Estructura Hit: representa una colisión o impacto visual ---
|
||||
struct Hit {
|
||||
private:
|
||||
// Indica si el Hit está activo o no
|
||||
bool enabled_{false};
|
||||
|
||||
// Sprite asociado al Hit, gestionado con un puntero único
|
||||
std::unique_ptr<Sprite> sprite_;
|
||||
|
||||
public:
|
||||
// Elimina el constructor por defecto para obligar a pasar una textura
|
||||
Hit() = delete;
|
||||
|
||||
// Constructor que obliga a pasar una textura compartida para crear el Sprite
|
||||
// Esto evita que se pueda crear un Hit sin recursos gráficos válidos
|
||||
explicit Hit(std::shared_ptr<Texture> texture)
|
||||
// --- Constructor ---
|
||||
Hit() = delete; // Elimina el constructor por defecto para obligar a pasar una textura
|
||||
explicit Hit(std::shared_ptr<Texture> texture) // Constructor con textura obligatoria
|
||||
: sprite_(std::make_unique<Sprite>(texture)) {}
|
||||
|
||||
// Establece la posición del Sprite en el espacio
|
||||
void setPos(SDL_FPoint position) {
|
||||
SDL_FPoint centered_position = {position.x - (sprite_->getWidth() / 2), position.y - (sprite_->getHeight() / 2)};
|
||||
sprite_->setPosition(centered_position);
|
||||
}
|
||||
|
||||
// Activa o desactiva el Hit
|
||||
void enable(bool value) {
|
||||
enabled_ = value;
|
||||
}
|
||||
|
||||
// Consulta si el Hit está activo
|
||||
[[nodiscard]] auto isEnabled() const -> bool {
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
// Crea un "Hit" en la posición especificada
|
||||
void create(SDL_FPoint position) {
|
||||
// --- Métodos principales ---
|
||||
void create(SDL_FPoint position) { // Crea un "Hit" en la posición especificada
|
||||
setPos(position);
|
||||
enable(true);
|
||||
}
|
||||
|
||||
// Dibuja el hit
|
||||
void render() {
|
||||
void render() { // Dibuja el hit
|
||||
if (enabled_) {
|
||||
sprite_->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Deshabilita el hit
|
||||
void disable() {
|
||||
void disable() { // Deshabilita el hit
|
||||
enabled_ = false;
|
||||
}
|
||||
|
||||
// --- Configuración ---
|
||||
void setPos(SDL_FPoint position) { // Establece la posición del Sprite en el espacio
|
||||
SDL_FPoint centered_position = {position.x - (sprite_->getWidth() / 2), position.y - (sprite_->getHeight() / 2)};
|
||||
sprite_->setPosition(centered_position);
|
||||
}
|
||||
void enable(bool value) { // Activa o desactiva el Hit
|
||||
enabled_ = value;
|
||||
}
|
||||
|
||||
// --- Getters ---
|
||||
[[nodiscard]] auto isEnabled() const -> bool { // Consulta si el Hit está activo
|
||||
return enabled_;
|
||||
}
|
||||
|
||||
private:
|
||||
// --- Variables de estado ---
|
||||
std::unique_ptr<Sprite> sprite_; // Sprite asociado al Hit
|
||||
bool enabled_{false}; // Indica si el Hit está activo
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user