revisió de capçaleres

This commit is contained in:
2025-05-29 09:58:23 +02:00
parent 677e4d465d
commit 0fc8224ef8
45 changed files with 1870 additions and 2684 deletions

View File

@@ -2,71 +2,60 @@
#include <SDL3/SDL_rect.h> // Para SDL_FRect, SDL_FPoint
#include <memory> // Para shared_ptr
class Texture;
// Clase sprite
// Clase Sprite: representa un objeto gráfico básico con posición, tamaño y textura
class Sprite
{
protected:
// Variables
std::shared_ptr<Texture> texture_; // Textura donde estan todos los dibujos del sprite
SDL_FRect pos_; // Posición y tamaño donde dibujar el sprite
SDL_FRect sprite_clip_; // Rectangulo de origen de la textura que se dibujará en pantalla
double zoom_ = 1.0f; // Zoom aplicado a la textura
public:
// Constructor
Sprite(std::shared_ptr<Texture>, float x, float y, float w, float h);
Sprite(std::shared_ptr<Texture>, SDL_FRect rect);
explicit Sprite(std::shared_ptr<Texture>);
// Destructor
// --- Constructores y destructor ---
Sprite(std::shared_ptr<Texture> texture, float x, float y, float w, float h);
Sprite(std::shared_ptr<Texture> texture, SDL_FRect rect);
explicit Sprite(std::shared_ptr<Texture> texture);
virtual ~Sprite() = default;
// Muestra el sprite por pantalla
virtual void render();
// --- Renderizado y control ---
virtual void render(); // Muestra el sprite por pantalla
virtual void clear(); // Reinicia las variables a cero
// Reinicia las variables a cero
virtual void clear();
// Obtiene la posición y el tamaño
// --- Getters de posición y tamaño ---
float getX() const { return pos_.x; }
float getY() const { return pos_.y; }
float getWidth() const { return pos_.w; }
float getHeight() const { return pos_.h; }
// Devuelve el rectangulo donde está el sprite
SDL_FRect getPosition() const { return pos_; }
SDL_FRect &getRect() { return pos_; }
// Establece la posición y el tamaño
// --- Setters de posición y tamaño ---
void setX(float x) { pos_.x = x; }
void setY(float y) { pos_.y = y; }
void setWidth(float w) { pos_.w = w; }
void setHeight(float h) { pos_.h = h; }
// Establece la posición del objeto
void setPosition(float x, float y);
void setPosition(SDL_FPoint p);
void setPosition(SDL_FRect r) { pos_ = r; }
// Establece el nivel de zoom
// --- Zoom ---
void setZoom(float zoom) { zoom_ = zoom; }
// Aumenta o disminuye la posición
// --- Modificación de posición ---
void incX(float value) { pos_.x += value; }
void incY(float value) { pos_.y += value; }
// Obtiene el rectangulo que se dibuja de la textura
// --- Sprite clip ---
SDL_FRect getSpriteClip() const { return sprite_clip_; }
// Establece el rectangulo que se dibuja de la textura
void setSpriteClip(SDL_FRect rect) { sprite_clip_ = rect; }
void setSpriteClip(float x, float y, float w, float h) { sprite_clip_ = (SDL_FRect){x, y, w, h}; }
void setSpriteClip(float x, float y, float w, float h) { sprite_clip_ = SDL_FRect{x, y, w, h}; }
// Obtiene un puntero a la textura
// --- Textura ---
std::shared_ptr<Texture> getTexture() const { return texture_; }
// Establece la textura a utilizar
void setTexture(std::shared_ptr<Texture> texture) { texture_ = texture; }
protected:
// --- Variables internas ---
std::shared_ptr<Texture> texture_; // Textura donde están todos los dibujos del sprite
SDL_FRect pos_; // Posición y tamaño donde dibujar el sprite
SDL_FRect sprite_clip_; // Rectángulo de origen de la textura que se dibujará en pantalla
double zoom_ = 1.0f; // Zoom aplicado a la textura
};