afegit efecte de "colp" quan el jugador es "alcanssat" per un globo
This commit is contained in:
61
source/hit.h
Normal file
61
source/hit.h
Normal file
@@ -0,0 +1,61 @@
|
||||
#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 que 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)
|
||||
: 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
|
||||
bool isEnabled() const {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
// Crea un "Hit" en la posición especificada
|
||||
void create(SDL_FPoint position) {
|
||||
setPos(position);
|
||||
enable(true);
|
||||
}
|
||||
|
||||
// Dibuja el hit
|
||||
void render() {
|
||||
if (enabled) {
|
||||
sprite->render();
|
||||
}
|
||||
}
|
||||
|
||||
// Deshabilita el hit
|
||||
void disable() {
|
||||
enabled = false;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user