diff --git a/SmashBigBordelv2/Entite.cpp b/SmashBigBordelv2/Entite.cpp index d1816d5..ac0bf8e 100644 --- a/SmashBigBordelv2/Entite.cpp +++ b/SmashBigBordelv2/Entite.cpp @@ -32,26 +32,30 @@ void Entite::CheckCollision(Entite *entite, float repoussement, sf::Time dureeIt { if (deltaX > 0.0f) { - this->move((intersectionX *dureeIteration.asSeconds()) * (dureeIteration.asSeconds() - repoussement), 0.0f); //vers la droite - //entite->move(intersectionX * (dureeIteration.asSeconds() - repoussement)* dureeIteration.asSeconds(), 0.0f); + this->move((intersectionX *dureeIteration.asSeconds()) * (dureeIteration.asSeconds() - repoussement), 0.0f); + this->setVersdroite(false);//vers la droite + } - else + else if (deltaX < 0.0f) { this->move(-(intersectionX *dureeIteration.asSeconds()) * (dureeIteration.asSeconds() - repoussement), 0.0f);//vers la gauche - //entite->move(intersectionX * (dureeIteration.asSeconds() - repoussement)* dureeIteration.asSeconds(), 0.0f); + this->setVersgauche(false); + } - } - else - { + + else if(intersectionX < intersectionY) + if (deltaY > 0.0f) { this->move(0.0f, (intersectionX *dureeIteration.asSeconds()) * (dureeIteration.asSeconds() - repoussement));//vers le bas - //entite->move(0.0f ,intersectionX * (dureeIteration.asSeconds() - repoussement)*dureeIteration.asSeconds()); + this->setVersbas(false); + } - else + else if (deltaY < 0.0f) { this->move(0.0f ,-(intersectionX *dureeIteration.asSeconds()) * (dureeIteration.asSeconds() - repoussement));//vers le haut - //entite->move(0.0f, intersectionX * (dureeIteration.asSeconds() - repoussement)* dureeIteration.asSeconds()); + this->setVershaut(false); + } } @@ -81,6 +85,46 @@ bool Entite::getCheckCollision() return this->CheckColision; } +void Entite::setVersdroite(bool ok) +{ + this->Versdroite = ok; +} + +bool Entite::getVersdroite() +{ + return this->Versdroite; +} + +void Entite::setVersgauche(bool ok) +{ + this->Versgauche = ok; +} + +bool Entite::getVersgauche() +{ + return this->Versgauche; +} + +void Entite::setVershaut(bool ok) +{ + this->Vershaut = ok; +} + +bool Entite::getVershaut() +{ + return this->Vershaut; +} + +void Entite::setVersbas(bool ok) +{ + this->Versbas = ok; +} + +bool Entite::getVersbas() +{ + return this->Versbas; +} + void Entite::SetNom(std::string nom) { diff --git a/SmashBigBordelv2/Entite.h b/SmashBigBordelv2/Entite.h index 8a05629..924c339 100644 --- a/SmashBigBordelv2/Entite.h +++ b/SmashBigBordelv2/Entite.h @@ -16,6 +16,17 @@ class Entite : public sf::Sprite virtual void setCheckCollision(bool ok); virtual bool getCheckCollision(); + virtual void setVersdroite(bool ok); + virtual bool getVersdroite(); + + virtual void setVersgauche(bool ok); + virtual bool getVersgauche(); + + virtual void setVershaut(bool ok); + virtual bool getVershaut(); + + virtual void setVersbas(bool ok); + virtual bool getVersbas(); virtual void SetNom(std::string nom); virtual std::string GetNom(); @@ -42,6 +53,10 @@ class Entite : public sf::Sprite protected: bool Collision = false; + bool Versgauche = true; + bool Versdroite = true; + bool Vershaut = true; + bool Versbas = true; bool CheckColision = false; Collider *collider; std::string Nom; diff --git a/SmashBigBordelv2/Jeu.cpp b/SmashBigBordelv2/Jeu.cpp index b5660de..d33971e 100644 --- a/SmashBigBordelv2/Jeu.cpp +++ b/SmashBigBordelv2/Jeu.cpp @@ -115,45 +115,45 @@ void Jeu::CheckModif() { //---------J1-------------------------------- - if (perso1choisi->getMoveRight()) //check si le bool est actif + if (perso1choisi->getMoveRight() && perso1choisi->getVersdroite()) //check si le bool est actif { Animate(perso1choisi, "droite",1); perso1choisi->move(dureeIteration.asSeconds()*((VitesseDeplacement / perso1choisi->GetPoids()) * VitesseDeplacement), 0); } - if (perso1choisi->getMoveLeft()) //check si le bool est actif + if (perso1choisi->getMoveLeft() && perso1choisi->getVersgauche()) //check si le bool est actif { Animate(perso1choisi, "gauche",1); perso1choisi->move(-dureeIteration.asSeconds()*((VitesseDeplacement / perso1choisi->GetPoids()) * VitesseDeplacement), 0); } - if (perso1choisi->getJump()/*&& perso1choisi->getCollision()*/) + if (perso1choisi->getJump() && perso1choisi->getVershaut()/*&& !perso2choisi->getVersbas()*/) { perso1choisi->move(0, (-dureeIteration.asSeconds()*((VitesseSaut / perso1choisi->GetPoids()) * VitesseSaut))); } - if (!perso1choisi->getCollision() && !perso1choisi->getJump()) + if (!perso1choisi->getCollision() && perso1choisi->getVersbas()) { perso1choisi->move(0, (dureeIteration.asSeconds()*((VitesseDeplacement / perso1choisi->GetPoids()) * Gravity))); } //----------J2-------------------------------- - if (perso2choisi->getMoveRight()) //check si le bool est actif + if (perso2choisi->getMoveRight() && perso2choisi->getVersdroite())//check si le bool est actif { Animate(perso2choisi, "droite",2); perso2choisi->move(dureeIteration.asSeconds()*((VitesseDeplacement / perso2choisi->GetPoids()) * VitesseDeplacement), 0); } - if (perso2choisi->getMoveLeft()) //check si le bool est actif + if (perso2choisi->getMoveLeft() && perso1choisi->getVersgauche()) //check si le bool est actif { Animate(perso2choisi, "gauche",3); perso2choisi->move(-dureeIteration.asSeconds()*((VitesseDeplacement / perso2choisi->GetPoids()) * VitesseDeplacement), 0); } - if (perso2choisi->getJump() /*&& perso2choisi->getCollision()*/) + if (perso2choisi->getJump() && perso2choisi->getVershaut() /*&& !perso2choisi->getVersbas()*/) { perso2choisi->move(0, (-dureeIteration.asSeconds()*((VitesseSaut / perso2choisi->GetPoids()) * VitesseSaut))); } - if (!perso2choisi->getCollision() && !perso2choisi->getJump()) + if (!perso2choisi->getCollision() && perso1choisi->getVersbas()) { perso2choisi->move(0, (dureeIteration.asSeconds()*((VitesseDeplacement / perso2choisi->GetPoids()) * Gravity))); } - } + } } @@ -172,6 +172,10 @@ void Jeu::CheckCollision(Personnage *michel) if (!michel->getCheckCollision()) { michel->setCollision(false); + michel->setVersbas(true); + michel->setVershaut(true); + michel->setVersgauche(true); + michel->setVersdroite(true); } michel->setCheckCollision(false); @@ -360,15 +364,13 @@ void Jeu::ChoixPerso() case 1: perso2choisi = new Rick(Spawn_x2, Spawn_y2); - perso2choisi->SetPersonnage(); std::cout << "J2 : Rick \n " << std::endl; break; case 2: perso2choisi = new Morty(Spawn_x2, Spawn_y2); - perso2choisi->SetPersonnage(); - + std::cout << "J2 : Morty \n " << std::endl; break; diff --git a/SmashBigBordelv2/Jeu.h b/SmashBigBordelv2/Jeu.h index f2cccfb..2567196 100644 --- a/SmashBigBordelv2/Jeu.h +++ b/SmashBigBordelv2/Jeu.h @@ -75,9 +75,9 @@ class Jeu const int Gravity = 150; const float Spawn_x1 = 100; - const float Spawn_y1 = 0; + const float Spawn_y1 = -500; const float Spawn_x2 = -100; - const float Spawn_y2 = 0; + const float Spawn_y2 = -500; // Label HUD sf::Sprite *avatar1; sf::Text *NomPerso1; diff --git a/SmashBigBordelv2/Morty.cpp b/SmashBigBordelv2/Morty.cpp index 38470bc..d240594 100644 --- a/SmashBigBordelv2/Morty.cpp +++ b/SmashBigBordelv2/Morty.cpp @@ -19,7 +19,7 @@ Morty::Morty(int x, int y) : Personnage() this->setTextureRect(sf::IntRect(0, 0, 78, 110)); //this->setColor(sf::Color::Black); this->setOrigin(this->getGlobalBounds().width / 2, this->getGlobalBounds().height / 2); - this->setPosition(x, y); + this->setPosition(x , y); Dessin.push_back(this); delete t; diff --git a/SmashBigBordelv2/Source.cpp b/SmashBigBordelv2/Source.cpp index a1a7ad1..8931ef7 100644 --- a/SmashBigBordelv2/Source.cpp +++ b/SmashBigBordelv2/Source.cpp @@ -77,9 +77,9 @@ void main(int argc,char** argv[]) Game.ChoixMap(); + Game.ChargementJeu(Game.GetMapChoisie()); // Chargement une fois Game.ChoixPerso(); Game.CreateHUD(); // Création de l'interface HUD - Game.ChargementJeu(Game.GetMapChoisie()); // Chargement une fois //----------------------------- Boucle du jeu -------------------------------------------------- while (Game.GetWindow()->isOpen())