77 lines
2.9 KiB
C++
77 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <memory> // Para shared_ptr
|
|
#include <utility>
|
|
class Surface; // lines 5-5
|
|
|
|
// Clase SurfaceSprite
|
|
class SurfaceSprite {
|
|
protected:
|
|
// Variables
|
|
std::shared_ptr<Surface> surface_; // Surface donde estan todos los dibujos del sprite
|
|
SDL_FRect pos_; // Posición y tamaño donde dibujar el sprite
|
|
SDL_FRect clip_; // Rectangulo de origen de la surface que se dibujará en pantalla
|
|
|
|
public:
|
|
// Constructor
|
|
SurfaceSprite(std::shared_ptr<Surface>, float x, float y, float w, float h);
|
|
SurfaceSprite(std::shared_ptr<Surface>, SDL_FRect rect);
|
|
explicit SurfaceSprite(std::shared_ptr<Surface>);
|
|
|
|
// Destructor
|
|
virtual ~SurfaceSprite() = default;
|
|
|
|
// Actualiza el estado del sprite (time-based)
|
|
virtual void update(float delta_time);
|
|
|
|
// Actualiza el estado del sprite (frame-based, deprecated)
|
|
[[deprecated("Use update(float delta_time) instead")]]
|
|
virtual void update();
|
|
|
|
// Muestra el sprite por pantalla
|
|
virtual void render();
|
|
virtual void render(Uint8 source_color, Uint8 target_color);
|
|
|
|
// Reinicia las variables a cero
|
|
virtual void clear();
|
|
|
|
// Obtiene la posición y el tamaño
|
|
[[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; }
|
|
|
|
// Devuelve el rectangulo donde está el sprite
|
|
[[nodiscard]] auto getPosition() const -> SDL_FRect { return pos_; }
|
|
auto getRect() -> SDL_FRect& { return pos_; }
|
|
|
|
// Establece la posición y el 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; }
|
|
|
|
// Aumenta o disminuye la posición
|
|
void incX(float value) { pos_.x += value; }
|
|
void incY(float value) { pos_.y += value; }
|
|
|
|
// Obtiene el rectangulo que se dibuja de la surface
|
|
[[nodiscard]] auto getClip() const -> SDL_FRect { return clip_; }
|
|
|
|
// Establece el rectangulo que se dibuja de la 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}; }
|
|
|
|
// Obtiene un puntero a la surface
|
|
[[nodiscard]] auto getSurface() const -> std::shared_ptr<Surface> { return surface_; }
|
|
|
|
// Establece la surface a utilizar
|
|
void setSurface(std::shared_ptr<Surface> surface) { surface_ = std::move(surface); }
|
|
}; |