diff --git a/SDL#4/err.log b/SDL#4/err.log index ed2c253..153be36 100644 --- a/SDL#4/err.log +++ b/SDL#4/err.log @@ -165,26 +165,6 @@ Grass collided with Mario from bottom Grass collided with Mario from bottom Grass collided with Mario from bottom Grass collided with Mario from bottom -Grass collided with Mario from right -bottom -Grass collided with Mario from right -bottom -Grass collided with Mario from right -bottom -Grass collided with Mario from right -bottom -Grass collided with Mario from right -bottom -Grass collided with Mario from right -bottom -Grass collided with Mario from right -bottom -Grass collided with Mario from right -bottom -Grass collided with Mario from right -bottom -Grass collided with Mario from right -bottom Grass collided with Mario from bottom Grass collided with Mario from bottom Grass collided with Mario from bottom @@ -196,23 +176,26 @@ Grass collided with Mario from bottom Grass collided with Mario from bottom Grass collided with Mario from bottom Grass collided with Mario from bottom -Grass collided with Mario from right +Grass collided with Mario from bottom +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left +bottom +Grass collided with Mario from left bottom Grass collided with Mario from bottom Grass collided with Mario from bottom @@ -226,57 +209,25 @@ Grass collided with Mario from bottom Grass collided with Mario from bottom Grass collided with Mario from bottom Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom -Grass collided with Mario from right +Grass collided with Mario from left bottom Grass collided with Mario from bottom Grass collided with Mario from bottom @@ -289,6 +240,29 @@ Grass collided with Mario from bottom Grass collided with Mario from bottom Grass collided with Mario from bottom Grass collided with Mario from bottom +Grass collided with Mario from left +bottom +Grass collided with Mario from left +bottom +Grass collided with Mario from left +bottom +Grass collided with Mario from left +bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom Grass collided with Mario from bottom Grass collided with Mario from bottom Grass collided with Mario from bottom @@ -401,8 +375,37 @@ Grass collided with Mario from bottom Grass collided with Mario from bottom Grass collided with Mario from bottom Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom Grass collided with Mario from left -Grass collided with Mario from left bottom Grass collided with Mario from left bottom @@ -422,32 +425,308 @@ Grass collided with Mario from left bottom Grass collided with Mario from left bottom -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW -mario collide with WINDOW +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from left +bottom +Grass collided with Mario from left +bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom +Grass collided with Mario from bottom diff --git a/SDL#4/exe b/SDL#4/exe index 8e05e2e..6d7871d 100755 Binary files a/SDL#4/exe and b/SDL#4/exe differ diff --git a/SDL#4/main.cpp b/SDL#4/main.cpp index 750a7dd..1bff3e5 100644 --- a/SDL#4/main.cpp +++ b/SDL#4/main.cpp @@ -49,10 +49,10 @@ int main(int argc, char* argv[]) { // On cree une coquille verte xMarioGreenShell gs(mgr, 5, 20-3); gs.push("green-sheel"); - gs.start(100, SPRITE_ANIM_INFINITE); + gs.start(80, SPRITE_ANIM_INFINITE); // On cree une brique - xMarioBrick mbr1(mgr, 4, 20-6, 1); // 1 saut + xMarioBrick mbr1(mgr, 4, 20-6, 10); // 10 sauts mbr1.push("brick1"); // On cree un bloc mystere @@ -94,9 +94,9 @@ int main(int argc, char* argv[]) { // Gestion des evenements SDL_Event event; - mgr->attachEvent(SDL_KEYDOWN, &keydownEventHandler); - mgr->attachEvent(SDL_KEYUP, &keyupEventHandler); - mgr->attachEvent(SDL_QUIT, &quitEventHandler); + mgr->attachEvent(SDL_KEYDOWN, &keydownEventHandler); // Evenement appui clavier + mgr->attachEvent(SDL_KEYUP, &keyupEventHandler); // Evenement relache clavier + mgr->attachEvent(SDL_QUIT, &quitEventHandler); // Evenement QUITTER mgr->debug(); @@ -112,41 +112,17 @@ int main(int argc, char* argv[]) { mgr->state = 0; while(mgr->state==0){ - // Gestion des evenements while( SDL_PollEvent(&event) != 0 ) mgr->manageEvents(&event); - // Gestion de la gravite - // if( !mario->onFloor() && SDL_GetTicks() % 10 < 5 ) - // mario->velocity(0, 1.0); - - - // Deplacement + // Deplacement de Mario mario->moveFromVelocity(); - - - // if( mgr->hit("brick1", 0, 1) )mbr1.jump(); - mbr1.unjump(); - // if( mgr->hit("brick2", 0, 1) ) mbr2.jump(); - mbr2.unjump(); - - - // if( mgr->hit("mystery-bloc", 0, 1) )mb.jump(); - mb.unjump(); - - // if( mgr->hit("mystery-bloc2", 0, 1) )mb1.jump(); - mb1.unjump(); - - // if( mgr->hit("mystery-bloc3", 0, 1) )mb2.jump(); - mb2.unjump(); - - // if( mgr->hit("mystery-bloc4", 0, 1) ) mb3.jump(); - mb3.unjump(); - + // Mise a jour du rendu mgr->manageFps(); // Gestion des FPS (speed) mgr->update(); // Mise a jour du rendu + } @@ -158,7 +134,7 @@ int main(int argc, char* argv[]) { mgr->setImage("src/game_over.jpg"); // Image GAME OVER mgr->update(); // Mise a jour du rendu - sleep(3); // Attente 3 sec + usleep(100*1000); // Attente 3 sec } diff --git a/SDL#4/main.o b/SDL#4/main.o index 067c898..a1e876c 100644 Binary files a/SDL#4/main.o and b/SDL#4/main.o differ diff --git a/SDL#4/src/koopa.jpg b/SDL#4/src/koopa.jpg new file mode 100644 index 0000000..83a6d68 Binary files /dev/null and b/SDL#4/src/koopa.jpg differ diff --git a/SDL#4/src/koopa.png b/SDL#4/src/koopa.png new file mode 100644 index 0000000..84671ee Binary files /dev/null and b/SDL#4/src/koopa.png differ diff --git a/SDL#4/todo.md b/SDL#4/todo.md index 87fddfa..06ed37f 100644 --- a/SDL#4/todo.md +++ b/SDL#4/todo.md @@ -5,9 +5,15 @@ A FAIRE EN COURS ======== +- [x] Refaire texture xGreenShell + - [ ] Gestion arret animation + reprise (switch) +- [ ] Gestion du deplacement xGreenShell +- [ ] Erreur saut infini mario FAIT ==== +- [x] Gestion du unjump() auto pour les blocs cassables + - [x] Classe parente pour blocs cassables xBreakableBloc - [x] Erreur accrochage quand saut sur un coin - [x] Game Over quand on tombe - [x] Gestion des briques cassables quand collision diff --git a/SDL#4/xMario.cpp b/SDL#4/xMario.cpp index 6f17b25..5b1f479 100644 --- a/SDL#4/xMario.cpp +++ b/SDL#4/xMario.cpp @@ -11,6 +11,7 @@ #include "xMario/xMarioGreenShell.cpp" #include "xMario/xMarioBloc.cpp" + #include "xMario/BreakableBloc/xMarioBreakableBloc.cpp" #include "xMario/BreakableBloc/xMarioMysteryBloc.cpp" #include "xMario/BreakableBloc/xMarioBrick.cpp" diff --git a/SDL#4/xMario.h b/SDL#4/xMario.h index ae6d06a..28cb453 100644 --- a/SDL#4/xMario.h +++ b/SDL#4/xMario.h @@ -18,6 +18,7 @@ #include "xMario/xMarioGreenShell.h" #include "xMario/xMarioBloc.h" + #include "xMario/BreakableBloc/xMarioBreakableBloc.h" #include "xMario/BreakableBloc/xMarioMysteryBloc.h" #include "xMario/BreakableBloc/xMarioBrick.h" diff --git a/SDL#4/xMario/BreakableBloc/xMarioBreakableBloc.cpp b/SDL#4/xMario/BreakableBloc/xMarioBreakableBloc.cpp new file mode 100644 index 0000000..90ebb74 --- /dev/null +++ b/SDL#4/xMario/BreakableBloc/xMarioBreakableBloc.cpp @@ -0,0 +1,103 @@ +/* [CONSTRUCTOR] Construction d'un xMarioGreenShell +=========================================================*/ +xMarioBreakableBloc::xMarioBreakableBloc(xManager *m, const char *url, int x, int y, int nb) +: xSpriteAnimation( + m, + url, + (SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE} +){ + this->setType("breakable-bloc"); + + + /* (1) On initialise les attributs */ + _auto_unjump = NULL; + _defaultrect = _dst; + _lastjump = SDL_GetTicks(); + _jumps = 0; + _active = true; + _nb_jumps = nb; +} + + + + +/* [ANIMATIONTHREAD] Gestion de la fin de l'animation +=========================================================*/ +void xUnjumpProcess(xMarioBreakableBloc *mb){ + usleep(1000 * 100); // 100ms + mb->unjump(); +} + + + + + + +/* [JUMP] Animation d'activation (quand saut) +=========================================================*/ +void xMarioBreakableBloc::jump(){ + if( !this->active() ) + return; + + + if( _defaultrect.y == _dst.y && SDL_GetTicks()-_lastjump > 100 ){ + + this->move(0, -5); + + // Gestion du thread pour fin d'animation + if( _auto_unjump != NULL) + delete _auto_unjump; + + _auto_unjump = NULL; + _auto_unjump = new thread(xUnjumpProcess, this); + _auto_unjump->detach(); + + + _lastjump = SDL_GetTicks(); + + _jumps++; + + if( _jumps >= _nb_jumps ) + this->active(false); + } + +} + + +/* [UNJUMP] Animation d'activation (quand saut) +=========================================================*/ +void xMarioBreakableBloc::unjump(){ + if( (_defaultrect.y-5) == _dst.y ){ + + this->move(0, 5); + + _lastjump = SDL_GetTicks(); + } +} + + + +/* [ACTIVE] Retourne l'etat du bouton +=========================================================*/ +bool xMarioBreakableBloc::active(){ + return _active; +} + + + +/* [ACTIVE] Gestion du caractere "actif" du bouton +=========================================================*/ +void xMarioBreakableBloc::active(bool active){ + _active = active; +} + + + + +/* [ONCOLLIDE] Gestion des collisions +=========================================================*/ +void xMarioBreakableBloc::onCollide(vector from, xSprite* by){ + /* (1) Saut de mario */ + if( by->getType() == "Mario" && from[1] == -1 ) + this->jump(); +} \ No newline at end of file diff --git a/SDL#4/xMario/BreakableBloc/xMarioBreakableBloc.h b/SDL#4/xMario/BreakableBloc/xMarioBreakableBloc.h new file mode 100644 index 0000000..2505f12 --- /dev/null +++ b/SDL#4/xMario/BreakableBloc/xMarioBreakableBloc.h @@ -0,0 +1,34 @@ +#ifndef DEF_XMARIOBREAKABLEBLOC_H + + #define DEF_XMARIOBREAKABLEBLOC_H + + class xMarioBreakableBloc : public xSpriteAnimation{ + + public: + xMarioBreakableBloc(xManager *manager, const char *url, int x, int y, int nb=1); // Spritesheet avec taille de chaque sprite + + // Surcharge parent + void onCollide(vector from, xSprite* by); + + + void jump(); // Effectue l'animation d'activation (debut/saut) + void unjump(); // Effectue l'animation d'activation (fin) + + bool active(); // Retourne si le bloc est actif ou non + virtual void active(bool active); // Active ou non le bloc + + protected: + bool _active; + int _jumps; + Uint32 _lastjump; + SDL_Rect _defaultrect; + + int _nb_jumps; // nombre de coups avant de casser + + // Gestion de la fin d'animation + thread *_auto_unjump; + friend void xUnjumpProcess(xMarioBreakableBloc *mb); + + }; + +#endif \ No newline at end of file diff --git a/SDL#4/xMario/BreakableBloc/xMarioBrick.cpp b/SDL#4/xMario/BreakableBloc/xMarioBrick.cpp index b26dff0..a7f4655 100644 --- a/SDL#4/xMario/BreakableBloc/xMarioBrick.cpp +++ b/SDL#4/xMario/BreakableBloc/xMarioBrick.cpp @@ -1,75 +1,21 @@ /* [CONSTRUCTOR] Construction d'un xMarioBrick =========================================================*/ xMarioBrick::xMarioBrick(xManager *m, int x, int y, int nb) -: xSprite( +: xMarioBreakableBloc( m, - "src/blocs.png" + "src/blocs.png", + x, + y, + nb ){ - _manager = m; + this->setType("brick"); - // Note: le rect correspond a un nombre de bloc - // On convertit le tout en blocs reels - int xReal = x * BLOC_SIZE; - int yReal = y * BLOC_SIZE; - - this->dimensions( - (SDL_Rect){xReal, yReal, BLOC_SIZE, BLOC_SIZE}, // On definit le viewport - (SDL_Rect){136, 0, 16, 16} // On definit le clip - ); + // On definit la frame de l'animation + this->addFrame( (SDL_Rect){136, 0, 16, 16} ); + this->addFrame( (SDL_Rect){136, 0, 16, 16} ); - _defaultrect = _dst; - _lastjump = SDL_GetTicks(); - _jumps = 0; - _active = true; - _nb_jumps = nb; } - - - - -/* [JUMP] Animation d'activation (quand saut) -=========================================================*/ -void xMarioBrick::jump(){ - if( !this->active() ) - return; - - - if( _defaultrect.y == _dst.y && SDL_GetTicks()-_lastjump > 100 ){ - - this->move(0, -2); - - _lastjump = SDL_GetTicks(); - - _jumps++; - - if( _jumps >= _nb_jumps ) - this->active(false); - } -} - - -/* [UNJUMP] Animation d'activation (quand saut) -=========================================================*/ -void xMarioBrick::unjump(){ - if( (_defaultrect.y-2) == _dst.y && SDL_GetTicks()-_lastjump > 100 ){ - - this->move(0, 2); - - _lastjump = SDL_GetTicks(); - } -} - - - -/* [ACTIVE] Retourne l'etat du bouton -=========================================================*/ -bool xMarioBrick::active(){ - return _active; -} - - - /* [ACTIVE] Gestion du caractere "actif" du bouton =========================================================*/ void xMarioBrick::active(bool active){ @@ -82,17 +28,4 @@ void xMarioBrick::active(bool active){ else this->pull(); - - -} - - - - -/* [ONCOLLIDE] Gestion des collisions -=========================================================*/ -void xMarioBrick::onCollide(vector from, xSprite* by){ - /* (1) Saut de mario */ - if( by->getType() == "Mario" && from[1] == -1 ) - this->jump(); } \ No newline at end of file diff --git a/SDL#4/xMario/BreakableBloc/xMarioBrick.h b/SDL#4/xMario/BreakableBloc/xMarioBrick.h index 9e31d35..0ee7f14 100644 --- a/SDL#4/xMario/BreakableBloc/xMarioBrick.h +++ b/SDL#4/xMario/BreakableBloc/xMarioBrick.h @@ -4,29 +4,13 @@ /* [DEF] Definition de la classe =========================================================*/ - class xMarioBrick : public xSprite{ + class xMarioBrick : public xMarioBreakableBloc{ public: xMarioBrick(xManager *m, int x, int y, int nb=1); - // Surcharge parent - void onCollide(vector from, xSprite* by); - - - void jump(); // Effectue l'animation d'activation - void unjump(); // Effectue l'animation d'activation - - bool active(); // Retourne si le bloc est actif ou non void active(bool active); // Active ou non le bloc - private: - bool _active; - int _jumps; - Uint32 _lastjump; - SDL_Rect _defaultrect; - - int _nb_jumps; // nombre de coups avant de casser - }; #endif \ No newline at end of file diff --git a/SDL#4/xMario/BreakableBloc/xMarioMysteryBloc.cpp b/SDL#4/xMario/BreakableBloc/xMarioMysteryBloc.cpp index c43ca6c..b90e919 100644 --- a/SDL#4/xMario/BreakableBloc/xMarioMysteryBloc.cpp +++ b/SDL#4/xMario/BreakableBloc/xMarioMysteryBloc.cpp @@ -1,10 +1,12 @@ /* [CONSTRUCTOR] Construction d'un xMarioGreenShell =========================================================*/ xMarioMysteryBloc::xMarioMysteryBloc(xManager *m, int x, int y, int nb) -: xSpriteAnimation( +: xMarioBreakableBloc( m, "src/myst_bloc.png", - (SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE} + x, + y, + nb ){ this->setType("mystery-bloc"); @@ -13,61 +15,11 @@ xMarioMysteryBloc::xMarioMysteryBloc(xManager *m, int x, int y, int nb) this->addFrame( (SDL_Rect){0, 16, 16, 16} ); this->addFrame( (SDL_Rect){0, 32, 16, 16} ); this->addFrame( (SDL_Rect){0, 48, 16, 16} ); - - _defaultrect = _dst; - _lastjump = SDL_GetTicks(); - _jumps = 0; - _active = true; - _nb_jumps = nb; } - -/* [JUMP] Animation d'activation (quand saut) -=========================================================*/ -void xMarioMysteryBloc::jump(){ - if( !this->active() ) - return; - - - if( _defaultrect.y == _dst.y && SDL_GetTicks()-_lastjump > 100 ){ - - this->move(0, -5); - - _lastjump = SDL_GetTicks(); - - _jumps++; - - if( _jumps >= _nb_jumps ) - this->active(false); - } - -} - - -/* [UNJUMP] Animation d'activation (quand saut) -=========================================================*/ -void xMarioMysteryBloc::unjump(){ - if( (_defaultrect.y-5) == _dst.y && SDL_GetTicks()-_lastjump > 100 ){ - - this->move(0, 5); - - _lastjump = SDL_GetTicks(); - } -} - - - -/* [ACTIVE] Retourne l'etat du bouton -=========================================================*/ -bool xMarioMysteryBloc::active(){ - return _active; -} - - - /* [ACTIVE] Gestion du caractere "actif" du bouton =========================================================*/ void xMarioMysteryBloc::active(bool active){ @@ -105,15 +57,4 @@ void xMarioMysteryBloc::active(bool active){ } -} - - - - -/* [ONCOLLIDE] Gestion des collisions -=========================================================*/ -void xMarioMysteryBloc::onCollide(vector from, xSprite* by){ - /* (1) Saut de mario */ - if( by->getType() == "Mario" && from[1] == -1 ) - this->jump(); } \ No newline at end of file diff --git a/SDL#4/xMario/BreakableBloc/xMarioMysteryBloc.h b/SDL#4/xMario/BreakableBloc/xMarioMysteryBloc.h index 9fb6a63..0bc1659 100644 --- a/SDL#4/xMario/BreakableBloc/xMarioMysteryBloc.h +++ b/SDL#4/xMario/BreakableBloc/xMarioMysteryBloc.h @@ -2,29 +2,13 @@ #define DEF_XMARIOMYSTERYBLOC_H - class xMarioMysteryBloc : public xSpriteAnimation{ + class xMarioMysteryBloc : public xMarioBreakableBloc{ public: xMarioMysteryBloc(xManager *manager, int x, int y, int nb=1); // Spritesheet avec taille de chaque sprite - // Surcharge parent - void onCollide(vector from, xSprite* by); - - - void jump(); // Effectue l'animation d'activation - void unjump(); // Effectue l'animation d'activation - - bool active(); // Retourne si le bloc est actif ou non void active(bool active); // Active ou non le bloc - private: - bool _active; - int _jumps; - Uint32 _lastjump; - SDL_Rect _defaultrect; - - int _nb_jumps; // nombre de coups avant de casser - }; #endif \ No newline at end of file diff --git a/SDL#4/xMario/xMarioGreenShell.cpp b/SDL#4/xMario/xMarioGreenShell.cpp index f699195..ec9cdfa 100644 --- a/SDL#4/xMario/xMarioGreenShell.cpp +++ b/SDL#4/xMario/xMarioGreenShell.cpp @@ -3,7 +3,7 @@ xMarioGreenShell::xMarioGreenShell(xManager *m, int x, int y) : xSpriteAnimation( m, - "src/mario_crop.png", + "src/koopa.png", (SDL_Rect){ (int)( BLOC_SIZE*x+BLOC_SIZE*.1 ), (int)( BLOC_SIZE*y+BLOC_SIZE*.3 ), @@ -11,11 +11,95 @@ xMarioGreenShell::xMarioGreenShell(xManager *m, int x, int y) (int)( BLOC_SIZE*.7 ) } ){ - _type = "green-shell"; + this->setType("green-shell"); + _active = false; + _intouch = false; /* (2) On definit les clip de chaque frame */ - this->addFrame( (SDL_Rect){79, 213, 16, 16} ); - this->addFrame( (SDL_Rect){98, 213, 16, 16} ); - this->addFrame( (SDL_Rect){116, 213, 16, 16} ); - this->addFrame( (SDL_Rect){135, 213, 16, 16} ); + this->addFrame( (SDL_Rect){62, 90, 16, 15} ); + this->addFrame( (SDL_Rect){62, 90, 16, 15} ); + this->addFrame( (SDL_Rect){62, 90, 16, 15} ); + this->addFrame( (SDL_Rect){62, 90, 16, 15} ); +} + + + + + +/* [ACTIVE] Retourne l'etat du bouton +=========================================================*/ +bool xMarioGreenShell::active(){ + return _active; +} + + + +/* [ACTIVE] Gestion du caractere "actif" du bouton +=========================================================*/ +void xMarioGreenShell::active(bool active){ + _active = active; + + + if( active ){ + + + this->pull(); + this->clear(); + + + this->addFrame( (SDL_Rect){62, 90, 16, 15} ); + this->addFrame( (SDL_Rect){83, 90, 16, 15} ); + this->addFrame( (SDL_Rect){104, 90, 16, 15} ); + this->addFrame( (SDL_Rect){125, 90, 16, 15} ); + + // On ajoute au rendu + this->push(_index); + + }else{ + + this->pull(); + this->clear(); + + this->addFrame( (SDL_Rect){62, 90, 16, 15} ); + this->addFrame( (SDL_Rect){62, 90, 16, 15} ); + this->addFrame( (SDL_Rect){62, 90, 16, 15} ); + this->addFrame( (SDL_Rect){62, 90, 16, 15} ); + + // On ajoute au rendu + this->push(_index); + + } + + +} + + + + +/* [ONCOLLIDE] Gestion des collisions +=========================================================*/ +void xMarioGreenShell::onCollide(vector from, xSprite* by){ + /* (1) Mario par le cote */ + if( by->getType() == "Mario" && from[0] != 0 && !_intouch ){ + + // si en mvt + if( this->active() ){ + this->manager()->state = 2; // mario meurt + + // si immobile, on met en mvt + }else{ + this->active(true); // sinon on fait tourner + _intouch = true; + } + + } + + + /* (2) Mario par le haut */ + if( by->getType() == "Mario" && from[1] != -1 ){ + if( !this->active() ) // a l'arret, on met en mvt + this->active(true); + else // si en mouvement, met a l'arret + this->active(false); + } } \ No newline at end of file diff --git a/SDL#4/xMario/xMarioGreenShell.h b/SDL#4/xMario/xMarioGreenShell.h index dce55a3..1cbd40c 100644 --- a/SDL#4/xMario/xMarioGreenShell.h +++ b/SDL#4/xMario/xMarioGreenShell.h @@ -6,6 +6,19 @@ public: xMarioGreenShell(xManager *manager, int x, int y); // Spritesheet avec taille de chaque sprite + + void onCollide(vector from, xSprite* by); + + + + + bool active(); // Retourne si le bloc est actif ou non + void active(bool active); // Active ou non le bloc + + private: + bool _active; + bool _intouch; + }; #endif \ No newline at end of file diff --git a/SDL#4/xMario/xMarioMario.cpp b/SDL#4/xMario/xMarioMario.cpp index ea6491a..42851de 100644 --- a/SDL#4/xMario/xMarioMario.cpp +++ b/SDL#4/xMario/xMarioMario.cpp @@ -343,11 +343,5 @@ void xMarioMario::turn(){ /* [ONCOLLIDE] Gestion des collisions =========================================================*/ void xMarioMario::onCollide(vector from, xSprite* by){ - /* (1) Mort par carapace */ - if( by->getType() == "green-shell" && from[0] != 0 ) - cout << "MORT" << endl; - /* (2) Casse la carapace */ - if( by->getType() == "green-shell" && from[1] == -1 ) - by->pull(); } \ No newline at end of file