Files
coffee_crisis_arcade_edition/source/sprite.h
2025-03-27 08:14:37 +01:00

73 lines
2.4 KiB
C++

#pragma once
#include <SDL3/SDL.h>
#include <SDL3/SDL_rect.h> // Para SDL_FRect, SDL_FPoint
#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_FRect pos_; // Posición y tamaño donde dibujar el sprite
SDL_FRect 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>, float x, float y, float w, float h);
Sprite(std::shared_ptr<Texture>, SDL_FRect 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
float getX() const { return pos_.x; }
float getY() const { return pos_.y; }
float getWidth() const { return pos_.w; }
float getHeight() const { return pos_.h; }
// Devuelve el rectangulo donde está el sprite
SDL_FRect getPosition() const { return pos_; }
SDL_FRect &getRect() { return pos_; }
// Establece la posición y el tamaño
void setX(float x) { pos_.x = x; }
void setY(float y) { pos_.y = y; }
void setWidth(float w) { pos_.w = w; }
void setHeight(float h) { pos_.h = h; }
// Establece la posición del objeto
void setPosition(float x, float y);
void setPosition(SDL_FPoint p);
void setPosition(SDL_FRect r) { pos_ = r; }
// Establece el nivel de zoom
void setZoom(float zoom) { zoom_ = zoom; }
// Aumenta o disminuye la posición
void incX(float value) { pos_.x += value; }
void incY(float value) { pos_.y += value; }
// Obtiene el rectangulo que se dibuja de la textura
SDL_FRect getSpriteClip() const { return sprite_clip_; }
// Establece el rectangulo que se dibuja de la textura
void setSpriteClip(SDL_FRect rect) { sprite_clip_ = rect; }
void setSpriteClip(float x, float y, float w, float h) { sprite_clip_ = (SDL_FRect){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; }
};