forked from jaildesigner-jailgames/jaildoctors_dilemma
81 lines
2.7 KiB
C++
81 lines
2.7 KiB
C++
#pragma once
|
|
|
|
#include <SDL3/SDL.h>
|
|
|
|
#include <memory> // Para shared_ptr
|
|
|
|
#include "sprite/surface_sprite.h" // Para SSprite
|
|
class Surface; // lines 8-8
|
|
|
|
// Clase SMovingSprite. Añade movimiento y flip al sprite
|
|
class SMovingSprite : public SSprite {
|
|
public:
|
|
protected:
|
|
float x_; // Posición en el eje X
|
|
float y_; // Posición en el eje Y
|
|
|
|
float vx_ = 0.0f; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
|
float vy_ = 0.0f; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
|
|
|
float ax_ = 0.0f; // Aceleración en el eje X. Variación de la velocidad
|
|
float ay_ = 0.0f; // Aceleración en el eje Y. Variación de la velocidad
|
|
|
|
SDL_RendererFlip flip_; // Indica como se voltea el sprite
|
|
|
|
// Mueve el sprite
|
|
void move();
|
|
|
|
public:
|
|
// Constructor
|
|
SMovingSprite(std::shared_ptr<Surface> surface, SDL_Rect pos, SDL_RendererFlip flip);
|
|
SMovingSprite(std::shared_ptr<Surface> surface, SDL_Rect pos);
|
|
explicit SMovingSprite(std::shared_ptr<Surface> surface);
|
|
|
|
// Destructor
|
|
virtual ~SMovingSprite() override = default;
|
|
|
|
// Actualiza las variables internas del objeto
|
|
virtual void update();
|
|
|
|
// Reinicia todas las variables a cero
|
|
void clear() override;
|
|
|
|
// Muestra el sprite por pantalla
|
|
void render() override;
|
|
void render(Uint8 source_color, Uint8 target_color) override;
|
|
|
|
// Obtiene la variable
|
|
float getPosX() const { return x_; }
|
|
float getPosY() const { return y_; }
|
|
float getVelX() const { return vx_; }
|
|
float getVelY() const { return vy_; }
|
|
float getAccelX() const { return ax_; }
|
|
float getAccelY() const { return ay_; }
|
|
|
|
// Establece la variable
|
|
void setVelX(float value) { vx_ = value; }
|
|
void setVelY(float value) { vy_ = value; }
|
|
void setAccelX(float value) { ax_ = value; }
|
|
void setAccelY(float value) { ay_ = value; }
|
|
|
|
// Establece el valor de la variable
|
|
void setFlip(SDL_RendererFlip flip) { flip_ = flip; }
|
|
|
|
// Gira el sprite horizontalmente
|
|
void flip() { flip_ = (flip_ == SDL_FLIP_HORIZONTAL) ? SDL_FLIP_NONE : SDL_FLIP_HORIZONTAL; }
|
|
|
|
// Obtiene el valor de la variable
|
|
SDL_RendererFlip getFlip() { return flip_; }
|
|
|
|
// Establece la posición y_ el tamaño del objeto
|
|
void setPos(SDL_Rect rect);
|
|
|
|
// Establece el valor de las variables
|
|
void setPos(float x, float y);
|
|
|
|
// Establece el valor de la variable
|
|
void setPosX(float value);
|
|
|
|
// Establece el valor de la variable
|
|
void setPosY(float value);
|
|
}; |