#ifndef ANIMATIONC_H
#define ANIMATIONC_H

// contains a bitmap with multiple animations
typedef struct ANIMATION_SET {
	ALLEGRO_BITMAP *bitmap;
} ANIMATION_SET;

typedef struct ANIMATION_FRAME {
    float frame_time;			// the time this frame should be visible
	float current_time;			// the elapsed time so far
	int set_pos_x;				// the position in the set bitmap
	int set_pos_y;				// !ONLY used when animation is ANIMATION_SET!
	int size_x;
	int size_y;
	int offset_x;
	int offset_y;
	ALLEGRO_BITMAP *bitmap;		// !ONLY used when animation is MULTIPLE_BITMAPS!
} ANIMATION_FRAME;

typedef struct ANIMATION {
	typedef enum { MULTIPLE_BITMAPS = 1, SET = 2} ANIMATION_TYPE;
	
	ANIMATION_TYPE type;			// determines whether the animation contains multiple bitmaps
									// or is made out of one animation_set
	int frame_count;				// contains the number of frames
	int active_frame;				// the currently active frame
	ANIMATION_SET *animation_set;	// contains the animation set
									// !ONLY used when animation is ANIMATION_SET!
    ANIMATION_FRAME *frames[];		// containing all the different frames
}ANIMATION;

typedef struct ANIMATION_INSTANCE {
	bool run;			// is set to false after a total animation
						// if looping is false
	bool looping;					
	bool ping_pong;
	int direction;		// 1 = upwards, -1 = downwards (for ping pong)
	float speed_multiplier;
	ANIMATION *animation;
} ANIMATION_INSTANCE;

ANIMATION* load_animation(const char *path);
ANIMATION_SET* load_animation_set(const char *path);
ANIMATION* load_animation_from_set(const char *path, ANIMATION_SET *set);
ANIMATION_INSTANCE* create_animation_instance(ANIMATION *anim, bool looping, bool ping_pong, float speed_multiplier);
void update_animation(ANIMATION_INSTANCE *anim_instance, float delta_time);
void draw_animation(ANIMATION_INSTANCE *anim_instance, int position_x, int position_y);
void destroy_animation(ANIMATION *anim);
void destroy_animation_instance(ANIMATION_INSTANCE *anim_instance);
void destroy_animation_set(ANIMATION_SET *set);

#endif
