lab.cpp/SDL#4/xMario/BreakableBloc/xMarioMysteryBloc.cpp

117 lines
2.4 KiB
C++
Raw Normal View History

/* [CONSTRUCTOR] Construction d'un xMarioGreenShell
=========================================================*/
xMarioMysteryBloc::xMarioMysteryBloc(xManager *m, int x, int y, int nb)
: xSpriteAnimation(
m,
"src/myst_bloc.png",
(SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE}
){
this->setType("mystery-bloc");
/* (2) On definit les clip de chaque frame */
this->addFrame( (SDL_Rect){0, 0, 16, 16} );
this->addFrame( (SDL_Rect){0, 16, 16, 16} );
this->addFrame( (SDL_Rect){0, 32, 16, 16} );
this->addFrame( (SDL_Rect){0, 48, 16, 16} );
2016-03-13 23:06:33 +00:00
_defaultrect = _dst;
2016-03-13 23:06:33 +00:00
_lastjump = SDL_GetTicks();
_jumps = 0;
_active = true;
_nb_jumps = nb;
2016-03-13 23:06:33 +00:00
}
/* [JUMP] Animation d'activation (quand saut)
=========================================================*/
void xMarioMysteryBloc::jump(){
if( !this->active() )
return;
if( _defaultrect.y == _dst.y && SDL_GetTicks()-_lastjump > 100 ){
2016-03-13 23:06:33 +00:00
this->move(0, -5);
2016-03-13 23:06:33 +00:00
_lastjump = SDL_GetTicks();
_jumps++;
if( _jumps >= _nb_jumps )
2016-03-13 23:06:33 +00:00
this->active(false);
}
}
/* [UNJUMP] Animation d'activation (quand saut)
=========================================================*/
void xMarioMysteryBloc::unjump(){
if( (_defaultrect.y-5) == _dst.y && SDL_GetTicks()-_lastjump > 100 ){
2016-03-13 23:06:33 +00:00
this->move(0, 5);
2016-03-13 23:06:33 +00:00
_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){
_active = active;
if( active ){
2016-03-14 12:14:35 +00:00
this->pull();
this->clear();
2016-03-14 12:14:35 +00:00
2016-03-13 23:06:33 +00:00
this->addFrame( (SDL_Rect){0, 0, 16, 16} );
this->addFrame( (SDL_Rect){0, 16, 16, 16} );
this->addFrame( (SDL_Rect){0, 32, 16, 16} );
this->addFrame( (SDL_Rect){0, 48, 16, 16} );
2016-03-14 12:14:35 +00:00
// On ajoute au rendu
this->push(_index);
2016-03-14 12:14:35 +00:00
2016-03-13 23:06:33 +00:00
}else{
this->pull();
this->clear();
2016-03-13 23:06:33 +00:00
this->addFrame( (SDL_Rect){0, 64, 16, 16} );
2016-03-14 12:14:35 +00:00
this->addFrame( (SDL_Rect){0, 64, 16, 16} );
this->addFrame( (SDL_Rect){0, 64, 16, 16} );
this->addFrame( (SDL_Rect){0, 64, 16, 16} );
// On ajoute au rendu
this->push(_index);
2016-03-13 23:06:33 +00:00
}
}
/* [ONCOLLIDE] Gestion des collisions
=========================================================*/
void xMarioMysteryBloc::onCollide(vector<int> from, xSprite* by){
/* (1) Saut de mario */
if( by->getType() == "Mario" && from[1] == 1 )
cout << "JUMP JUMP" << endl;
}