193 lines
3.7 KiB
C++
193 lines
3.7 KiB
C++
/* [CONSTRUCTOR] Construction d'un xMarioGreenShell
|
|
=========================================================*/
|
|
xMarioGreenShell::xMarioGreenShell(xManager *m, int x, int y)
|
|
/* (1) Constructeur animation */
|
|
: 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 )
|
|
}
|
|
),
|
|
|
|
/* (2) Constructeur objet mobile */
|
|
xMarioMobile(
|
|
.5, // gravite
|
|
15, 1, // multiplicateur
|
|
1, 1, // acceleration
|
|
.5, 1, // decceleration
|
|
.5, 1, // min
|
|
25, 100 // max
|
|
){
|
|
/* (1) Initialisation des attributs */
|
|
this->setType("green-shell");
|
|
_active = false;
|
|
_way = false; // vers droite
|
|
|
|
|
|
/* (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);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool xMarioGreenShell::onFloor(){
|
|
return _manager->hit((xSprite*)this, 0, 1);
|
|
}
|
|
|
|
|
|
|
|
bool xMarioGreenShell::onWall(){
|
|
return _manager->hit((xSprite*)this, 1, 0) || _manager->hit((xSprite*)this, -1, 0);
|
|
}
|
|
|
|
|
|
|
|
/* [ONCOLLIDE] Gestion des collisions
|
|
=========================================================*/
|
|
void xMarioGreenShell::onCollide(vector<bool> from, xSprite* by){
|
|
|
|
/* (1) Mario par le cote */
|
|
if( by->getType() == "Mario" && (from[0]||from[1]) ){
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
/* (2) Mario par le haut */
|
|
if( by->getType() == "Mario" && from[2] ){
|
|
if( !this->active() ){ // a l'arret, on met en mvt
|
|
this->active(true);
|
|
|
|
}else // si en mouvement, met a l'arret
|
|
this->active(false);
|
|
}
|
|
|
|
|
|
/* (3) Collision par cote -> rebond */
|
|
if( !from[2] && !from[3] ){ // si pas de collision haut ni bas
|
|
if( from[0] && !_way ){ _velocity[0] = 0; _way = true; } // par droite
|
|
else if( from[1] && _way ){ _velocity[0] = 0; _way = false; } // par gauche
|
|
}
|
|
|
|
// if( from[0] )
|
|
// cout << "[right] ";
|
|
// if( from[1] )
|
|
// cout << "[left] ";
|
|
// if( from[2] )
|
|
// cout << "[top] ";
|
|
// if( from[3] )
|
|
// cout << "[bottom] ";
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [SPREAD] Fonction a propager
|
|
=========================================================*/
|
|
vector<int> xMarioGreenShell::spreadMove(){
|
|
// cout << "velx: " << _velocity[0] << endl;
|
|
|
|
|
|
|
|
// si actif
|
|
if( this->active() )
|
|
if( _velocity[0] <= .5 || (_way!=_velocity[0]<0) )
|
|
this->velocity( _way ? -1 : 1, 0);
|
|
|
|
// si inactif
|
|
else
|
|
_velocity[0] = 0;
|
|
|
|
return this->move(_velocity[0], _velocity[1]);
|
|
}
|
|
|
|
|
|
void xMarioGreenShell::spreadTurn(){
|
|
}
|
|
|
|
|
|
void xMarioGreenShell::spreadUpdateVelocity(){
|
|
|
|
|
|
}
|
|
|
|
void xMarioGreenShell::spreadApplyGravity(){
|
|
if( !this->onFloor() )
|
|
_velocity[1] += _gravity;
|
|
} |