Arreglades les herencies de Sprite
Abans de llevar mil coses que sobren i replantejar-se estes 4 classes
This commit is contained in:
@@ -1,16 +1,25 @@
|
||||
#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 <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 "sprite.h" // for Sprite
|
||||
#include "texture.h"
|
||||
|
||||
// Clase MovingSprite. Añade posicion y velocidad en punto flotante
|
||||
class MovingSprite : public Sprite
|
||||
{
|
||||
protected:
|
||||
struct Rotate
|
||||
{
|
||||
bool enabled; // Indica si ha de rotar
|
||||
int speed; // Velocidad de giro
|
||||
float angle; // Angulo para dibujarlo
|
||||
float amount; // Cantidad de grados a girar en cada iteración
|
||||
SDL_Point *center; // Centro de rotación
|
||||
};
|
||||
|
||||
float x_; // Posición en el eje X
|
||||
float y_; // Posición en el eje Y
|
||||
|
||||
@@ -20,20 +29,17 @@ 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 zoomW_; // Zoom aplicado a la anchura
|
||||
float zoomH_; // Zoom aplicado a la altura
|
||||
float zoom_w_; // Zoom aplicado a la anchura
|
||||
float zoom_h_; // 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
|
||||
int counter_; // Contador interno
|
||||
Rotate rotate_; // Variables usada para controlar la rotación del sprite
|
||||
SDL_RendererFlip flip_; // 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);
|
||||
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);
|
||||
|
||||
// Mueve el sprite
|
||||
void move();
|
||||
@@ -42,13 +48,13 @@ public:
|
||||
void rotate();
|
||||
|
||||
// Actualiza las variables internas del objeto
|
||||
void update();
|
||||
virtual void update();
|
||||
|
||||
// Reinicia todas las variables
|
||||
void clear();
|
||||
|
||||
// Muestra el sprite por pantalla
|
||||
void render();
|
||||
void render() override;
|
||||
|
||||
// Obten el valor de la variable
|
||||
float getPosX() const;
|
||||
@@ -67,16 +73,17 @@ public:
|
||||
float getZoomH() const;
|
||||
|
||||
// Obten el valor de la variable
|
||||
double getAngle() const;
|
||||
float 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
|
||||
// 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);
|
||||
@@ -118,6 +125,5 @@ public:
|
||||
// Obtiene el valor de la variable
|
||||
SDL_RendererFlip getFlip();
|
||||
|
||||
// Devuelve el rectangulo donde está el sprite
|
||||
SDL_Rect getRect();
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user