117 lines
2.6 KiB
C++
117 lines
2.6 KiB
C++
#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 animation
|
|
=========================================================*/
|
|
/* (1) On met un fond */
|
|
int white[] = {255, 255, 255};
|
|
Sprite *coin_background = new Sprite(
|
|
white,
|
|
(SDL_Rect){0, 0, 180, 200}
|
|
);
|
|
|
|
|
|
/* (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 );
|
|
|
|
|
|
|
|
|
|
/* [5] On lance l'animation en parallele
|
|
=========================================================*/
|
|
thread* anim = animated_coin.animate(mgr->window(), 500 );
|
|
anim->detach(); // On laisse le thread tourner
|
|
delete anim; // On le supprime ensuite
|
|
|
|
|
|
|
|
|
|
/* [n-1] Boucle infinie
|
|
=========================================================*/
|
|
mgr->manageFps(FPS);
|
|
running = true;
|
|
while(running){
|
|
mgr->waitEvent(SDL_QUIT, &quitEventHandler);
|
|
|
|
cout << "Main loop" << endl;
|
|
|
|
// 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;
|
|
} |