2016-03-13 13:53:39 +00:00
|
|
|
/* [CONSTRUCTOR] Construction d'un xMarioGreenShell
|
|
|
|
=========================================================*/
|
|
|
|
xMarioMysteryBloc::xMarioMysteryBloc(xManager *m, int x, int y)
|
|
|
|
: xSpriteAnimation(
|
|
|
|
m,
|
|
|
|
"src/myst_bloc.png",
|
|
|
|
(SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE}
|
|
|
|
){
|
|
|
|
|
|
|
|
/* (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
|
|
|
|
2016-03-14 18:28:18 +00:00
|
|
|
_defaultrect = _dst;
|
2016-03-13 23:06:33 +00:00
|
|
|
_lastjump = SDL_GetTicks();
|
|
|
|
_jumps = 0;
|
|
|
|
_active = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [JUMP] Animation d'activation (quand saut)
|
|
|
|
=========================================================*/
|
|
|
|
void xMarioMysteryBloc::jump(){
|
|
|
|
if( !this->active() )
|
|
|
|
return;
|
|
|
|
|
2016-03-14 18:28:18 +00:00
|
|
|
if( _defaultrect.y == _dst.y && SDL_GetTicks()-_lastjump > 300 ){
|
2016-03-13 23:06:33 +00:00
|
|
|
|
2016-03-14 18:28:18 +00:00
|
|
|
_dst.x = _defaultrect.x - _defaultrect.w*.1/2;
|
|
|
|
_dst.y = _defaultrect.y-10 - _defaultrect.h*.1/2;
|
|
|
|
_dst.w = _defaultrect.w * 1.1;
|
|
|
|
_dst.h = _defaultrect.h * 1.1;
|
2016-03-13 23:06:33 +00:00
|
|
|
|
2016-03-14 18:28:18 +00:00
|
|
|
this->move(_dst);
|
2016-03-13 23:06:33 +00:00
|
|
|
|
|
|
|
_lastjump = SDL_GetTicks();
|
|
|
|
|
|
|
|
_jumps++;
|
|
|
|
|
|
|
|
if( _jumps >= 6 )
|
|
|
|
this->active(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* [UNJUMP] Animation d'activation (quand saut)
|
|
|
|
=========================================================*/
|
|
|
|
void xMarioMysteryBloc::unjump(){
|
2016-03-14 18:28:18 +00:00
|
|
|
if( _defaultrect.y != _dst.y && SDL_GetTicks()-_lastjump > 100 ){
|
2016-03-13 23:06:33 +00:00
|
|
|
|
2016-03-14 18:28:18 +00:00
|
|
|
_dst.x = _defaultrect.x;
|
|
|
|
_dst.y = _defaultrect.y;
|
|
|
|
_dst.w = _defaultrect.w;
|
|
|
|
_dst.h = _defaultrect.h;
|
2016-03-13 23:06:33 +00:00
|
|
|
|
2016-03-14 18:28:18 +00:00
|
|
|
this->move(_dst);
|
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();
|
2016-03-14 18:28:18 +00:00
|
|
|
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
|
2016-03-14 15:10:21 +00:00
|
|
|
this->push(_index);
|
2016-03-14 12:14:35 +00:00
|
|
|
|
2016-03-13 23:06:33 +00:00
|
|
|
}else{
|
|
|
|
|
2016-03-14 15:10:21 +00:00
|
|
|
this->pull();
|
2016-03-14 18:28:18 +00:00
|
|
|
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
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-03-13 13:53:39 +00:00
|
|
|
}
|