51 lines
1.7 KiB
C++
51 lines
1.7 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h> // Para SDL_FPoint
|
|
|
|
#include <memory> // Para std::unique_ptr y std::shared_ptr
|
|
|
|
#include "sprite.h" // Para Sprite
|
|
#include "texture.h" // 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(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
|
|
};
|