79 lines
1.6 KiB
C
79 lines
1.6 KiB
C
|
#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:
|
||
|
Sprite(SDL_Rect r);
|
||
|
Sprite(const int rgb[], SDL_Rect r);
|
||
|
Sprite(const char url[], SDL_Rect r, SDL_Rect clip);
|
||
|
~Sprite();
|
||
|
|
||
|
void setImage(const char url[], int ox=0, int oy=0);
|
||
|
|
||
|
void appendTo(sdltl *mgr);
|
||
|
void removeFrom(sdltl *mgr);
|
||
|
|
||
|
// GETTERS
|
||
|
SDL_Surface *surface();
|
||
|
|
||
|
private:
|
||
|
SDL_Surface *_surface;
|
||
|
SDL_Texture *_texture;
|
||
|
|
||
|
SDL_Rect _rect;
|
||
|
SDL_Rect _origin;
|
||
|
|
||
|
};
|
||
|
|
||
|
/* [AGGR] Groupement de Sprite
|
||
|
=========================================================*/
|
||
|
class SpriteGroup{
|
||
|
|
||
|
public:
|
||
|
SpriteGroup();
|
||
|
void add(Sprite *s);
|
||
|
void remove(Sprite *s);
|
||
|
Sprite* get(int i);
|
||
|
void appendTo(sdltl *mgr);
|
||
|
void removeFrom(sdltl *mgr);
|
||
|
|
||
|
thread *animate(sdltl *mgr, int t, int flags=0);
|
||
|
|
||
|
private:
|
||
|
SDL_Renderer *_renderer;
|
||
|
vector<Sprite*> _sprites;
|
||
|
thread *_animation;
|
||
|
|
||
|
|
||
|
friend void SpriteGroupAnimation(sdltl *mgr, SpriteGroup *sg, int t, int flags=SPRITE_ANIM_ONCE );
|
||
|
|
||
|
};
|
||
|
|
||
|
|
||
|
/* [BODY] Inclusion du corps
|
||
|
=========================================================*/
|
||
|
#include "Sprite.cpp"
|
||
|
|
||
|
|
||
|
#endif
|