Commit 2b2dd2a7 authored by Justine Martin's avatar Justine Martin 💖
Browse files

fix : didP1Die était mal instancié et prenait la valeur résiduel en

mémoire causant parfois la fin du jeu avec une défaite pour le joueur 1
parent 425085d7
Loading
Loading
Loading
Loading
+10 −9
Changes for src/GlApplication.cpp: 10 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -260,17 +260,18 @@ void GlApplication::updateGame() {
        }
    }

    bool didP1Die, didP2Die = false;
    bool didP1Die = false;
    bool didP2Die = false;
 
    for (int index = this->m_entities[ModelKeys::LASER_1].size()-1; index != -1; --index) {
        std::shared_ptr<Entity> missile = this->m_entities[ModelKeys::LASER_1].at(index);
        if (missile->check_box_intersection(this->m_models[ModelKeys::LASER_1], *this->m_entities[ModelKeys::SPACESHIP_2][0], this->m_models[ModelKeys::SPACESHIP_2])) {
        if (missile->check_box_intersection(this->m_models[ModelKeys::LASER_1], *this->m_spaceshipPlayer2.get(), this->m_models[ModelKeys::SPACESHIP_2])) {
            std::cout << "Player 1 hit player 2 !" << std::endl;
            this->m_entities[ModelKeys::LASER_1].erase(this->m_entities[ModelKeys::LASER_1].begin()+index);
            std::static_pointer_cast<Spaceship>(this->m_entities[ModelKeys::SPACESHIP_2][0])->take_damage();
            std::cout << "HP restants : " << std::static_pointer_cast<Spaceship>(this->m_entities[ModelKeys::SPACESHIP_2][0])->get_health_points() << std::endl;
            this->m_spaceshipPlayer2->take_damage();
            std::cout << "HP restants : " << this->m_spaceshipPlayer2->get_health_points() << std::endl;
            
            if (std::static_pointer_cast<Spaceship>(this->m_entities[ModelKeys::SPACESHIP_2][0])->get_health_points() == 0) {
            if (this->m_spaceshipPlayer2->get_health_points() == 0) {
                didP2Die = true;
            }
        }
@@ -278,13 +279,13 @@ void GlApplication::updateGame() {

    for (int index = this->m_entities[ModelKeys::LASER_2].size()-1; index != -1; --index) {
        std::shared_ptr<Entity> missile = this->m_entities[ModelKeys::LASER_2].at(index);
        if (missile->check_box_intersection(this->m_models[ModelKeys::LASER_2], *this->m_entities[ModelKeys::SPACESHIP_1][0], this->m_models[ModelKeys::SPACESHIP_1])) {
        if (missile->check_box_intersection(this->m_models[ModelKeys::LASER_2], *this->m_spaceshipPlayer1.get(), this->m_models[ModelKeys::SPACESHIP_1])) {
            std::cout << "Player 2 hit player 1 !" << std::endl;
            this->m_entities[ModelKeys::LASER_2].erase(this->m_entities[ModelKeys::LASER_2].begin()+index);
            std::static_pointer_cast<Spaceship>(this->m_entities[ModelKeys::SPACESHIP_1][0])->take_damage();
            std::cout << "HP restants : " << std::static_pointer_cast<Spaceship>(this->m_entities[ModelKeys::SPACESHIP_1][0])->get_health_points() << std::endl;
            this->m_spaceshipPlayer1->take_damage();
            std::cout << "HP restants : " << this->m_spaceshipPlayer1->get_health_points() << std::endl;
            
            if (std::static_pointer_cast<Spaceship>(this->m_entities[ModelKeys::SPACESHIP_1][0])->get_health_points() == 0) {
            if (this->m_spaceshipPlayer1->get_health_points() == 0) {
                didP1Die = true;
            }
        }