/* [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} ); _defaultrect = _viewport; _lastjump = SDL_GetTicks(); _jumps = 0; _active = true; } /* [JUMP] Animation d'activation (quand saut) =========================================================*/ void xMarioMysteryBloc::jump(){ if( !this->active() ) return; if( _defaultrect.y == _viewport.y && SDL_GetTicks()-_lastjump > 300 ){ _viewport.x = _defaultrect.x - _defaultrect.w*.1/2; _viewport.y = _defaultrect.y-10 - _defaultrect.h*.1/2; _viewport.w = _defaultrect.w * 1.1; _viewport.h = _defaultrect.h * 1.1; this->move(_viewport); _lastjump = SDL_GetTicks(); _jumps++; if( _jumps >= 6 ) this->active(false); } } /* [UNJUMP] Animation d'activation (quand saut) =========================================================*/ void xMarioMysteryBloc::unjump(){ if( _defaultrect.y != _viewport.y && SDL_GetTicks()-_lastjump > 100 ){ _viewport.x = _defaultrect.x; _viewport.y = _defaultrect.y; _viewport.w = _defaultrect.w; _viewport.h = _defaultrect.h; this->move(_viewport); _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 ){ _frames.clear(); // for( int i = 0 ; i < _frames.size() ; i++ ) // _frames.erase(_frames.begin()+i); this->pull(); 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} ); // On ajoute au rendu this->start(_timeout, _flags); }else{ _frames.clear(); // for( int i = 0 ; i < _frames.size() ; i++ ) // _frames.erase(_frames.begin()+i); this->stop(); this->addFrame( (SDL_Rect){0, 64, 16, 16} ); 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); } }