#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 =========================================================*/ mgr = new xManager("Ma fenetre SDL", WIN_WIDTH, WIN_HEIGHT); // Gestion erreur if( !mgr->status() ){ cout << "[INIT] -> " << SDL_GetError() << endl; return -1; } /* [2] On definit le background color =========================================================*/ mgr->setBackground(255, 0, 255, 150); // mgr->setImage( "src/1.bmp" ); /* [3] Gestion des animations =========================================================*/ xSpriteAnimation mario_mystery_block( mgr, "src/mario_crop.png", (SDL_Rect){0, 0, 50, 50} ); mario_mystery_block.addFrame( (SDL_Rect){4*19, 2*20, 20, 20} ); mario_mystery_block.addFrame( (SDL_Rect){5*19, 2*20, 20, 20} ); mario_mystery_block.addFrame( (SDL_Rect){6*19, 2*20, 20, 20} ); mario_mystery_block.addFrame( (SDL_Rect){7*19, 2*20, 20, 20} ); mario_mystery_block.start(200, SPRITE_ANIM_INFINITE); xSpriteAnimation mario_green_shell( mgr, "src/mario_crop.png", (SDL_Rect){50, 0, 50, 50} ); mario_green_shell.addFrame( (SDL_Rect){4*19, 210, 20, 20} ); mario_green_shell.addFrame( (SDL_Rect){5*19, 210, 20, 20} ); mario_green_shell.addFrame( (SDL_Rect){6*19, 210, 20, 20} ); mario_green_shell.addFrame( (SDL_Rect){7*19, 210, 20, 20} ); mario_green_shell.start(200, SPRITE_ANIM_INFINITE); /* [n-1] Boucle infinie =========================================================*/ mgr->update(); mgr->manageFps(FPS); running = true; while(running){ // Gestion d'un evenement mgr->waitEvent(SDL_QUIT, &quitEventHandler); // cout << "Main loop" << endl; // Gestion des FPS (vitesse de la boucle) mgr->manageFps(); mgr->update(); // Mise a jour du rendu } /* [n] Fin d'execution =========================================================*/ delete mgr; return 0; } void quitEventHandler(SDL_Event *e){ cout << "Exiting program" << endl; running = false; }