2016-03-11 15:17:57 +00:00
|
|
|
#ifndef DEF_SPRITE_H
|
|
|
|
|
|
|
|
#define DEF_SPRITE_H
|
|
|
|
|
|
|
|
/* [LIBS] Internes
|
|
|
|
=========================================================*/
|
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_image.h"
|
|
|
|
#include <vector>
|
|
|
|
#include <thread>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
/* [LIBS] Externes
|
|
|
|
=========================================================*/
|
|
|
|
#define SPRITE_ANIM_ONCE 0x1
|
|
|
|
#define SPRITE_ANIM_INFINITE 0x10
|
|
|
|
#define SPRITE_ANIM_REVERSE 0x100
|
|
|
|
|
|
|
|
/* [NS] Namespaces
|
|
|
|
=========================================================*/
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
|
|
class Sprite{
|
|
|
|
|
|
|
|
public:
|
2016-03-11 23:10:38 +00:00
|
|
|
Sprite(sdltl *m); // Sprite vide
|
|
|
|
Sprite(sdltl *m, const int rgb[]); // Sprite couleur
|
|
|
|
Sprite(sdltl *m, const char *url); // Sprite image
|
2016-03-11 15:17:57 +00:00
|
|
|
~Sprite();
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
void dimensions(); // Dimensions par defaut
|
|
|
|
void dimensions(SDL_Rect r); // Dimensions sortie
|
|
|
|
void dimensions(SDL_Rect r, SDL_Rect clip); // Dimensions in/out
|
2016-03-11 15:17:57 +00:00
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
void push(); // Ajoute a l'affichage
|
|
|
|
void pull(); // Retire de l'affichage
|
|
|
|
|
|
|
|
void update(); // Fait renmonter la mise a jour du manager
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
// GETTERS
|
2016-03-11 23:10:38 +00:00
|
|
|
SDL_Texture *texture();
|
|
|
|
sdltl *manager();
|
|
|
|
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
private:
|
2016-03-11 23:10:38 +00:00
|
|
|
sdltl *_manager;
|
2016-03-11 15:17:57 +00:00
|
|
|
SDL_Texture *_texture;
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
SDL_Rect _dst;
|
|
|
|
SDL_Rect _src;
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* [AGGR] Groupement de Sprite
|
|
|
|
=========================================================*/
|
|
|
|
class SpriteGroup{
|
|
|
|
|
|
|
|
public:
|
|
|
|
SpriteGroup();
|
|
|
|
void add(Sprite *s);
|
|
|
|
void remove(Sprite *s);
|
|
|
|
Sprite* get(int i);
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
void push(); // Ajoute les sprites a l'affichage
|
|
|
|
void pull(); // Retire les sprites de l'affichage
|
|
|
|
|
|
|
|
void update(); // Fait renmonter la mise a jour du manager
|
|
|
|
|
|
|
|
thread *animate(int t, int flags=0);
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
private:
|
2016-03-11 23:10:38 +00:00
|
|
|
vector<Sprite*> _sprites;
|
|
|
|
thread *_animation;
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
friend void SpriteGroupAnimation(SpriteGroup *sg, int t, int flags=SPRITE_ANIM_ONCE );
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* [BODY] Inclusion du corps
|
|
|
|
=========================================================*/
|
|
|
|
#include "Sprite.cpp"
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|