Commit 34f42689 authored by Pierre TESSIER's avatar Pierre TESSIER

Added GameOver feature

parent 4346b19e
......@@ -41,6 +41,12 @@ void scene_model::frame_draw(std::map<std::string,GLuint>& shaders, scene_struct
{
set_gui();
logicLoop(shaders, scene, gui);
if (m_gameOver)
{
std::cout << "Game Over" << std::endl;
glfwSetWindowShouldClose(gui.window, GLFW_TRUE);
return;
}
renderLoop(shaders, scene);
}
......@@ -55,6 +61,7 @@ void scene_model::createResources()
buildAIHierarchyPool(m_resources);
m_resources.collisionGrid = CollisionGrid(gridResolution, gridResolution, &m_resources.terrainGeometry);
m_ecs.subscribeToEntityDestroyedEvent("removeFromCollisionGrid", [&grid = m_resources.collisionGrid](ecs::Entity entity) { grid.removeEntity(entity); });
m_ecs.subscribeToEntityDestroyedEvent("GameOver", [&b = m_gameOver, &playerEntity = m_player](ecs::Entity entity) {if (playerEntity == entity) { b = true; } });
m_resources.meshes["collision_box"] = mesh_primitive_cylinder(1.f, vec3{}, vec3{ 0.f, 0.f, 1.f });
setupCollisionRates();
}
......@@ -105,6 +112,7 @@ void scene_model::set_gui()
void scene_model::logicLoop(std::map<std::string,GLuint>& shaders, scene_structure& scene, gui_structure& gui)
{
const float dt = m_timer.update();
const bool timerEvent = m_timer.event;
......@@ -143,6 +151,7 @@ void scene_model::logicLoop(std::map<std::string,GLuint>& shaders, scene_structu
m_ecs.update<LockdownSystem>();
m_ecs.update<HealthSystem>(m_ecs);
m_ecs.getSystem<HealthSystem>().destroyDeadCharacter(m_ecs);
}
void scene_model::renderLoop(std::map<std::string,GLuint>& shaders, scene_structure& scene)
......
......@@ -74,6 +74,8 @@ private:
MyEcs m_ecs;
CommonSceneResources m_resources;
bool m_gameOver = false;
Skybox m_skybox;
ecs::Entity m_player;
ecs::Entity m_aimCursor;
......
......@@ -19,7 +19,7 @@ static void NewDirection(PlayerControlComponent& controls)
}
}
void AIHandlingSystem::update(const MyEcs& m_ecs, const bool AIEvent, PlayerControlComponent& controls, TransformComponent& transform, AIPlayerComponent const& player)
void AIHandlingSystem::update(MyEcs& m_ecs, const bool AIEvent, PlayerControlComponent& controls, TransformComponent& transform, AIPlayerComponent const& player)
{
controls.currentControls[PlayerControlInfos::Control::Jump] = false;
controls.currentControls[PlayerControlInfos::Control::Shoot] = false;
......@@ -34,7 +34,7 @@ void AIHandlingSystem::update(const MyEcs& m_ecs, const bool AIEvent, PlayerCont
NewDirection(controls);
if (shoot < m_shootProba)
controls.currentControls[PlayerControlComponent::Control::Shoot] = true;
createRay(m_ecs, transform.entity(), m_ecs.get<TransformComponent>(player.target), transform);
if (jump < m_jumpProba)
controls.currentControls[PlayerControlComponent::Control::Jump] = true;
......@@ -47,4 +47,23 @@ void AIHandlingSystem::update(const MyEcs& m_ecs, const bool AIEvent, PlayerCont
mat3 rot = rotation_between_vector_mat3(currentAxis, targetDirection);
rot.zz = 1.0f;
transform.rotation = transform.rotation * rot;
}
void AIHandlingSystem::createRay(MyEcs& m_ecs, ecs::Entity const& AIEntity, TransformComponent const& targetTransform, TransformComponent const& AITransform)
{
std::mt19937 gen(m_rd());
std::uniform_real_distribution<float> dis(.0f, 1.0f);
auto realRayEntity = m_ecs.createEntity();
float const speed = 50.0f;
vec3 const position = AITransform.position + vec3(0, 0, 1) * 0.4;
vec3 direction = normalize(targetTransform.position - position);
const float theta = 3.1415 * dis(gen);
const float lambda = m_noise * dis(gen);
const vec3 noise = rotation_between_vector_mat3(vec3(0, 0, 1), direction) * vec3(cos(theta), sin(theta), 0);
direction = normalize(lambda * noise + direction);
auto& realRay = m_ecs.add<RayComponent>(realRayEntity, position, direction, speed, AIEntity, m_ecs.get<CharacterDesignComponent>(AIEntity).damage);
m_ecs.getSystem<RayTrajectory>().computeRayTrajectory(realRay, m_ecs);
}
\ No newline at end of file
......@@ -11,14 +11,18 @@ struct MyEcs;
struct AIHandlingSystem
{
public :
void update(const MyEcs& m_ecs, const bool AIEvent, PlayerControlComponent& controls, TransformComponent& transform, AIPlayerComponent const& player);
void update(MyEcs& m_ecs, const bool AIEvent, PlayerControlComponent& controls, TransformComponent& transform, AIPlayerComponent const& player);
void createRay(MyEcs& m_ecs, ecs::Entity const& AIEntity, TransformComponent const& targetTransform, TransformComponent const& AITransform);
using Requirements = ecs::Requirements<ecs::Auto>;
using UpdatePolicy = ecs::OncePerEntity;
private :
const float m_changeDirectionProba = .2f;
const float m_shootProba = 0.1f;
const float m_shootProba = .3f;
const float m_jumpProba = 0.1f;
const float m_noise = 0.2f;
std::random_device m_rd;
};
#endif // !SYSTEMS_AI_HANDLING_HPP_INCLUDED
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment