Empezando a trabajar en la precarga de recursos para el juego

This commit is contained in:
2022-10-26 14:13:33 +02:00
parent db5d2901ee
commit c6e8050f95
4 changed files with 158 additions and 23 deletions

View File

@@ -11,21 +11,27 @@
#ifndef ANIMATEDSPRITE_H
#define ANIMATEDSPRITE_H
// Clase AnimatedSprite
struct t_animation
{
std::string name; // Nombre de la animacion
std::vector<SDL_Rect> frames; // Cada uno de los frames que componen la animación
int speed; // Velocidad de la animación
int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva
bool completed; // Indica si ha finalizado la animación
int currentFrame; // Frame actual
int counter; // Contador para las animaciones
};
struct animatedSprite_t
{
std::vector<t_animation> animations; // Vector con las diferentes animaciones
Texture *texture; // Textura con los graficos para el sprite
SDL_Renderer *renderer; // Renderizador para el sprite
};
class AnimatedSprite : public MovingSprite
{
private:
struct t_animation
{
std::string name; // Nombre de la animacion
std::vector<SDL_Rect> frames; // Cada uno de los frames que componen la animación
int speed; // Velocidad de la animación
int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva
bool completed; // Indica si ha finalizado la animación
int currentFrame; // Frame actual
int counter; // Contador para las animaciones
};
// Variables
std::vector<t_animation> animation; // Vector con las diferentes animaciones
int currentAnimation; // Animacion activa
@@ -33,6 +39,7 @@ private:
public:
// Constructor
AnimatedSprite(Texture *texture = nullptr, SDL_Renderer *renderer = nullptr, std::string file = "", std::vector<std::string> *buffer = nullptr);
AnimatedSprite(animatedSprite_t as);
// Destructor
~AnimatedSprite();
@@ -72,7 +79,7 @@ public:
int getIndex(std::string name);
// Carga la animación desde un fichero
bool loadFromFile(std::string filePath);
animatedSprite_t loadFromFile(std::string filePath);
// Carga la animación desde un vector
bool loadFromVector(std::vector<std::string> *source);