2016-03-12 23:22:28 +00:00
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
// On cree un sdl-toplevel statique
|
|
|
|
static xManager *mgr = NULL;
|
|
|
|
static bool running = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
srand(time(0));
|
|
|
|
|
|
|
|
/* [0] Initialisation du manager + Creation de la fenetre
|
|
|
|
=========================================================*/
|
2016-03-13 13:53:39 +00:00
|
|
|
mgr = new xManager("Ma fenetre SDL", BLOC_WIDTH*BLOC_SIZE, BLOC_HEIGHT*BLOC_SIZE);
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
// Gestion erreur
|
|
|
|
if( !mgr->status() ){
|
|
|
|
cout << "[INIT] -> " << SDL_GetError() << endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
// Couleur de fond
|
|
|
|
mgr->setBackground(0, 96, 183);
|
|
|
|
mgr->setImage("src/bg1.png");
|
2016-03-12 23:22:28 +00:00
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
/* [2] On definit le terrain
|
2016-03-12 23:22:28 +00:00
|
|
|
=========================================================*/
|
2016-03-13 13:53:39 +00:00
|
|
|
// On cree un bout du terrain
|
|
|
|
xMarioGrass btmleft(mgr, (SDL_Rect){-1, 20-2, 10, 3} );
|
|
|
|
btmleft.push();
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
/* [3] Gestion des animations (blocs animes)
|
|
|
|
=========================================================*/
|
|
|
|
// On cree une coquille verte
|
|
|
|
// xMarioGreenShell gs(mgr, 5, 20-3);
|
|
|
|
// gs.start(100, SPRITE_ANIM_INFINITE);
|
2016-03-12 23:22:28 +00:00
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
// On cree un bloc mystere
|
|
|
|
xMarioMysteryBloc mb(mgr, 5, 20-5);
|
|
|
|
mb.start(150, SPRITE_ANIM_INFINITE);
|
2016-03-12 23:22:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [n-1] Boucle infinie
|
|
|
|
=========================================================*/
|
2016-03-13 13:53:39 +00:00
|
|
|
|
|
|
|
// Gestion des evenements
|
|
|
|
SDL_Event event;
|
|
|
|
mgr->attachEvent(SDL_KEYDOWN, &keydownEventHandler);
|
|
|
|
mgr->attachEvent(SDL_QUIT, &quitEventHandler);
|
|
|
|
|
|
|
|
// Boucle de traitement
|
|
|
|
mgr->update(); mgr->update();
|
2016-03-12 23:22:28 +00:00
|
|
|
mgr->manageFps(FPS);
|
|
|
|
while(running){
|
|
|
|
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
// Gestion des evenements
|
|
|
|
while( SDL_PollEvent(&event) != 0 )
|
|
|
|
mgr->manageEvents(&event);
|
2016-03-12 23:22:28 +00:00
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
mgr->manageFps(); // Gestion des FPS (speed)
|
2016-03-13 09:08:07 +00:00
|
|
|
mgr->update(); // Mise a jour du rendu
|
2016-03-12 23:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [n] Fin d'execution
|
|
|
|
=========================================================*/
|
|
|
|
delete mgr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
/* GESTION DE QUAND ON QUITTE LA FENETRE
|
|
|
|
*
|
|
|
|
* @e<SDL_Event*> Pointeur sur l'evenement appelant
|
|
|
|
*
|
|
|
|
*/
|
2016-03-12 23:22:28 +00:00
|
|
|
void quitEventHandler(SDL_Event *e){
|
2016-03-13 09:08:07 +00:00
|
|
|
cout << "Exiting program" << endl;
|
2016-03-12 23:22:28 +00:00
|
|
|
running = false;
|
2016-03-13 13:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* GESTION DE QUAND ON APPUIE SUR FLECHE BAS
|
|
|
|
*
|
|
|
|
* @e<SDL_Event*> Pointeur sur l'evenement appelant
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void keydownEventHandler(SDL_Event *e){
|
|
|
|
cout << "BAS" << endl;
|
2016-03-12 23:22:28 +00:00
|
|
|
}
|