67 lines
1.8 KiB
C++
67 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <SDL2/SDL_rect.h> // para 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
|
|
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();
|
|
|
|
// Obten el valor de la variable
|
|
int getX() const;
|
|
int getY() const;
|
|
int getWidth() const;
|
|
int getHeight() const;
|
|
|
|
// Devuelve el rectangulo donde está el sprite
|
|
SDL_Rect getPosition() const;
|
|
|
|
// Establece el valor de la variable
|
|
void setX(int x);
|
|
void setY(int y);
|
|
void setWidth(int w);
|
|
void setHeight(int h);
|
|
|
|
// Establece la posición del objeto
|
|
void setPosition(int x, int y);
|
|
void setPosition(SDL_Point p);
|
|
void setPosition(SDL_Rect r);
|
|
|
|
// Incrementa el valor de la variable
|
|
void incX(int value);
|
|
void incY(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);
|
|
}; |