93 lines
1.8 KiB
C++
93 lines
1.8 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 sprite
|
|
=========================================================*/
|
|
SpriteGroup background;
|
|
|
|
/* (1) Bloc vide */
|
|
background.add( new Sprite(
|
|
(SDL_Rect) {0, 0, 200, 200}
|
|
));
|
|
|
|
/* (2) Bloc rose */
|
|
int pink[] = {255, 0, 255};
|
|
cout << "a: [" << (sizeof(pink)/sizeof(*pink)) << "]" << endl;
|
|
|
|
background.add( new Sprite(
|
|
pink,
|
|
(SDL_Rect){200, 0, 200, 200}
|
|
));
|
|
|
|
/* (2) Bloc image */
|
|
background.add( new Sprite(
|
|
"src/1.bmp",
|
|
(SDL_Rect){400, 0, 200, 200},
|
|
(SDL_Rect){200, 200, 200, 200}
|
|
));
|
|
|
|
|
|
|
|
|
|
/* [5] On ajoute les elements + mise a jour affichage
|
|
=========================================================*/
|
|
background.appendTo( mgr->screen() );
|
|
mgr->update();
|
|
|
|
|
|
|
|
|
|
|
|
/* [n-1] Boucle infinie
|
|
=========================================================*/
|
|
mgr->manageFps(FPS);
|
|
running = true;
|
|
while(running){
|
|
|
|
mgr->waitEvent(SDL_QUIT, &quitEventHandler);
|
|
|
|
// 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;
|
|
} |