Commit de vesprà tirada a la brossa
This commit is contained in:
@@ -1,25 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint16
|
||||
#include <memory> // for shared_ptr
|
||||
#include "sprite.h" // for Sprite
|
||||
#include <SDL2/SDL_rect.h> // for SDL_Rect, SDL_Point
|
||||
#include <SDL2/SDL_render.h> // for SDL_RendererFlip
|
||||
#include <SDL2/SDL_stdinc.h> // for Uint16
|
||||
#include <memory> // for shared_ptr
|
||||
#include "sprite.h" // for Sprite
|
||||
class Texture;
|
||||
|
||||
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
||||
// Clase MovingSprite. Añade movimiento y efectos de rotación, zoom y flip al sprite
|
||||
class MovingSprite : public Sprite
|
||||
{
|
||||
protected:
|
||||
public:
|
||||
struct Rotate
|
||||
{
|
||||
bool enabled; // Indica si ha de rotar
|
||||
int counter; // Contador
|
||||
int speed; // Velocidad de giro
|
||||
float angle; // Angulo para dibujarlo
|
||||
float amount; // Cantidad de grados a girar en cada iteración
|
||||
double angle; // Angulo para dibujarlo
|
||||
float amount; // Cantidad de grados a girar en cada iteración
|
||||
SDL_Point *center; // Centro de rotación
|
||||
};
|
||||
|
||||
protected:
|
||||
float x_; // Posición en el eje X
|
||||
float y_; // Posición en el eje Y
|
||||
|
||||
@@ -29,20 +31,13 @@ protected:
|
||||
float ax_; // Aceleración en el eje X. Variación de la velocidad
|
||||
float ay_; // Aceleración en el eje Y. Variación de la velocidad
|
||||
|
||||
float zoom_w_; // Zoom aplicado a la anchura
|
||||
float zoom_h_; // Zoom aplicado a la altura
|
||||
|
||||
int counter_; // Contador interno
|
||||
Rotate rotate_; // Variables usada para controlar la rotación del sprite
|
||||
float zoom_w_; // Zoom aplicado a la anchura
|
||||
float zoom_h_; // Zoom aplicado a la altura
|
||||
SDL_RendererFlip flip_; // Indica como se voltea el sprite
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit MovingSprite(float x = 0, float y = 0, int w = 0, int h = 0, float velx = 0, float vely = 0, float accelx = 0, float accely = 0, std::shared_ptr<Texture> texture = nullptr);
|
||||
explicit MovingSprite(std::shared_ptr<Texture> texture = nullptr);
|
||||
|
||||
// Destructor
|
||||
virtual ~MovingSprite() = default;
|
||||
// Incrementa el valor del ángulo
|
||||
void updateAngle();
|
||||
|
||||
// Mueve el sprite
|
||||
void move();
|
||||
@@ -50,6 +45,15 @@ public:
|
||||
// Rota el sprite
|
||||
void rotate();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos, MovingSprite::Rotate rotate, float zoom_w, float zoom_h, SDL_RendererFlip flip);
|
||||
MovingSprite(std::shared_ptr<Texture> texture, SDL_Rect pos);
|
||||
explicit MovingSprite(std::shared_ptr<Texture> texture);
|
||||
|
||||
// Destructor
|
||||
~MovingSprite() = default;
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
virtual void update();
|
||||
|
||||
@@ -59,45 +63,28 @@ public:
|
||||
// Muestra el sprite por pantalla
|
||||
void render() override;
|
||||
|
||||
// Obten el valor de la variable
|
||||
// Obtiene la variable
|
||||
float getPosX() const;
|
||||
float getPosY() const;
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getVelX() const;
|
||||
float getVelY() const;
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getAccelX() const;
|
||||
float getAccelY() const;
|
||||
|
||||
// Establece la variable
|
||||
void setVelX(float value);
|
||||
void setVelY(float value);
|
||||
void setAccelX(float value);
|
||||
void setAccelY(float value);
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getZoomW() const;
|
||||
float getZoomH() const;
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getAngle() const;
|
||||
bool getRotate() const;
|
||||
Uint16 getRotateSpeed() const;
|
||||
|
||||
// Establece la posición del objeto
|
||||
void setPos(SDL_Rect rect) override;
|
||||
void setPos(float x, float y);
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getPos() const override;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(float value);
|
||||
void setPosY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelX(float value);
|
||||
void setVelY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAccelX(float value);
|
||||
void setAccelY(float value);
|
||||
bool isRotating() const;
|
||||
double getAngle() const;
|
||||
int getRotateSpeed() const;
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomW(float value);
|
||||
@@ -105,17 +92,15 @@ public:
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAngle(double vaue);
|
||||
void incAngle(double value);
|
||||
void decAngle(double value);
|
||||
|
||||
// Activa o desactiva el efecto derotación
|
||||
void enableRotate();
|
||||
void disableRotate();
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotate(bool value);
|
||||
void setRotateSpeed(int value);
|
||||
void setRotateAmount(double value);
|
||||
|
||||
// Quita el efecto de rotación y deja el sprite en su angulo inicial.
|
||||
void disableRotate();
|
||||
|
||||
// Cambia el sentido de la rotación
|
||||
void switchRotate();
|
||||
|
||||
@@ -128,5 +113,15 @@ public:
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip getFlip();
|
||||
|
||||
// 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);
|
||||
};
|
||||
Reference in New Issue
Block a user