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" );
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-11 00:25:46 +00:00
|
|
|
/* [4] On ajoute Une animation
|
2016-03-10 23:00:26 +00:00
|
|
|
=========================================================*/
|
2016-03-11 00:25:46 +00:00
|
|
|
/* (1) On met un fond */
|
|
|
|
int white[] = {255, 255, 255};
|
|
|
|
Sprite *coin_background = new Sprite(
|
|
|
|
white,
|
|
|
|
(SDL_Rect){0, 0, 180, 200}
|
|
|
|
);
|
2016-03-10 23:00:26 +00:00
|
|
|
|
|
|
|
|
2016-03-11 00:25:46 +00:00
|
|
|
/* (2) On enregistre les frames de l'animation */
|
|
|
|
SpriteGroup animated_coin;
|
|
|
|
animated_coin.add( new Sprite(
|
|
|
|
"src/coins.jpg",
|
|
|
|
(SDL_Rect){0, 0, 180, 200},
|
|
|
|
(SDL_Rect){57, 50, 180, 200}
|
|
|
|
) );
|
|
|
|
// On ajoute un fond entre chaque pour cacher si chgt taille
|
|
|
|
animated_coin.add( coin_background );
|
|
|
|
|
|
|
|
animated_coin.add( new Sprite(
|
|
|
|
"src/coins.jpg",
|
|
|
|
(SDL_Rect){0, 0, 180, 200},
|
|
|
|
(SDL_Rect){57+200, 50, 180, 200}
|
|
|
|
) );
|
|
|
|
animated_coin.add( coin_background );
|
|
|
|
|
|
|
|
animated_coin.add( new Sprite(
|
|
|
|
"src/coins.jpg",
|
|
|
|
(SDL_Rect){30, 0, 150, 200},
|
|
|
|
(SDL_Rect){57+200*2, 50, 180, 200}
|
|
|
|
) );
|
|
|
|
animated_coin.add( coin_background );
|
|
|
|
|
|
|
|
animated_coin.add( new Sprite(
|
|
|
|
"src/coins.jpg",
|
|
|
|
(SDL_Rect){80, 0, 100, 200},
|
|
|
|
(SDL_Rect){57+200*3-30, 50, 180, 200}
|
|
|
|
) );
|
|
|
|
animated_coin.add( coin_background );
|
|
|
|
|
|
|
|
animated_coin.add( new Sprite(
|
|
|
|
"src/coins.jpg",
|
|
|
|
(SDL_Rect){30, 0, 150, 200},
|
|
|
|
(SDL_Rect){57+200*4+10, 50, 180, 200}
|
|
|
|
) );
|
|
|
|
animated_coin.add( coin_background );
|
2016-03-10 23:00:26 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-11 00:12:03 +00:00
|
|
|
/* [5] On lance l'animation en parallele
|
|
|
|
=========================================================*/
|
2016-03-11 00:25:46 +00:00
|
|
|
thread* anim = animated_coin.animate(mgr->window(), 500 );
|
2016-03-11 00:12:03 +00:00
|
|
|
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;
|
|
|
|
}
|