2016-03-12 23:22:28 +00:00
|
|
|
#ifndef DEF_XMANAGER_H
|
|
|
|
|
|
|
|
#define DEF_XMANAGER_H
|
|
|
|
class xManager{
|
|
|
|
|
|
|
|
public:
|
|
|
|
xManager(const char *t, int w, int h);
|
|
|
|
~xManager();
|
|
|
|
SDL_Window *window();
|
|
|
|
SDL_Renderer *renderer();
|
|
|
|
bool status();
|
|
|
|
bool setBackground(Uint8 r=0xff, Uint8 g=0xff, Uint8 b=0xff, Uint8 a=0xff);
|
|
|
|
bool setImage(const char *url);
|
|
|
|
|
2016-03-15 21:56:39 +00:00
|
|
|
|
2016-03-17 22:18:52 +00:00
|
|
|
bool collide(SDL_Rect a, SDL_Rect b, vector<bool>& cols); // Collision entre 2 SDL_Rect
|
2016-03-15 23:15:18 +00:00
|
|
|
bool hit(xSprite *current, int movex=0, int movey=0); // Gestion des collisions
|
|
|
|
bool hit(string current, int movex=0, int movey=0); // Gestion des collisions
|
2016-03-13 17:33:47 +00:00
|
|
|
|
2016-03-15 23:15:18 +00:00
|
|
|
xSprite* get(string index); // retourne une sprite
|
2016-03-13 19:36:16 +00:00
|
|
|
|
2016-03-15 23:15:18 +00:00
|
|
|
void push(string index, xSprite* sprite);
|
2016-03-13 19:36:16 +00:00
|
|
|
void pull(string index);
|
2016-03-15 23:15:18 +00:00
|
|
|
void pull(xSprite *sprite);
|
2016-03-16 13:36:46 +00:00
|
|
|
void clearAll(); // Supprime toutes les sprites
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
void update();
|
|
|
|
|
|
|
|
void manageFps(const int fps=0);
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
|
|
|
|
// Gestion des evenements
|
|
|
|
void attachEvent(SDL_EventType t, void(*handler)(SDL_Event*) );
|
|
|
|
void manageEvents(SDL_Event* event);
|
|
|
|
|
|
|
|
|
2016-03-16 13:36:46 +00:00
|
|
|
|
|
|
|
// Boucle infinie
|
|
|
|
int state;
|
|
|
|
// 0 -> Boucle infinie
|
|
|
|
// 1 -> Arret jeu
|
|
|
|
// 2 -> mort
|
2019-10-31 22:17:56 +00:00
|
|
|
|
2016-03-16 13:36:46 +00:00
|
|
|
|
2016-03-15 21:56:39 +00:00
|
|
|
// DEBUG
|
|
|
|
void debug();
|
|
|
|
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
private:
|
|
|
|
// gestion FPS
|
|
|
|
Uint32 _lasttick;
|
|
|
|
Uint32 _fpstime;
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
// Gestion evenements
|
|
|
|
vector<SDL_EventType> _events;
|
|
|
|
vector<void(*)(SDL_Event*)> _handlers;
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
// status de l'initialisation
|
|
|
|
bool _status;
|
|
|
|
|
|
|
|
// Elements utiles
|
|
|
|
SDL_Window *_window;
|
2016-03-13 13:53:39 +00:00
|
|
|
SDL_Rect _winrect;
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
SDL_Renderer *_renderer;
|
|
|
|
SDL_Texture *_texture;
|
|
|
|
|
|
|
|
// Gestion des textures
|
2016-03-13 17:33:47 +00:00
|
|
|
vector<string> _indexes;
|
2016-03-15 23:15:18 +00:00
|
|
|
vector<xSprite*> _sprites;
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
// Protection thread-safe
|
2016-03-13 23:06:33 +00:00
|
|
|
mutex _mutex_push;
|
|
|
|
mutex _mutex_pull;
|
|
|
|
mutex _mutex_update;
|
|
|
|
mutex _mutex_hit;
|
2016-03-15 21:56:39 +00:00
|
|
|
// DEBUG
|
|
|
|
SDL_Rect _debug;
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|