forked from jaildesigner-jailgames/jaildoctors_dilemma
canvi de pc
This commit is contained in:
128
source/sprite.h
128
source/sprite.h
@@ -1,96 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect
|
||||
#include <SDL2/SDL_render.h> // Para SDL_Renderer
|
||||
#include <SDL2/SDL_rect.h> // Para SDL_Rect, SDL_Point
|
||||
#include <memory> // Para shared_ptr
|
||||
class Texture;
|
||||
|
||||
// Clase sprite
|
||||
class Sprite
|
||||
{
|
||||
protected:
|
||||
// Objetos y punteros
|
||||
SDL_Renderer *renderer; // Puntero al renderizador de la ventana
|
||||
Texture *texture; // Textura donde estan todos los dibujos del sprite
|
||||
|
||||
// Variables
|
||||
int x; // Posición en el eje X donde dibujar el sprite
|
||||
int y; // Posición en el eje Y donde dibujar el sprite
|
||||
int w; // Ancho del sprite
|
||||
int h; // Alto del sprite
|
||||
SDL_Rect spriteClip; // Rectangulo de origen de la textura que se dibujará en pantalla
|
||||
bool enabled; // Indica si el sprite esta habilitado
|
||||
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 clip_; // Rectangulo de origen de la textura que se dibujará en pantalla
|
||||
double zoom_ = 1.0f; // Zoom aplicado a la textura
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Sprite(int x = 0, int y = 0, int w = 0, int h = 0, Texture *texture = nullptr, SDL_Renderer *renderer = nullptr);
|
||||
Sprite(SDL_Rect rect, Texture *texture, SDL_Renderer *renderer);
|
||||
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
|
||||
void render();
|
||||
virtual void render();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getPosX();
|
||||
// Reinicia las variables a cero
|
||||
virtual void clear();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getPosY();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getWidth();
|
||||
|
||||
// Obten el valor de la variable
|
||||
int getHeight();
|
||||
|
||||
// Establece la posición del objeto
|
||||
void setPos(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(int x);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosY(int y);
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void incPosX(int value);
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void incPosY(int value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setWidth(int w);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setHeight(int h);
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Rect getSpriteClip();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSpriteClip(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setSpriteClip(int x, int y, int w, int h);
|
||||
|
||||
// Obten el valor de la variable
|
||||
Texture *getTexture();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setTexture(Texture *texture);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRenderer(SDL_Renderer *renderer);
|
||||
|
||||
// Obten el valor de la variable
|
||||
SDL_Renderer *getRenderer();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setEnabled(bool value);
|
||||
|
||||
// Comprueba si el objeto está habilitado
|
||||
bool isEnabled();
|
||||
// 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 getRect();
|
||||
SDL_Rect getPosition() const { return pos_; }
|
||||
SDL_Rect &getRect() { return pos_; }
|
||||
|
||||
// Establece los valores de posición y tamaño del sprite
|
||||
void setRect(SDL_Rect rect);
|
||||
// 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 getClip() const { return clip_; }
|
||||
|
||||
// Establece el rectangulo que se dibuja de la textura
|
||||
void setClip(SDL_Rect rect) { clip_ = rect; }
|
||||
void setClip(int x, int y, int w, int h) { 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; }
|
||||
};
|
||||
Reference in New Issue
Block a user