174 lines
3.7 KiB
C++
174 lines
3.7 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
|
||
|
=========================================================*/
|
||
|
bool bgLoaded = mgr->setBackground(255, 255, 255);
|
||
|
cout << "BG: " << bgLoaded << endl;
|
||
|
// bool imageLoaded = 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(
|
||
|
white,
|
||
|
(SDL_Rect){0, 0, 20, 20}
|
||
|
);
|
||
|
|
||
|
Sprite *gs_background = new Sprite(
|
||
|
white,
|
||
|
(SDL_Rect){100, 0, 20, 20}
|
||
|
);
|
||
|
|
||
|
Sprite *rs_background = new Sprite(
|
||
|
white,
|
||
|
(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(
|
||
|
"src/mario_crop.png",
|
||
|
(SDL_Rect){0, 0, 20, 20},
|
||
|
(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(
|
||
|
"src/mario_crop.png",
|
||
|
(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(
|
||
|
"src/mario_crop.png",
|
||
|
(SDL_Rect){150, 0, 20, 20},
|
||
|
(SDL_Rect){2+19*i, 11*19, 20, 20}
|
||
|
) );
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
// TEST
|
||
|
int red[] = {255, 0, 0};
|
||
|
int pink[] = {255, 0, 255};
|
||
|
SpriteGroup testgroup;
|
||
|
|
||
|
testgroup.add( new Sprite(
|
||
|
"src/mario_crop.png",
|
||
|
(SDL_Rect){150, 0, 20, 20},
|
||
|
(SDL_Rect){2+19*1, 11*19, 20, 20}
|
||
|
) );
|
||
|
|
||
|
testgroup.add( new Sprite(
|
||
|
pink,
|
||
|
(SDL_Rect){100, 0, 100, 100}
|
||
|
) );
|
||
|
|
||
|
// testgroup.appendTo(mgr);
|
||
|
testgroup.get(0)->appendTo(mgr);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/* [5] On lance les animation en parallele
|
||
|
=========================================================*/
|
||
|
vector<thread*> animations(0);
|
||
|
|
||
|
|
||
|
animations.push_back( animated_mystery_bloc.animate(
|
||
|
mgr, // rendu a mettre a jour
|
||
|
200, // delai entre-frames
|
||
|
SPRITE_ANIM_INFINITE // FLAGS
|
||
|
) );
|
||
|
delete animations[0]; // On le supprime ensuite
|
||
|
|
||
|
|
||
|
animations.push_back( animated_green_shell.animate(
|
||
|
mgr, // rendu a mettre a jour
|
||
|
100, // delai entre-frames
|
||
|
SPRITE_ANIM_INFINITE // FLAGS
|
||
|
) );
|
||
|
delete animations[1]; // On le supprime ensuite
|
||
|
|
||
|
|
||
|
animations.push_back( animated_red_shell.animate(
|
||
|
mgr, // rendu a mettre a jour
|
||
|
100, // delai entre-frames
|
||
|
SPRITE_ANIM_INFINITE // FLAGS
|
||
|
) );
|
||
|
delete animations[2]; // On le supprime ensuite
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/* [n-1] Boucle infinie
|
||
|
=========================================================*/
|
||
|
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;
|
||
|
}
|