- [x] Integrer pour xGreenShell
- [x] Gestion du deplacement xGreenShell
This commit is contained in:
parent
1bff71cae4
commit
8aab526d28
|
@ -104,7 +104,7 @@ int main(int argc, char* argv[]) {
|
|||
mario->moveFromVelocity();
|
||||
|
||||
// Deplacement coquille verte
|
||||
gs.autoMove();
|
||||
gs.moveFromVelocity();
|
||||
|
||||
// Mise a jour du rendu
|
||||
mgr->manageFps(); // Gestion des FPS (speed)
|
||||
|
|
BIN
SDL#4/main.o
BIN
SDL#4/main.o
Binary file not shown.
|
@ -7,7 +7,6 @@ EN COURS
|
|||
========
|
||||
- [x] Refaire texture xGreenShell
|
||||
- [ ] Gestion arret animation + reprise (switch)
|
||||
- [ ] Gestion du deplacement xGreenShell
|
||||
|
||||
- [ ] Verifier toute la trajectoire pour move()
|
||||
|
||||
|
@ -17,6 +16,9 @@ FAIT
|
|||
====
|
||||
- [x] Classe parente pour objets mobiles
|
||||
- [x] Integrer a xMario
|
||||
- [x] Integrer pour xGreenShell
|
||||
- [x] Gestion du deplacement xGreenShell
|
||||
|
||||
- [x] Gestion direction collision en fonction des verifs de collide()
|
||||
- [x] Erreur saut infini mario
|
||||
- [x] Erreur -> Gestion params velocite en fonction taille bloc
|
||||
|
|
|
@ -26,7 +26,7 @@ xMarioBloc::xMarioBloc(xManager *m, SDL_Rect rect){
|
|||
this->add( new xSprite(_manager, _spritesheet) );
|
||||
|
||||
// On definit le tyoe
|
||||
_sprites[index]->setType("Bloc");
|
||||
_sprites[index]->setType("bloc");
|
||||
|
||||
this->get(index)->dimensions(
|
||||
(SDL_Rect){BLOC_SIZE*x, BLOC_SIZE*y, BLOC_SIZE, BLOC_SIZE},
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
/* [CONSTRUCTOR] Construction d'un xMarioGreenShell
|
||||
=========================================================*/
|
||||
xMarioGreenShell::xMarioGreenShell(xManager *m, int x, int y)
|
||||
/* (1) Constructeur animation */
|
||||
: xSpriteAnimation(
|
||||
m,
|
||||
"src/koopa.png",
|
||||
|
@ -10,11 +11,22 @@ xMarioGreenShell::xMarioGreenShell(xManager *m, int x, int y)
|
|||
(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;
|
||||
_intouch = false;
|
||||
_way = false; // vers droite
|
||||
|
||||
|
||||
/* (2) On definit les clip de chaque frame */
|
||||
this->addFrame( (SDL_Rect){62, 90, 16, 15} );
|
||||
|
@ -27,15 +39,6 @@ xMarioGreenShell::xMarioGreenShell(xManager *m, int x, int y)
|
|||
|
||||
|
||||
|
||||
/* [AUTOMOVE] Gestion du mouvement
|
||||
=========================================================*/
|
||||
void xMarioGreenShell::autoMove(){
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* [ACTIVE] Retourne l'etat du bouton
|
||||
=========================================================*/
|
||||
bool xMarioGreenShell::active(){
|
||||
|
@ -86,30 +89,105 @@ void xMarioGreenShell::active(bool active){
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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<int> from, xSprite* by){
|
||||
void xMarioGreenShell::onCollide(vector<bool> from, xSprite* by){
|
||||
|
||||
/* (1) Mario par le cote */
|
||||
if( by->getType() == "Mario" && (from[0]||from[1]) && !_intouch ){
|
||||
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{
|
||||
}else
|
||||
this->active(true); // sinon on fait tourner
|
||||
_intouch = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* (2) Mario par le haut */
|
||||
if( by->getType() == "Mario" && from[2] ){
|
||||
if( !this->active() ) // a l'arret, on met en mvt
|
||||
if( !this->active() ){ // a l'arret, on met en mvt
|
||||
this->active(true);
|
||||
else // si en mouvement, met a l'arret
|
||||
|
||||
}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;
|
||||
}
|
|
@ -2,22 +2,32 @@
|
|||
|
||||
#define DEF_XMARIOGREENSHELL_H
|
||||
|
||||
class xMarioGreenShell : public xSpriteAnimation{
|
||||
class xMarioGreenShell : public xSpriteAnimation, public xMarioMobile{
|
||||
|
||||
public:
|
||||
xMarioGreenShell(xManager *manager, int x, int y); // Spritesheet avec taille de chaque sprite
|
||||
|
||||
void onCollide(vector<int> from, xSprite* by);
|
||||
// GETTERS
|
||||
bool onFloor(); // Si mario est sur le sol
|
||||
bool onWall(); // Si mario est contre un mur
|
||||
|
||||
// PROPAGATION AUX ENFANTS
|
||||
vector<int> spreadMove();
|
||||
void spreadTurn();
|
||||
void spreadUpdateVelocity();
|
||||
void spreadApplyGravity();
|
||||
|
||||
// Surcharge xSprite
|
||||
void onCollide(vector<bool> from, xSprite* by);
|
||||
|
||||
|
||||
void autoMove();
|
||||
|
||||
bool active(); // Retourne si le bloc est actif ou non
|
||||
void active(bool active); // Active ou non le bloc
|
||||
|
||||
private:
|
||||
bool _active;
|
||||
bool _intouch;
|
||||
bool _way;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -15,12 +15,12 @@ xMarioMario::xMarioMario(xManager *m, int x, int y)
|
|||
|
||||
/* (2) Constructeur objet mobile */
|
||||
xMarioMobile(
|
||||
.25, // gravite
|
||||
0.3125, 1.25, // multiplicateur
|
||||
0.05, .09375, // acceleration
|
||||
0.021875, .009375, // decceleration
|
||||
0.003125, .00625, // min
|
||||
0.3125, 3.125 // max
|
||||
0.25, // gravite
|
||||
10, 40, // multiplicateur
|
||||
1.6, 3, // acceleration
|
||||
0.7, 0.3, // decceleration
|
||||
0.1, 0.2, // min
|
||||
10, 100 // max
|
||||
){
|
||||
this->setType("Mario");
|
||||
|
||||
|
@ -58,11 +58,12 @@ bool xMarioMario::onWall(){
|
|||
|
||||
/* [SPREAD] Fonction a propager
|
||||
=========================================================*/
|
||||
vector<int> xMarioMario::spreadMove(int x, int y){
|
||||
return this->move(x, y);
|
||||
vector<int> xMarioMario::spreadMove(){
|
||||
return this->move(_velocity[0], _velocity[1]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void xMarioMario::spreadTurn(){
|
||||
/* (0) Variables utiles */
|
||||
bool left = _velocity[0] < 0; // si vers la gauche
|
||||
|
@ -236,6 +237,5 @@ void xMarioMario::spreadApplyGravity(){
|
|||
|
||||
/* [ONCOLLIDE] Gestion des collisions
|
||||
=========================================================*/
|
||||
void xMarioMario::onCollide(vector<int> from, xSprite* by){
|
||||
|
||||
void xMarioMario::onCollide(vector<bool> from, xSprite* by){
|
||||
}
|
|
@ -19,13 +19,13 @@
|
|||
bool onWall(); // Si mario est contre un mur
|
||||
|
||||
// PROPAGATION AUX ENFANTS
|
||||
vector<int> spreadMove(int x, int y);
|
||||
vector<int> spreadMove();
|
||||
void spreadTurn();
|
||||
void spreadUpdateVelocity();
|
||||
void spreadApplyGravity();
|
||||
|
||||
// Surcharge parent
|
||||
void onCollide(vector<int> from, xSprite* by);
|
||||
void onCollide(vector<bool> from, xSprite* by);
|
||||
|
||||
|
||||
// Gestion du suivi du deplacement
|
||||
|
|
|
@ -11,20 +11,20 @@ double maxx, double maxy){
|
|||
_gravity = BLOC_SIZE * gravity;
|
||||
|
||||
// Constantes de mouvement sur X
|
||||
_velocity[0] = BLOC_SIZE * 0.0;
|
||||
_mult[0] = BLOC_SIZE * multx;
|
||||
_dec[0] = BLOC_SIZE * decx;
|
||||
_acc[0] = BLOC_SIZE * accx;
|
||||
_min_vel[0] = BLOC_SIZE * minx;
|
||||
_max_vel[0] = BLOC_SIZE * maxx;
|
||||
_velocity[0] = 0.0;
|
||||
_mult[0] = multx;
|
||||
_dec[0] = decx;
|
||||
_acc[0] = accx;
|
||||
_min_vel[0] = minx;
|
||||
_max_vel[0] = maxx;
|
||||
|
||||
// Constantes de mouvement sur Y
|
||||
_velocity[1] = BLOC_SIZE * 0.0;
|
||||
_mult[1] = BLOC_SIZE * multy;
|
||||
_dec[1] = BLOC_SIZE * decy;
|
||||
_acc[1] = BLOC_SIZE * accy;
|
||||
_min_vel[1] = BLOC_SIZE * miny;
|
||||
_max_vel[1] = BLOC_SIZE * maxy;
|
||||
_velocity[1] = 0.0;
|
||||
_mult[1] = multy;
|
||||
_dec[1] = decy;
|
||||
_acc[1] = accy;
|
||||
_min_vel[1] = miny;
|
||||
_max_vel[1] = maxy;
|
||||
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ double maxx, double maxy){
|
|||
void xMarioMobile::moveFromVelocity(){
|
||||
|
||||
/* (1) Si aucune collision, on deplace */
|
||||
vector<int> after = this->spreadMove(_velocity[0], _velocity[1]);
|
||||
vector<int> after = this->spreadMove();
|
||||
|
||||
/* (2) On modifie la velocite en fonction des collisions */
|
||||
_velocity[0] = (double) after[0];
|
||||
|
@ -134,7 +134,7 @@ void xMarioMobile::velocity(double x, double y){
|
|||
|
||||
/* [SPREAD] Fonction a propager
|
||||
=========================================================*/
|
||||
vector<int> xMarioMobile::spreadMove(int x, int y){
|
||||
vector<int> xMarioMobile::spreadMove(){
|
||||
// To implement in children
|
||||
cout << "PARENT" << endl;
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
void velocity(double x=0.0, double y=0.0); // Modification de velocite
|
||||
|
||||
// PROPAGATION AUX ENFANTS
|
||||
virtual vector<int> spreadMove(int x, int y);
|
||||
virtual vector<int> spreadMove();
|
||||
virtual void spreadTurn();
|
||||
virtual void spreadUpdateVelocity();
|
||||
virtual void spreadApplyGravity();
|
||||
|
|
Loading…
Reference in New Issue