64 lines
1.8 KiB
C++
64 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
|
#include "texture.h"
|
|
#include <memory>
|
|
|
|
// 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
|
|
|
|
public:
|
|
// Constructor
|
|
explicit Sprite(int x = 0, int y = 0, int w = 0, int h = 0, std::shared_ptr<Texture> texture = nullptr);
|
|
explicit Sprite(SDL_Rect rect, std::shared_ptr<Texture> texture = nullptr);
|
|
explicit Sprite(std::shared_ptr<Texture> texture = nullptr);
|
|
|
|
// Destructor
|
|
virtual ~Sprite() = default;
|
|
|
|
// Muestra el sprite por pantalla
|
|
virtual void render();
|
|
|
|
// Obten el valor de la variable
|
|
int getIntPosX() const;
|
|
int getIntPosY() const;
|
|
int getWidth() const;
|
|
int getHeight() const;
|
|
|
|
// Devuelve el rectangulo donde está el sprite
|
|
virtual SDL_Rect getPos() const;
|
|
|
|
// Establece el valor de la variable
|
|
void setPosX(int x);
|
|
void setPosY(int y);
|
|
void setWidth(int w);
|
|
void setHeight(int h);
|
|
|
|
// Establece la posición del objeto
|
|
void setPos(int x, int y);
|
|
void setPos(SDL_Point p);
|
|
virtual void setPos(SDL_Rect r);
|
|
|
|
// Incrementa el valor de la variable
|
|
void incPosX(int value);
|
|
void incPosY(int value);
|
|
|
|
// Obten el valor de la variable
|
|
SDL_Rect getSpriteClip() const;
|
|
|
|
// Establece el valor de la variable
|
|
void setSpriteClip(SDL_Rect rect);
|
|
void setSpriteClip(int x, int y, int w, int h);
|
|
|
|
// Obten el valor de la variable
|
|
std::shared_ptr<Texture> getTexture() const;
|
|
|
|
// Establece el valor de la variable
|
|
void setTexture(std::shared_ptr<Texture> texture);
|
|
}; |