#pragma once #include "ifdefs.h" #include "movingsprite.h" #ifndef ANIMATEDSPRITE_H #define ANIMATEDSPRITE_H #define MAX_FRAMES 30 #define MAX_ANIMATIONS 20 // Clase AnimatedSprite class AnimatedSprite : public MovingSprite { private: struct sAnimation { SDL_Rect frames[MAX_FRAMES]; // Cada uno de los frames que componen la animación Uint8 numFrames; // Numero de frames que componen la animación Uint8 speed; // Velocidad de la animación bool loop; // Indica si la animación se reproduce en bucle bool completed; // Indica si ha finalizado la animación }; sAnimation mAnimation[MAX_ANIMATIONS]; // Vector con las diferentes animaciones Uint8 mCurrentFrame; // Frame actual Uint16 mAnimationCounter; // Contador para las animaciones public: // Constructor AnimatedSprite(LTexture *texture, SDL_Renderer *renderer) : MovingSprite(0, 0, 0, 0, 0, 0, 0, 0, texture, renderer) { }; // Destructor ~AnimatedSprite(); // Iniciador void init(); // Calcula el frame correspondiente a la animación void animate(int index); // Establece el frame actual de la animación void setCurrentFrame(Uint8 num); // Establece el valor del contador void setAnimationCounter(Uint16 num); // Establece el rectangulo para un frame de una animación void setAnimationFrames(Uint8 index_animation, Uint8 index_frame, int x, int y, int w, int h); // Establece la velocidad de una animación void setAnimationSpeed(Uint8 index, Uint8 speed); // Establece el numero de frames de una animación void setAnimationNumFrames(Uint8 index, Uint8 num); // Establece si la animación se reproduce en bucle void setAnimationLoop(Uint8 index, bool loop); // Establece el valor de la variable void setCompleted(Uint8 index, bool value); // Comprueba si ha terminado la animación bool isCompleted(Uint8 index); // Devuelve el rectangulo de una animación y frame concreto SDL_Rect getAnimationClip(Uint8 index_animation, Uint8 index_frame); }; #endif