72 lines
2.4 KiB
C++
72 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
|
#include <memory> // Para shared_ptr
|
|
class Texture;
|
|
|
|
// Clase sprite
|
|
class Sprite
|
|
{
|
|
protected:
|
|
// Variables
|
|
std::shared_ptr<Texture> texture_; // Textura donde estan todos los dibujos del sprite
|
|
SDL_Rect pos_; // Posición y tamaño donde dibujar el sprite
|
|
SDL_Rect 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>, int x, int y, int w, int h);
|
|
Sprite(std::shared_ptr<Texture>, SDL_Rect rect);
|
|
explicit Sprite(std::shared_ptr<Texture>);
|
|
|
|
// Destructor
|
|
virtual ~Sprite() = default;
|
|
|
|
// Muestra el sprite por pantalla
|
|
virtual void render();
|
|
|
|
// Reinicia las variables a cero
|
|
virtual void clear();
|
|
|
|
// Obtiene la posición y el tamaño
|
|
int getX() const { return pos_.x; }
|
|
int getY() const { return pos_.y; }
|
|
int getWidth() const { return pos_.w; }
|
|
int getHeight() const { return pos_.h; }
|
|
|
|
// Devuelve el rectangulo donde está el sprite
|
|
SDL_Rect getPosition() const { return pos_; }
|
|
SDL_Rect &getRect() { return pos_; }
|
|
|
|
// Establece la posición y el tamaño
|
|
void setX(int x) { pos_.x = x; }
|
|
void setY(int y) { pos_.y = y; }
|
|
void setWidth(int w) { pos_.w = w; }
|
|
void setHeight(int h) { pos_.h = h; }
|
|
|
|
// Establece la posición del objeto
|
|
void setPosition(int x, int y);
|
|
void setPosition(SDL_Point p);
|
|
void setPosition(SDL_Rect r) { pos_ = r; }
|
|
|
|
// Establece el nivel de zoom
|
|
void setZoom(float zoom) { zoom_ = zoom; }
|
|
|
|
// Aumenta o disminuye la posición
|
|
void incX(int value) { pos_.x += value; }
|
|
void incY(int value) { pos_.y += value; }
|
|
|
|
// Obtiene el rectangulo que se dibuja de la textura
|
|
SDL_Rect getSpriteClip() const { return sprite_clip_; }
|
|
|
|
// Establece el rectangulo que se dibuja de la textura
|
|
void setSpriteClip(SDL_Rect rect) { sprite_clip_ = rect; }
|
|
void setSpriteClip(int x, int y, int w, int h) { sprite_clip_ = (SDL_Rect){x, y, w, h}; }
|
|
|
|
// Obtiene un puntero a la textura
|
|
std::shared_ptr<Texture> getTexture() const { return texture_; }
|
|
|
|
// Establece la textura a utilizar
|
|
void setTexture(std::shared_ptr<Texture> texture) { texture_ = texture; }
|
|
}; |