primer commit
This commit is contained in:
70
source/s_sprite.h
Normal file
70
source/s_sprite.h
Normal file
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL3/SDL_stdinc.h> // for Uint8
|
||||
#include <memory> // for shared_ptr
|
||||
class Surface; // lines 5-5
|
||||
|
||||
// Clase SSprite
|
||||
class SSprite
|
||||
{
|
||||
protected:
|
||||
// Variables
|
||||
std::shared_ptr<Surface> surface_; // Surface 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 surface que se dibujará en pantalla
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
SSprite(std::shared_ptr<Surface>, int x, int y, int w, int h);
|
||||
SSprite(std::shared_ptr<Surface>, SDL_Rect rect);
|
||||
explicit SSprite(std::shared_ptr<Surface>);
|
||||
|
||||
// Destructor
|
||||
virtual ~SSprite() = default;
|
||||
|
||||
// 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
|
||||
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; }
|
||||
|
||||
// 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 surface
|
||||
SDL_Rect getClip() const { return clip_; }
|
||||
|
||||
// Establece el rectangulo que se dibuja de la surface
|
||||
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 surface
|
||||
std::shared_ptr<Surface> getSurface() const { return surface_; }
|
||||
|
||||
// Establece la surface a utilizar
|
||||
void setSurface(std::shared_ptr<Surface> surface) { surface_ = surface; }
|
||||
};
|
||||
Reference in New Issue
Block a user