#pragma once #include // Para SDL_FRect #include // Para shared_ptr #include // Para string #include // Para vector #include "moving_sprite.h" // Para MovingSprite class Texture; struct Animation { std::string name; // Nombre de la animación std::vector frames; // Frames que componen la animación int speed; // Velocidad de reproducción int loop; // Frame al que vuelve la animación al terminar (-1 para no repetir) bool completed; // Indica si la animación ha finalizado int current_frame; // Frame actual en reproducción int counter; // Contador para la animación Animation() : name(std::string()), speed(5), loop(0), completed(false), current_frame(0), counter(0) {} }; using AnimationsFileBuffer = std::vector; // Carga las animaciones desde un fichero en un vector AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path); class AnimatedSprite : public MovingSprite { public: // Constructor AnimatedSprite(std::shared_ptr texture, const std::string &file_path); AnimatedSprite(std::shared_ptr texture, const AnimationsFileBuffer &animations); explicit AnimatedSprite(std::shared_ptr texture) : MovingSprite(texture) {} // Destructor virtual ~AnimatedSprite() override = default; // Actualización del objeto void update() override; // Actualiza la animación bool animationIsCompleted(); // Comprueba si la animación ha terminado int getIndex(const std::string &name); // Obtiene el índice de una animación según su nombre // Manipulación de animaciones void setCurrentAnimation(const std::string &name = "default"); // Establece animación por nombre void setCurrentAnimation(int index = 0); // Establece animación por índice void resetAnimation(); // Reinicia la animación protected: // Almacenamiento de animaciones std::vector animations_; // Vector de animaciones disponibles int current_animation_ = 0; // Índice de la animación activa // Procesos internos void animate(); // Calcula el frame actual de la animación void loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source); // Carga animaciones desde un buffer };