- [x] Gestion du unjump() auto pour les blocs cassables

- [x] Classe parente pour blocs cassables xBreakableBloc
This commit is contained in:
xdrm-brackets 2016-03-17 10:17:21 +01:00
parent 3251cb2b6f
commit 57c029aadd
18 changed files with 652 additions and 319 deletions

View File

@ -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

BIN
SDL#4/exe

Binary file not shown.

View File

@ -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
}

Binary file not shown.

BIN
SDL#4/src/koopa.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

BIN
SDL#4/src/koopa.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 MiB

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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<int> from, xSprite* by){
/* (1) Saut de mario */
if( by->getType() == "Mario" && from[1] == -1 )
this->jump();
}

View File

@ -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<int> 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

View File

@ -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<int> from, xSprite* by){
/* (1) Saut de mario */
if( by->getType() == "Mario" && from[1] == -1 )
this->jump();
}

View File

@ -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<int> 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

View File

@ -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<int> from, xSprite* by){
/* (1) Saut de mario */
if( by->getType() == "Mario" && from[1] == -1 )
this->jump();
}

View File

@ -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<int> 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

View File

@ -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<int> 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);
}
}

View File

@ -6,6 +6,19 @@
public:
xMarioGreenShell(xManager *manager, int x, int y); // Spritesheet avec taille de chaque sprite
void onCollide(vector<int> 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

View File

@ -343,11 +343,5 @@ void xMarioMario::turn(){
/* [ONCOLLIDE] Gestion des collisions
=========================================================*/
void xMarioMario::onCollide(vector<int> 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();
}