2016-03-10 23:00:26 +00:00
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
// On cree un sdl-toplevel statique
|
|
|
|
static sdltl *mgr = NULL;
|
|
|
|
static bool running = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[]) {
|
|
|
|
srand(time(0));
|
|
|
|
|
|
|
|
/* [0] Initialisation de SDL
|
|
|
|
=========================================================*/
|
|
|
|
mgr = new sdltl("Ma fenetre SDL", WIN_WIDTH, WIN_HEIGHT);
|
|
|
|
|
|
|
|
/* [1] Creation de la fenetre
|
|
|
|
=========================================================*/
|
|
|
|
if( !mgr->status() ) cout << "Erreur: " << SDL_GetError() << endl;
|
|
|
|
|
|
|
|
|
|
|
|
/* [3] On definit le background color
|
|
|
|
=========================================================*/
|
|
|
|
mgr->setBackground(255, 255, 255);
|
|
|
|
// bool imageLoaded = mgr->setImage( "src/1.bmp" );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [4] On ajoute une sprite
|
|
|
|
=========================================================*/
|
2016-03-11 00:12:03 +00:00
|
|
|
SpriteGroup animated_coin;
|
2016-03-10 23:00:26 +00:00
|
|
|
|
2016-03-11 00:12:03 +00:00
|
|
|
/* (1) On enregistre les frames de l'animation */
|
|
|
|
for( int i = 0 ; i < 7 ; i++ ){
|
2016-03-10 23:00:26 +00:00
|
|
|
|
2016-03-11 00:12:03 +00:00
|
|
|
animated_coin.add( new Sprite(
|
|
|
|
"src/coins.jpg",
|
|
|
|
(SDL_Rect){0, 0, 180, 180},
|
|
|
|
(SDL_Rect){57+168*i, 40, 180, 180}
|
|
|
|
) );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-10 23:00:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-11 00:12:03 +00:00
|
|
|
/* [5] On lance l'animation en parallele
|
|
|
|
=========================================================*/
|
|
|
|
thread* anim = animated_coin.animate(mgr->window(), 1000 );
|
|
|
|
anim->detach(); // On laisse le thread tourner
|
|
|
|
delete anim; // On le supprime ensuite
|
|
|
|
|
2016-03-10 23:00:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [n-1] Boucle infinie
|
|
|
|
=========================================================*/
|
|
|
|
mgr->manageFps(FPS);
|
|
|
|
running = true;
|
|
|
|
while(running){
|
|
|
|
mgr->waitEvent(SDL_QUIT, &quitEventHandler);
|
|
|
|
|
2016-03-11 00:12:03 +00:00
|
|
|
cout << "Main loop" << endl;
|
|
|
|
|
2016-03-10 23:00:26 +00:00
|
|
|
// Gestion des FPS (vitesse de la boucle)
|
|
|
|
mgr->manageFps();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [n] Fin d'execution
|
|
|
|
=========================================================*/
|
|
|
|
delete mgr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void quitEventHandler(SDL_Event *e){
|
|
|
|
cout << "Ferme" << endl;
|
|
|
|
running = false;
|
|
|
|
}
|