- [x] Gestion du nombre de saut avant de casser Brick ou MysteryBloc
This commit is contained in:
parent
6f9d7dc40f
commit
a3c7418bb1
|
@ -53,28 +53,28 @@ int main(int argc, char* argv[]) {
|
|||
gs.start(100, SPRITE_ANIM_INFINITE);
|
||||
|
||||
// On cree une brique
|
||||
xMarioBrick mbr1(mgr, 4, 20-6);
|
||||
xMarioBrick mbr1(mgr, 4, 20-6, 1); // 1 saut
|
||||
mbr1.push("brick1");
|
||||
|
||||
// On cree un bloc mystere
|
||||
xMarioMysteryBloc mb(mgr, 5, 20-6);
|
||||
xMarioMysteryBloc mb(mgr, 5, 20-6, 2); // 2 sauts
|
||||
mb.push("mystery-bloc");
|
||||
mb.start(150, SPRITE_ANIM_INFINITE);
|
||||
|
||||
// On cree une brique
|
||||
xMarioBrick mbr2(mgr, 6, 20-6);
|
||||
xMarioBrick mbr2(mgr, 6, 20-6, 2); // 2 sauts
|
||||
mbr2.push("brick2");
|
||||
|
||||
|
||||
xMarioMysteryBloc mb1(mgr, 15, 20-6);
|
||||
xMarioMysteryBloc mb1(mgr, 15, 20-6, 1); // 1 saut
|
||||
mb1.push("mystery-bloc2");
|
||||
mb1.start(150, SPRITE_ANIM_INFINITE);
|
||||
|
||||
xMarioMysteryBloc mb2(mgr, 17, 20-5);
|
||||
xMarioMysteryBloc mb2(mgr, 17, 20-5, 1); // 1 saut
|
||||
mb2.push("mystery-bloc3");
|
||||
mb2.start(150, SPRITE_ANIM_INFINITE);
|
||||
|
||||
xMarioMysteryBloc mb3(mgr, 19, 20-4);
|
||||
xMarioMysteryBloc mb3(mgr, 19, 20-4, 6); // 6 sauts
|
||||
mb3.push("mystery-bloc4");
|
||||
mb3.start(150, SPRITE_ANIM_INFINITE);
|
||||
|
||||
|
@ -126,6 +126,13 @@ int main(int argc, char* argv[]) {
|
|||
mario->moveFromVelocity();
|
||||
|
||||
|
||||
|
||||
if( mgr->hit("brick1", 0, 1) ) mbr1.jump();
|
||||
else mbr1.unjump();
|
||||
if( mgr->hit("brick2", 0, 1) ) mbr2.jump();
|
||||
else mbr2.unjump();
|
||||
|
||||
|
||||
if( mgr->hit("mystery-bloc", 0, 1) ) mb.jump();
|
||||
else mb.unjump();
|
||||
|
||||
|
|
BIN
SDL#4/main.o
BIN
SDL#4/main.o
Binary file not shown.
|
@ -1,19 +1,20 @@
|
|||
A FAIRE
|
||||
=======
|
||||
|
||||
- [ ] Verifier toute la trajectoire pour move()
|
||||
- [x][ ] Gestion du saut unique ou double (limitation)
|
||||
|
||||
EN COURS
|
||||
========
|
||||
- [ ] Optimisation/Correction des collisions (hit + move)
|
||||
- [ ] Erreur de hit()
|
||||
- [x] Optimisation de la correction apres saut
|
||||
- [x] Correction du move qui fait friser parfois
|
||||
- [ ] Liberation memoire car lag
|
||||
- [...] Gestion sprites de mario en fonction mouvement
|
||||
|
||||
FAIT
|
||||
====
|
||||
- [x] Gestion du nombre de saut avant de casser Brick ou MysteryBloc
|
||||
- [x] Optimisation/Correction des collisions (hit + move)
|
||||
- [x] Erreur de hit() (gravity)
|
||||
- [x] Optimisation de la correction apres saut
|
||||
- [x] Correction du move qui fait friser parfois
|
||||
- [x] @pushsprites Ajout de Sprites et non uniquement de SDL_Textures au xManager
|
||||
- [x] Permettre a move() de renvoyer qqch
|
||||
- [x] Gestion velocite pour deplacement
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* [CONSTRUCTOR] Construction d'un xMarioBrick
|
||||
=========================================================*/
|
||||
xMarioBrick::xMarioBrick(xManager *m, int x, int y)
|
||||
xMarioBrick::xMarioBrick(xManager *m, int x, int y, int nb)
|
||||
: xSprite(
|
||||
m,
|
||||
"src/blocs.png"
|
||||
|
@ -17,4 +17,81 @@ xMarioBrick::xMarioBrick(xManager *m, int x, int y)
|
|||
(SDL_Rect){136, 0, 16, 16} // On definit le clip
|
||||
);
|
||||
|
||||
_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;
|
||||
|
||||
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 */
|
||||
if( by->getType() == "Mario" && from[1] == 1 )
|
||||
cout << "JUMP JUMP" << endl;
|
||||
}
|
|
@ -7,10 +7,25 @@
|
|||
class xMarioBrick : public xSprite{
|
||||
|
||||
public:
|
||||
xMarioBrick(xManager *m, int x, int y);
|
||||
xMarioBrick(xManager *m, int x, int y, int nb=1);
|
||||
|
||||
// Surcharge parent
|
||||
void onCollide(vector<int> from, xSprite* by);
|
||||
|
||||
|
||||
void jump(); // Effectue l'animation d'activation
|
||||
void unjump(); // Effectue l'animation d'activation
|
||||
|
||||
bool active(); // Retourne si le bloc est actif ou non
|
||||
void active(bool active); // Active ou non le bloc
|
||||
|
||||
private:
|
||||
xManager *_manager;
|
||||
bool _active;
|
||||
int _jumps;
|
||||
Uint32 _lastjump;
|
||||
SDL_Rect _defaultrect;
|
||||
|
||||
int _nb_jumps; // nombre de coups avant de casser
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/* [CONSTRUCTOR] Construction d'un xMarioGreenShell
|
||||
=========================================================*/
|
||||
xMarioMysteryBloc::xMarioMysteryBloc(xManager *m, int x, int y)
|
||||
xMarioMysteryBloc::xMarioMysteryBloc(xManager *m, int x, int y, int nb)
|
||||
: xSpriteAnimation(
|
||||
m,
|
||||
"src/myst_bloc.png",
|
||||
|
@ -18,6 +18,7 @@ xMarioMysteryBloc::xMarioMysteryBloc(xManager *m, int x, int y)
|
|||
_lastjump = SDL_GetTicks();
|
||||
_jumps = 0;
|
||||
_active = true;
|
||||
_nb_jumps = nb;
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,15 +31,15 @@ void xMarioMysteryBloc::jump(){
|
|||
if( !this->active() )
|
||||
return;
|
||||
|
||||
if( _defaultrect.y == _dst.y && SDL_GetTicks()-_lastjump > 300 ){
|
||||
if( _defaultrect.y == _dst.y && SDL_GetTicks()-_lastjump > 100 ){
|
||||
|
||||
this->move(0, -10);
|
||||
this->move(0, -5);
|
||||
|
||||
_lastjump = SDL_GetTicks();
|
||||
|
||||
_jumps++;
|
||||
|
||||
if( _jumps >= 6 )
|
||||
if( _jumps >= _nb_jumps )
|
||||
this->active(false);
|
||||
}
|
||||
}
|
||||
|
@ -47,9 +48,9 @@ void xMarioMysteryBloc::jump(){
|
|||
/* [UNJUMP] Animation d'activation (quand saut)
|
||||
=========================================================*/
|
||||
void xMarioMysteryBloc::unjump(){
|
||||
if( (_defaultrect.y-10) == _dst.y && SDL_GetTicks()-_lastjump > 100 ){
|
||||
if( (_defaultrect.y-5) == _dst.y && SDL_GetTicks()-_lastjump > 100 ){
|
||||
|
||||
this->move(0, 10);
|
||||
this->move(0, 5);
|
||||
|
||||
_lastjump = SDL_GetTicks();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
class xMarioMysteryBloc : public xSpriteAnimation{
|
||||
|
||||
public:
|
||||
xMarioMysteryBloc(xManager *manager, int x, int y); // Spritesheet avec taille de chaque sprite
|
||||
xMarioMysteryBloc(xManager *manager, int x, int y, int nb=1); // Spritesheet avec taille de chaque sprite
|
||||
|
||||
// Surcharge parent
|
||||
void onCollide(vector<int> from, xSprite* by);
|
||||
|
@ -23,6 +23,8 @@
|
|||
Uint32 _lastjump;
|
||||
SDL_Rect _defaultrect;
|
||||
|
||||
int _nb_jumps; // nombre de coups avant de casser
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ xMarioMario::xMarioMario(xManager *m, int x, int y)
|
|||
|
||||
// Constantes de mouvement sur Y
|
||||
_velocity[1] = 0.0;
|
||||
_mult[1] = 50;
|
||||
_mult[1] = 40;
|
||||
_dec[1] = .3;
|
||||
_acc[1] = 3;
|
||||
_min_vel[1] = 0.2;
|
||||
|
|
|
@ -78,6 +78,59 @@ xSprite::xSprite(xManager *m, SDL_Texture *t){
|
|||
|
||||
|
||||
|
||||
/* [SETTEXTURE] Modification de la texture avec couleur
|
||||
=========================================================*/
|
||||
void xSprite::setTexture(const int rgb[]){
|
||||
_texture = NULL;
|
||||
|
||||
SDL_Surface *surf = SDL_CreateRGBSurface(0, 0, 0, 32, 0, 0, 0, rgb[3]);
|
||||
|
||||
// On recupere la couleur
|
||||
Uint32 color = SDL_MapRGBA( surf->format, rgb[0], rgb[1], rgb[2], rgb[3]);
|
||||
|
||||
|
||||
// On cree la texture a partir de la surface
|
||||
_texture = SDL_CreateTextureFromSurface(_manager->renderer(), surf);
|
||||
|
||||
|
||||
// On libere la surface inutile maintenant
|
||||
SDL_FreeSurface( surf );
|
||||
surf = NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* [SETTEXTURE] Modification de la texture avec image
|
||||
=========================================================*/
|
||||
void xSprite::setTexture(const char *url){
|
||||
_texture = NULL;
|
||||
|
||||
/* (1) On cree la texture directement */
|
||||
_texture = IMG_LoadTexture(_manager->renderer(), url);
|
||||
|
||||
// Gestion erreur
|
||||
if( _texture == NULL )
|
||||
return;
|
||||
}
|
||||
|
||||
/* [SETTEXTURE] Modification de la texture texture
|
||||
=========================================================*/
|
||||
void xSprite::setTexture(SDL_Texture *t){
|
||||
_type = "basic";
|
||||
|
||||
_texture = NULL;
|
||||
|
||||
_texture = t;
|
||||
|
||||
// Gestion erreur
|
||||
if( _texture == NULL )
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* [MOVE] Modification de la position/taille du sprite
|
||||
=========================================================*/
|
||||
vector<int> xSprite::move(SDL_Rect newpos){
|
||||
|
|
|
@ -11,6 +11,11 @@
|
|||
xSprite(xManager *m, SDL_Texture *t); // Sprite texture
|
||||
~xSprite();
|
||||
|
||||
// Modifications de la texture
|
||||
void setTexture(const int rgb[]); // Sprite couleur
|
||||
void setTexture(const char *url); // Sprite image
|
||||
void setTexture(SDL_Texture *t); // Sprite texture
|
||||
|
||||
|
||||
vector<int> move(SDL_Rect newpos); // Deplace le sprite
|
||||
vector<int> move(int x, int y); // Deplace le sprite
|
||||
|
|
Loading…
Reference in New Issue