Commit 76d27f3d authored by Benjamin Castel's avatar Benjamin Castel
Browse files

feat: Working missile-ship collisions

parent 0dc20cb0
Loading
Loading
Loading
Loading
+1 −1
Changes for CMakeLists.txt: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -18,5 +18,5 @@ include_directories("glitter/ext/tinyobjloader"
		${OPENGL_INCLUDE_DIR})

add_executable(GLE-test src/main.cpp src/RenderObject.cpp src/GuiElement.cpp src/RenderObjectPart.cpp src/GlApplication.cpp
               src/model/Spaceship.cpp src/model/Entity.cpp src/model/Missile.cpp src/model/Box.cpp)
               src/model/Spaceship.cpp src/model/Entity.cpp src/model/Missile.cpp)
target_link_libraries(GLE-test utils ${GLFW3_LIBRARIES} ${GLEW_LIBRARIES})

include/model/Box.hpp

deleted100644 → 0
+0 −16
Changes for include/model/Box.hpp: 0 added lines, 16 removed lines.
Original line number Diff line number Diff line
#pragma once


#include <glm/ext.hpp>


#include "model/Entity.hpp"

class Box {
    private:
        glm::vec3 scales;

    public:
        Box(glm::vec3 &scales);
        bool is_point_inside(glm::vec3 &point, glm::vec3 &center);
};
+3 −1
Changes for include/model/Entity.hpp: 3 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -28,7 +28,9 @@ class Entity {
        void setScale(glm::vec3 scales);

        glm::mat4 get_box_model_matrix(std::unique_ptr<RenderObject> &renderObject) const;
        bool check_box_intersection() const;
        bool check_box_intersection(std::unique_ptr<RenderObject> &renderObjectThis,
                                    const Entity &other,
                                    std::unique_ptr<RenderObject> &renderObjectOther) const;

    protected:
        void computeModelMatrix(); 
+5 −0
Changes for include/model/Spaceship.hpp: 5 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ class Spaceship : public Entity {
        Player       playerNumber;
        bool         thrusting;
        float        fireCooldown;
        unsigned int healthPoints;

    public:
        Spaceship(const Player &playerNumber, const glm::mat4 &modelWorld);
@@ -19,12 +20,16 @@ class Spaceship : public Entity {
        const glm::vec3    &get_acceleration()  const;
        const Player       &get_player_number() const;
        const bool         &is_thrusting()      const;
        const unsigned int &get_health_points() const;

        void set_acceleration(const glm::vec3 &newAcceleration);
        void set_thrusting(const bool &newThrusting);
        
        void take_damage();

        void update(const float &deltaTime) override;


        std::shared_ptr<Missile> generate_missile();

        // TODO : REMOVE AND REPLACE
+16 −0
Changes for src/GlApplication.cpp: 16 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -169,6 +169,22 @@ void GlApplication::update()
            entity->update(deltaTime);
        }
    }

    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);
        }
    }

    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])) {
            std::cout << "Player 2 hit player 1 !" << std::endl;
            this->m_entities[ModelKeys::LASER_2].erase(this->m_entities[ModelKeys::LASER_2].begin()+index);
        }
    }
}

void GlApplication::computeView(Player player)
Loading