2016-03-11 15:17:57 +00:00
|
|
|
#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));
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
/* [0] Initialisation du manager + Creation de la fenetre
|
2016-03-11 15:17:57 +00:00
|
|
|
=========================================================*/
|
|
|
|
mgr = new sdltl("Ma fenetre SDL", WIN_WIDTH, WIN_HEIGHT);
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
// Gestion erreur
|
|
|
|
if( !mgr->status() ){
|
|
|
|
cout << "[INIT] -> " << SDL_GetError() << endl;
|
|
|
|
return -1;
|
|
|
|
}
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
/* [2] On definit le background color
|
2016-03-11 15:17:57 +00:00
|
|
|
=========================================================*/
|
2016-03-11 23:10:38 +00:00
|
|
|
mgr->setBackground(255, 0, 255, 150);
|
|
|
|
// mgr->setImage( "src/1.bmp" );
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
|
2016-03-12 23:22:28 +00:00
|
|
|
/* [3] Gestion des animations
|
|
|
|
=========================================================*/
|
|
|
|
// Definition du spritesheet
|
|
|
|
// SpriteSheet mario("url", unit_width, unit_height);
|
|
|
|
|
|
|
|
// Creation des animations a partir du spritesheet
|
|
|
|
// SpriteAnimation mario_mystery_block(mario, x, y);
|
|
|
|
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
/* [4] On ajoute Une animation
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) On cree les fonds pour couvrir les frames en arriere plan */
|
2016-03-11 23:10:38 +00:00
|
|
|
// int white[] = {255, 255, 255};
|
|
|
|
// Sprite *mb_background = new Sprite(mgr, white );
|
|
|
|
// mb_background->dimensions((SDL_Rect){0, 0, 20, 20});
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
// Sprite *gs_background = new Sprite(mgr, white);
|
|
|
|
// gs_background->dimensions((SDL_Rect){100, 0, 20, 20});
|
2016-03-11 15:17:57 +00:00
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
// Sprite *rs_background = new Sprite(mgr, white);
|
|
|
|
// rs_background->dimensions((SDL_Rect){150, 0, 20, 20});
|
2016-03-11 15:17:57 +00:00
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
// /* (2) On enregistre les frames de l'animation du bloc mystere */
|
2016-03-11 15:17:57 +00:00
|
|
|
SpriteGroup animated_mystery_bloc;
|
|
|
|
|
|
|
|
for( int i = 0 ; i < 4 ; i++ ){
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
animated_mystery_bloc.add( new Sprite(mgr, "src/mario_crop.png") );
|
|
|
|
animated_mystery_bloc.get(i)->dimensions(
|
|
|
|
(SDL_Rect){0, 0, 100, 100},
|
2016-03-11 15:17:57 +00:00
|
|
|
(SDL_Rect){4*19+19*i, 2*20, 20, 20}
|
2016-03-11 23:10:38 +00:00
|
|
|
);
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
// (3) On enregistre les frames de l'animation d'une carapace verte
|
2016-03-11 15:17:57 +00:00
|
|
|
SpriteGroup animated_green_shell;
|
|
|
|
|
|
|
|
for( int i = 0 ; i < 4 ; i++ ){
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
animated_green_shell.add( new Sprite(mgr, "src/mario_crop.png") );
|
|
|
|
animated_green_shell.get(i)->dimensions(
|
2016-03-11 15:17:57 +00:00
|
|
|
(SDL_Rect){100, 0, 20, 20},
|
|
|
|
(SDL_Rect){4*19+19*i, 11*19, 20, 20}
|
2016-03-11 23:10:38 +00:00
|
|
|
);
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
// /* (4) On enregistre les frames de l'animation d'une carapace rouge */
|
2016-03-11 15:17:57 +00:00
|
|
|
SpriteGroup animated_red_shell;
|
|
|
|
|
|
|
|
for( int i = 0 ; i < 4 ; i++ ){
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
animated_red_shell.add( new Sprite(mgr, "src/mario_crop.png") );
|
|
|
|
animated_red_shell.get(i)->dimensions(
|
|
|
|
(SDL_Rect){150, 0, 50, 50},
|
2016-03-11 15:17:57 +00:00
|
|
|
(SDL_Rect){2+19*i, 11*19, 20, 20}
|
2016-03-11 23:10:38 +00:00
|
|
|
);
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-03-11 23:10:38 +00:00
|
|
|
// /* [5] On lance les animation en parallele
|
|
|
|
// =========================================================*/
|
2016-03-11 15:17:57 +00:00
|
|
|
vector<thread*> animations(0);
|
|
|
|
|
|
|
|
|
2016-03-11 23:26:50 +00:00
|
|
|
animations.push_back( animated_mystery_bloc.animate(
|
|
|
|
200, // delai entre-frames
|
|
|
|
SPRITE_ANIM_INFINITE // FLAGS
|
|
|
|
) );
|
|
|
|
delete animations[0]; // On le supprime ensuite
|
2016-03-11 15:17:57 +00:00
|
|
|
|
2016-03-11 23:26:50 +00:00
|
|
|
|
|
|
|
animations.push_back( animated_green_shell.animate(
|
|
|
|
100, // delai entre-frames
|
|
|
|
SPRITE_ANIM_INFINITE // FLAGS
|
|
|
|
) );
|
|
|
|
delete animations[1]; // On le supprime ensuite
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
animations.push_back( animated_red_shell.animate(
|
|
|
|
100, // delai entre-frames
|
|
|
|
SPRITE_ANIM_INFINITE // FLAGS
|
|
|
|
) );
|
2016-03-11 23:26:50 +00:00
|
|
|
delete animations[2]; // On le supprime ensuite
|
2016-03-11 15:17:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [n-1] Boucle infinie
|
|
|
|
=========================================================*/
|
2016-03-11 23:10:38 +00:00
|
|
|
mgr->update();
|
2016-03-11 15:17:57 +00:00
|
|
|
mgr->manageFps(FPS);
|
|
|
|
running = true;
|
|
|
|
while(running){
|
2016-03-11 23:10:38 +00:00
|
|
|
|
2016-03-11 15:17:57 +00:00
|
|
|
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;
|
|
|
|
}
|