lab.cpp/SDL#4/main.cpp

92 lines
1.8 KiB
C++
Raw Normal View History

2016-03-12 23:22:28 +00:00
#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, 20, 20}
);
mario_mystery_block.addFrame(4, 2);
mario_mystery_block.addFrame(5, 2);
mario_mystery_block.addFrame(6, 2);
mario_mystery_block.addFrame(7, 2);
mario_mystery_block.start(200, SPRITE_ANIM_INFINITE);
xSpriteAnimation mario_green_shell(
mgr,
"src/mario_crop.png",
(SDL_Rect){50, 50, 20, 20}
);
mario_green_shell.addFrame(4, 11);
mario_green_shell.addFrame(5, 11);
mario_green_shell.addFrame(6, 11);
mario_green_shell.addFrame(7, 11);
mario_green_shell.start(200, SPRITE_ANIM_INFINITE);
/* [n-1] Boucle infinie
=========================================================*/
mgr->update();
mgr->manageFps(FPS);
running = true;
while(running){
mgr->waitEvent(SDL_QUIT, &quitEventHandler);
// cout << "Main loop" << endl;
mgr->update();
// 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;
}