renombrades extensions .h a .hpp
This commit is contained in:
50
source/hit.hpp
Normal file
50
source/hit.hpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_FPoint
|
||||
|
||||
#include <memory> // Para std::unique_ptr y std::shared_ptr
|
||||
|
||||
#include "sprite.hpp" // Para Sprite
|
||||
#include "texture.hpp" // Para Texture
|
||||
|
||||
// --- Estructura Hit: representa una colisión o impacto visual ---
|
||||
struct Hit {
|
||||
public:
|
||||
// --- Constructor ---
|
||||
Hit() = delete; // Elimina el constructor por defecto para obligar a pasar una textura
|
||||
explicit Hit(const std::shared_ptr<Texture>& texture) // Constructor con textura obligatoria
|
||||
: sprite_(std::make_unique<Sprite>(texture)) {}
|
||||
|
||||
// --- Métodos principales ---
|
||||
void create(SDL_FPoint position) { // Crea un "Hit" en la posición especificada
|
||||
setPos(position);
|
||||
enable(true);
|
||||
}
|
||||
void render() { // Dibuja el hit
|
||||
if (enabled_) {
|
||||
sprite_->render();
|
||||
}
|
||||
}
|
||||
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