60 lines
2.7 KiB
C++
60 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <memory> // Para shared_ptr
|
|
#include <utility>
|
|
class Surface; // lines 5-5
|
|
|
|
// Clase SurfaceSprite
|
|
class SurfaceSprite {
|
|
public:
|
|
// Constructores
|
|
SurfaceSprite(std::shared_ptr<Surface>, float x, float y, float w, float h);
|
|
SurfaceSprite(std::shared_ptr<Surface>, SDL_FRect rect);
|
|
SurfaceSprite();
|
|
explicit SurfaceSprite(std::shared_ptr<Surface>);
|
|
|
|
// Destructor
|
|
virtual ~SurfaceSprite() = default;
|
|
|
|
// Actualización y renderizado
|
|
virtual void update(float delta_time); // Actualiza el estado del sprite (time-based)
|
|
virtual void render(); // Muestra el sprite por pantalla
|
|
virtual void render(Uint8 source_color, Uint8 target_color); // Renderiza con reemplazo de color
|
|
|
|
// Gestión de estado
|
|
virtual void clear(); // Reinicia las variables a cero
|
|
|
|
// Obtención de propiedades
|
|
[[nodiscard]] auto getX() const -> float { return pos_.x; }
|
|
[[nodiscard]] auto getY() const -> float { return pos_.y; }
|
|
[[nodiscard]] auto getWidth() const -> float { return pos_.w; }
|
|
[[nodiscard]] auto getHeight() const -> float { return pos_.h; }
|
|
[[nodiscard]] auto getPosition() const -> SDL_FRect { return pos_; }
|
|
[[nodiscard]] auto getClip() const -> SDL_FRect { return clip_; }
|
|
[[nodiscard]] auto getSurface() const -> std::shared_ptr<Surface> { return surface_; }
|
|
auto getRect() -> SDL_FRect& { return pos_; }
|
|
|
|
// Modificación 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; }
|
|
void setPosition(float x, float y);
|
|
void setPosition(SDL_FPoint p);
|
|
void setPosition(SDL_FRect r) { pos_ = r; }
|
|
void incX(float value) { pos_.x += value; }
|
|
void incY(float value) { pos_.y += value; }
|
|
|
|
// Modificación de clip y surface
|
|
void setClip(SDL_FRect rect) { clip_ = rect; }
|
|
void setClip(float x, float y, float w, float h) { clip_ = SDL_FRect{x, y, w, h}; }
|
|
void setSurface(std::shared_ptr<Surface> surface) { surface_ = std::move(surface); }
|
|
|
|
protected:
|
|
// Variables miembro
|
|
std::shared_ptr<Surface> surface_{nullptr}; // Surface donde estan todos los dibujos del sprite
|
|
SDL_FRect pos_{0.0F, 0.0F, 0.0F, 0.0F}; // Posición y tamaño donde dibujar el sprite
|
|
SDL_FRect clip_{0.0F, 0.0F, 0.0F, 0.0F}; // Rectangulo de origen de la surface que se dibujará en pantalla
|
|
}; |