Loading src/GlApplication.cpp +26 −0 Changes for src/GlApplication.cpp: 26 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -170,11 +170,19 @@ void GlApplication::update() } } bool didP1Die, 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])) { 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; if (std::static_pointer_cast<Spaceship>(this->m_entities[ModelKeys::SPACESHIP_2][0])->get_health_points() == 0) { didP2Die = true; } } } Loading @@ -183,8 +191,26 @@ void GlApplication::update() if (missile->check_box_intersection(this->m_models[ModelKeys::LASER_2], *this->m_entities[ModelKeys::SPACESHIP_1][0], 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; if (std::static_pointer_cast<Spaceship>(this->m_entities[ModelKeys::SPACESHIP_1][0])->get_health_points() == 0) { didP1Die = true; } } } GLFWwindow *window = glfwGetCurrentContext(); if (didP1Die && didP2Die) { std::cout << "Égalité parfaite ! Incroyable !" << std::endl; } else if (didP1Die) { std::cout << "Victoire du joueur 2 !" << std::endl; glfwSetWindowShouldClose(window, 1); } else if (didP2Die) { std::cout << "Victoire du joueur 1 !" << std::endl; glfwSetWindowShouldClose(window, 1); } } void GlApplication::computeView(Player player) Loading src/model/Spaceship.cpp +8 −1 Changes for src/model/Spaceship.cpp: 8 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -4,7 +4,8 @@ Spaceship::Spaceship(const Player &playerNumber, const glm::mat4 &modelWorld) : Entity(), acceleration(glm::vec3(1, 0, 0)), playerNumber(playerNumber), fireCooldown(0) {} fireCooldown(0), healthPoints(3) {} const glm::vec3 &Spaceship::get_acceleration() const { return this->acceleration; } Loading @@ -12,6 +13,8 @@ const Player &Spaceship::get_player_number() const { return this->playerNumber; const bool &Spaceship::is_thrusting() const { return this->thrusting; } const unsigned int &Spaceship::get_health_points() const { return this->healthPoints; } void Spaceship::set_acceleration(const glm::vec3 &newAcceleration) { this->acceleration = newAcceleration; } Loading @@ -20,6 +23,10 @@ void Spaceship::set_thrusting(const bool &newThrusting) { this->thrusting = newThrusting; } void Spaceship::take_damage() { this->healthPoints--; } // TODO : REMOVE AND REPLACE void Spaceship::thrust(const float &deltaTime) { Entity::move(normalize(this->m_localZ)*deltaTime); Loading Loading
src/GlApplication.cpp +26 −0 Changes for src/GlApplication.cpp: 26 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -170,11 +170,19 @@ void GlApplication::update() } } bool didP1Die, 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])) { 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; if (std::static_pointer_cast<Spaceship>(this->m_entities[ModelKeys::SPACESHIP_2][0])->get_health_points() == 0) { didP2Die = true; } } } Loading @@ -183,8 +191,26 @@ void GlApplication::update() if (missile->check_box_intersection(this->m_models[ModelKeys::LASER_2], *this->m_entities[ModelKeys::SPACESHIP_1][0], 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; if (std::static_pointer_cast<Spaceship>(this->m_entities[ModelKeys::SPACESHIP_1][0])->get_health_points() == 0) { didP1Die = true; } } } GLFWwindow *window = glfwGetCurrentContext(); if (didP1Die && didP2Die) { std::cout << "Égalité parfaite ! Incroyable !" << std::endl; } else if (didP1Die) { std::cout << "Victoire du joueur 2 !" << std::endl; glfwSetWindowShouldClose(window, 1); } else if (didP2Die) { std::cout << "Victoire du joueur 1 !" << std::endl; glfwSetWindowShouldClose(window, 1); } } void GlApplication::computeView(Player player) Loading
src/model/Spaceship.cpp +8 −1 Changes for src/model/Spaceship.cpp: 8 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -4,7 +4,8 @@ Spaceship::Spaceship(const Player &playerNumber, const glm::mat4 &modelWorld) : Entity(), acceleration(glm::vec3(1, 0, 0)), playerNumber(playerNumber), fireCooldown(0) {} fireCooldown(0), healthPoints(3) {} const glm::vec3 &Spaceship::get_acceleration() const { return this->acceleration; } Loading @@ -12,6 +13,8 @@ const Player &Spaceship::get_player_number() const { return this->playerNumber; const bool &Spaceship::is_thrusting() const { return this->thrusting; } const unsigned int &Spaceship::get_health_points() const { return this->healthPoints; } void Spaceship::set_acceleration(const glm::vec3 &newAcceleration) { this->acceleration = newAcceleration; } Loading @@ -20,6 +23,10 @@ void Spaceship::set_thrusting(const bool &newThrusting) { this->thrusting = newThrusting; } void Spaceship::take_damage() { this->healthPoints--; } // TODO : REMOVE AND REPLACE void Spaceship::thrust(const float &deltaTime) { Entity::move(normalize(this->m_localZ)*deltaTime); Loading