Primer commit. Clon del repo de CC
This commit is contained in:
167
source/common/movingsprite.h
Normal file
167
source/common/movingsprite.h
Normal file
@@ -0,0 +1,167 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include "sprite.h"
|
||||
|
||||
#ifndef MOVINGSPRITE_H
|
||||
#define MOVINGSPRITE_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 xPrev; // Posición anterior en el eje X
|
||||
float yPrev; // Posición anterior 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, Texture *texture = nullptr, SDL_Renderer *renderer = 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();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getPosY();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getVelX();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getVelY();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getAccelX();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getAccelY();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getZoomW();
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getZoomH();
|
||||
|
||||
// Obten el valor de la variable
|
||||
double getAngle();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
bool getRotate();
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
Uint16 getRotateSpeed();
|
||||
|
||||
// Establece la posición y el tamaño del objeto
|
||||
void setRect(SDL_Rect rect);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setPosY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setVelY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAccelX(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAccelY(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomW(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setZoomH(float value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setAngle(double vaue);
|
||||
|
||||
// Incrementa el valor de la variable
|
||||
void incAngle(double value);
|
||||
|
||||
// Decrementa el valor de la variable
|
||||
void decAngle(double value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotate(bool value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
void setRotateSpeed(int value);
|
||||
|
||||
// Establece el valor de la variable
|
||||
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();
|
||||
|
||||
// Deshace el último movimiento
|
||||
void undoMove();
|
||||
|
||||
// Deshace el último movimiento en el eje X
|
||||
void undoMoveX();
|
||||
|
||||
// Deshace el último movimiento en el eje Y
|
||||
void undoMoveY();
|
||||
|
||||
// Pone a cero las velocidades de desplacamiento
|
||||
void clearVel();
|
||||
|
||||
// Devuelve el incremento en el eje X en pixels
|
||||
int getIncX();
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user