2016-03-14 18:28:18 +00:00
|
|
|
/* [CONSTRUCTOR] Construction d'un xMarioBrick
|
|
|
|
=========================================================*/
|
2016-03-16 11:08:22 +00:00
|
|
|
xMarioBrick::xMarioBrick(xManager *m, int x, int y, int nb)
|
2016-03-14 18:28:18 +00:00
|
|
|
: xSprite(
|
|
|
|
m,
|
|
|
|
"src/blocs.png"
|
|
|
|
){
|
|
|
|
_manager = m;
|
|
|
|
|
|
|
|
// 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
|
|
|
|
);
|
|
|
|
|
2016-03-16 11:08:22 +00:00
|
|
|
_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;
|
|
|
|
|
2016-03-16 12:56:52 +00:00
|
|
|
|
2016-03-16 11:08:22 +00:00
|
|
|
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){
|
|
|
|
_active = active;
|
|
|
|
|
|
|
|
// actif, on affiche
|
|
|
|
if( active )
|
|
|
|
this->push(_index);
|
|
|
|
// sinon on enleve
|
|
|
|
else
|
|
|
|
this->pull();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [ONCOLLIDE] Gestion des collisions
|
|
|
|
=========================================================*/
|
|
|
|
void xMarioBrick::onCollide(vector<int> from, xSprite* by){
|
|
|
|
/* (1) Saut de mario */
|
2016-03-16 12:56:52 +00:00
|
|
|
if( by->getType() == "Mario" && from[1] == -1 )
|
|
|
|
this->jump();
|
2016-03-14 18:28:18 +00:00
|
|
|
}
|