#ifndef SPRITE_H
#define SPRITE_H

#include "common.h"

#define LENGHT_NAME_ANIMATION 20

typedef struct animation_s animation_t;

typedef struct sprite_s
{
    point_t      origin;
    int          width;
    int          height;
    animation_t *list_animations_first;
    animation_t *list_animations_last;
    animation_t *current_animation;
    bool         play;
    bool         loop;
    bool         flip;
    SDL_Texture *texture;
} sprite_t;

extern sprite_t*    Sprite_Create(point_t origin, int width, int height, SDL_Texture *texture);
extern void         Sprite_AnimationAdd(sprite_t* sprite, char *name, int frames_sleep);
extern void         Sprite_AnimationAddFrame(sprite_t* sprite, char *name, const SDL_Rect rect);
extern void         Sprite_AnimationPlay(sprite_t* sprite, char *name, bool loop);
extern void         Sprite_AnimationStop(sprite_t* sprite);
extern bool         Sprite_IsEndCurrentAnimation(sprite_t* sprite);
extern bool         Sprite_IsEndFrameCurrentAnimation(sprite_t* sprite, unsigned int number_frame);
extern bool         Sprite_IsNameCurrentAnimation(sprite_t* sprite, char *name);
extern char*        Sprite_GetNameCurrentAnimation(sprite_t* sprite);
extern unsigned int Sprite_GetNumberFrameCurrentAnimation(sprite_t* sprite);
extern void         Sprite_SetTexture(sprite_t* sprite, SDL_Texture *texture);
extern void         Sprite_SetFlip(sprite_t* sprite, bool flip);
extern void         Sprite_Update(sprite_t* sprite);
extern void         Sprite_Draw(SDL_Renderer *renderer, sprite_t* sprite, vector_t position);
extern void         Sprite_Free(sprite_t* sprite);

#endif
