lab.cpp/SDL#4/xMario/xMarioGreenShell.cpp

105 lines
2.2 KiB
C++
Raw Normal View History

/* [CONSTRUCTOR] Construction d'un xMarioGreenShell
=========================================================*/
xMarioGreenShell::xMarioGreenShell(xManager *m, int x, int y)
: xSpriteAnimation(
m,
"src/koopa.png",
(SDL_Rect){
(int)( BLOC_SIZE*x+BLOC_SIZE*.1 ),
(int)( BLOC_SIZE*y+BLOC_SIZE*.3 ),
(int)( BLOC_SIZE*.8 ),
(int)( BLOC_SIZE*.7 )
}
){
this->setType("green-shell");
_active = false;
_intouch = false;
/* (2) On definit les clip de chaque frame */
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);
}
}