146 lines
3.4 KiB
C++
146 lines
3.4 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 du manager + Creation de la fenetre
|
|
=========================================================*/
|
|
mgr = new sdltl("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" );
|
|
|
|
|
|
|
|
/* [4] On ajoute Une animation
|
|
=========================================================*/
|
|
/* (1) On cree les fonds pour couvrir les frames en arriere plan */
|
|
// int white[] = {255, 255, 255};
|
|
// Sprite *mb_background = new Sprite(mgr, white );
|
|
// mb_background->dimensions((SDL_Rect){0, 0, 20, 20});
|
|
|
|
|
|
// Sprite *gs_background = new Sprite(mgr, white);
|
|
// gs_background->dimensions((SDL_Rect){100, 0, 20, 20});
|
|
|
|
// Sprite *rs_background = new Sprite(mgr, white);
|
|
// rs_background->dimensions((SDL_Rect){150, 0, 20, 20});
|
|
|
|
// /* (2) On enregistre les frames de l'animation du bloc mystere */
|
|
SpriteGroup animated_mystery_bloc;
|
|
|
|
for( int i = 0 ; i < 4 ; i++ ){
|
|
|
|
animated_mystery_bloc.add( new Sprite(mgr, "src/mario_crop.png") );
|
|
animated_mystery_bloc.get(i)->dimensions(
|
|
(SDL_Rect){0, 0, 100, 100},
|
|
(SDL_Rect){4*19+19*i, 2*20, 20, 20}
|
|
);
|
|
|
|
}
|
|
|
|
// (3) On enregistre les frames de l'animation d'une carapace verte
|
|
SpriteGroup animated_green_shell;
|
|
|
|
for( int i = 0 ; i < 4 ; i++ ){
|
|
|
|
animated_green_shell.add( new Sprite(mgr, "src/mario_crop.png") );
|
|
animated_green_shell.get(i)->dimensions(
|
|
(SDL_Rect){100, 0, 20, 20},
|
|
(SDL_Rect){4*19+19*i, 11*19, 20, 20}
|
|
);
|
|
|
|
}
|
|
|
|
// /* (4) On enregistre les frames de l'animation d'une carapace rouge */
|
|
SpriteGroup animated_red_shell;
|
|
|
|
for( int i = 0 ; i < 4 ; i++ ){
|
|
|
|
animated_red_shell.add( new Sprite(mgr, "src/mario_crop.png") );
|
|
animated_red_shell.get(i)->dimensions(
|
|
(SDL_Rect){150, 0, 50, 50},
|
|
(SDL_Rect){2+19*i, 11*19, 20, 20}
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// /* [5] On lance les animation en parallele
|
|
// =========================================================*/
|
|
vector<thread*> animations(0);
|
|
|
|
|
|
// animations.push_back( animated_mystery_bloc.animate(
|
|
// 200, // delai entre-frames
|
|
// SPRITE_ANIM_INFINITE // FLAGS
|
|
// ) );
|
|
// delete animations[0]; // On le supprime ensuite
|
|
|
|
|
|
// animations.push_back( animated_green_shell.animate(
|
|
// 100, // delai entre-frames
|
|
// SPRITE_ANIM_INFINITE // FLAGS
|
|
// ) );
|
|
// delete animations[1]; // On le supprime ensuite
|
|
|
|
|
|
animations.push_back( animated_red_shell.animate(
|
|
100, // delai entre-frames
|
|
SPRITE_ANIM_INFINITE // FLAGS
|
|
) );
|
|
delete animations[0]; // On le supprime ensuite
|
|
|
|
|
|
|
|
|
|
/* [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;
|
|
} |