123 lines
3.5 KiB
C++
123 lines
3.5 KiB
C++
#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>
|
|
#include "sprite.h" // for Sprite
|
|
#include "texture.h"
|
|
|
|
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
|
class MovingSprite : public Sprite
|
|
{
|
|
protected:
|
|
float x_; // Posición en el eje X
|
|
float y_; // Posición en el eje Y
|
|
|
|
float vx_; // Velocidad en el eje X. Cantidad de pixeles a desplazarse
|
|
float vy_; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse
|
|
|
|
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 zoomW_; // Zoom aplicado a la anchura
|
|
float zoomH_; // Zoom aplicado a la altura
|
|
|
|
double angle_; // Angulo para dibujarlo
|
|
bool rotateEnabled_; // Indica si ha de rotar
|
|
int rotateSpeed_; // Velocidad de giro
|
|
double rotateAmount_; // Cantidad de grados a girar en cada iteración
|
|
int counter_; // Contador interno
|
|
SDL_Point *center_; // Centro de rotación
|
|
SDL_RendererFlip currentFlip_; // Indica como se voltea el sprite
|
|
|
|
public:
|
|
// Constructor
|
|
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);
|
|
|
|
// Mueve el sprite
|
|
void move();
|
|
|
|
// Rota el sprite
|
|
void rotate();
|
|
|
|
// Actualiza las variables internas del objeto
|
|
void update();
|
|
|
|
// Reinicia todas las variables
|
|
void clear();
|
|
|
|
// Muestra el sprite por pantalla
|
|
void render();
|
|
|
|
// Obten el valor de 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;
|
|
|
|
// Obten el valor de la variable
|
|
float getZoomW() const;
|
|
float getZoomH() const;
|
|
|
|
// Obten el valor de la variable
|
|
double getAngle() const;
|
|
bool getRotate() const;
|
|
Uint16 getRotateSpeed() const;
|
|
|
|
// Establece la posición y el tamaño del objeto
|
|
void setRect(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);
|
|
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);
|
|
|
|
// Establece el valor de la variable
|
|
void setZoomW(float value);
|
|
void setZoomH(float value);
|
|
|
|
// Establece el valor de la variable
|
|
void setAngle(double vaue);
|
|
void incAngle(double value);
|
|
void decAngle(double value);
|
|
|
|
// 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();
|
|
|
|
// Establece el valor de la variable
|
|
void setFlip(SDL_RendererFlip flip);
|
|
|
|
// Gira el sprite horizontalmente
|
|
void flip();
|
|
|
|
// Obtiene el valor de la variable
|
|
SDL_RendererFlip getFlip();
|
|
|
|
// Devuelve el rectangulo donde está el sprite
|
|
SDL_Rect getRect();
|
|
}; |