[WIP] Collision detectie moet nog worden egimplementeerd om naar game over screen te gaan
This commit is contained in:
@@ -35,7 +35,11 @@ namespace entities
|
||||
collision::Box model_box = { model_pos, model.raw_model.model_size };
|
||||
model_box.SetRotation(-90);
|
||||
furniture.push_back(std::make_shared<CollisionEntity>(model, model_pos, glm::vec3(0, -90, 0), HOUSE_SIZE * 2, model_box));
|
||||
//furniture_collision.push_back(std::make_shared<CollisionEntity>(model, model_pos, glm::vec3(0, -90, 0), HOUSE_SIZE * 2, model_box));
|
||||
|
||||
}
|
||||
|
||||
//furniture_collision.pop_front();
|
||||
|
||||
/*
|
||||
// Add furniture
|
||||
@@ -255,4 +259,9 @@ namespace entities
|
||||
|
||||
furniture_models.insert(std::pair<FurnitureType, std::deque<models::TexturedModel>>(FurnitureType::MISC, miscs));
|
||||
}
|
||||
|
||||
/*std::deque<std::shared_ptr<CollisionEntity>> HouseGenerator::GetFurnitureCollisions()
|
||||
{
|
||||
return furniture_collision;
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ namespace entities
|
||||
models::ModelTexture default_texture;
|
||||
|
||||
std::map<FurnitureType, std::deque<models::TexturedModel>> furniture_models;
|
||||
//std::deque<std::shared_ptr<CollisionEntity>> furniture_collision;
|
||||
|
||||
|
||||
public:
|
||||
HouseGenerator();
|
||||
@@ -47,7 +49,12 @@ namespace entities
|
||||
/*
|
||||
* @brief: Returns the depth of the house (chunk)
|
||||
*/
|
||||
float GetHouseDepth() const { return house_model.raw_model.model_size.x * HOUSE_SIZE; }
|
||||
float GetHouseDepth() const { return house_model.raw_model.model_size.x * HOUSE_SIZE;
|
||||
|
||||
}
|
||||
|
||||
//std::deque<std::shared_ptr<CollisionEntity>> GetFurnitureCollisions();
|
||||
|
||||
|
||||
private:
|
||||
/*
|
||||
|
||||
@@ -97,4 +97,8 @@ namespace entities
|
||||
is_playing = false;
|
||||
std::cout << "collision" << std::endl;
|
||||
}
|
||||
|
||||
bool MainCharacter::GetOnCollide() {
|
||||
return is_playing;
|
||||
}
|
||||
}
|
||||
@@ -34,5 +34,7 @@ namespace entities
|
||||
void Move(GLFWwindow* window);
|
||||
|
||||
void OnCollide(const collision::Collision& collision) override;
|
||||
|
||||
bool GetOnCollide();
|
||||
};
|
||||
}
|
||||
|
||||
184
src/scenes/game_Over_Scene.cpp
Normal file
184
src/scenes/game_Over_Scene.cpp
Normal file
@@ -0,0 +1,184 @@
|
||||
#include <iostream>
|
||||
#include <GL/glew.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <map>
|
||||
#include "game_Over_Scene.h"
|
||||
#include <iostream>
|
||||
#include <opencv2/core/mat.hpp>
|
||||
|
||||
#include "../models/model.h"
|
||||
#include "../renderEngine/loader.h"
|
||||
#include "../renderEngine/obj_loader.h"
|
||||
#include "../renderEngine/renderer.h"
|
||||
#include "../shaders/entity_shader.h"
|
||||
#include "../gui/gui_interactable.h"
|
||||
#include "../toolbox/toolbox.h"
|
||||
#include "../computervision/MenuTest.h"
|
||||
#include "../computervision/ObjectDetection.h"
|
||||
#include "../computervision/HandDetectRegion.h"
|
||||
|
||||
namespace scene
|
||||
{
|
||||
shaders::GuiShader* gui_shader_gameOver;
|
||||
std::vector<gui::GuiTexture*> guis_gameOver;
|
||||
computervision::ObjectDetection objDetect_gameOver;
|
||||
|
||||
float item_number_gameOver = 0;
|
||||
|
||||
bool hand_mode_gameOver = false;
|
||||
|
||||
Game_Over_Scene::Game_Over_Scene() {
|
||||
shaders::EntityShader shader;
|
||||
shader.Init();
|
||||
render_engine::renderer::Init(shader);
|
||||
shader.CleanUp();
|
||||
|
||||
gui_shader_gameOver = new shaders::GuiShader();
|
||||
gui_shader_gameOver->Init();
|
||||
}
|
||||
|
||||
gui::Button* ConvertGuiTextureToButtonGameOver(gui::GuiTexture* texture) {
|
||||
gui::Button* button;
|
||||
if (texture != NULL)
|
||||
{
|
||||
|
||||
if (texture->GetType() == gui::GuiType::BUTTON) {
|
||||
|
||||
button = (gui::Button*)texture;
|
||||
return button;
|
||||
}
|
||||
else {
|
||||
button = nullptr;
|
||||
return button;
|
||||
}
|
||||
}
|
||||
else {
|
||||
button = nullptr;
|
||||
return button;
|
||||
}
|
||||
}
|
||||
|
||||
gui::GuiTexture* GetMenuItemGameOver(bool hand_state) {
|
||||
if (hand_state)
|
||||
item_number_gameOver += 0.20f;
|
||||
|
||||
int temp_item_number = item_number_gameOver;
|
||||
|
||||
//If temp_item_number is equal to the size of the array, set item_number bac to zero to loop through the array again
|
||||
if (temp_item_number == guis_gameOver.size()) {
|
||||
item_number_gameOver = 0;
|
||||
temp_item_number = 0;
|
||||
}
|
||||
std::cout << guis_gameOver[temp_item_number]->texture << std::endl;
|
||||
return guis_gameOver[temp_item_number];
|
||||
}
|
||||
|
||||
scene::Scenes scene::Game_Over_Scene::start(GLFWwindow* window) {
|
||||
gui::Button button_start_scene(render_engine::loader::LoadTexture("res/Birb1.jpg"), glm::vec2(0.0f, 0.6f), glm::vec2(0.25f, 0.25f));
|
||||
button_start_scene.SetHoverTexture(render_engine::loader::LoadTexture("res/Birb2.jpg"));
|
||||
button_start_scene.SetClickedTexture(render_engine::loader::LoadTexture("res/Birb3.jpg"));
|
||||
button_start_scene.SetOnClickAction([]()
|
||||
{
|
||||
std::cout << "Back to start screen!!" << std::endl;
|
||||
});
|
||||
guis_gameOver.push_back(&button_start_scene);
|
||||
|
||||
computervision::ObjectDetection objDetect;
|
||||
cv::Mat cameraFrame;
|
||||
gui::GuiTexture* chosen_item_gameOver = NULL; //This is the selected menu_item
|
||||
bool hand_closed = false; //Flag to prevent multiple button presses
|
||||
|
||||
while (return_value == scene::Scenes:: GAMEOVER)
|
||||
{
|
||||
render();
|
||||
update(window);
|
||||
|
||||
if (hand_mode_gameOver)
|
||||
{
|
||||
cameraFrame = objDetect_gameOver.ReadCamera();
|
||||
|
||||
bool detect = false;
|
||||
bool hand_detection = objDetect_gameOver.DetectHand(cameraFrame, detect);
|
||||
|
||||
if (hand_detection)
|
||||
{
|
||||
hand_closed = false;
|
||||
std::cout << "hand is opened" << std::endl;
|
||||
|
||||
//Loop through menu items
|
||||
chosen_item_gameOver = GetMenuItemGameOver(true);
|
||||
|
||||
gui::Button* new_button = ConvertGuiTextureToButtonGameOver(chosen_item_gameOver);
|
||||
if (new_button != NULL) {
|
||||
const float x_pos = (chosen_item_gameOver->position.x + 1.0) * WINDOW_WIDTH / 2;
|
||||
const float y_pos = (1.0 - chosen_item_gameOver->position.y) * WINDOW_HEIGHT / 2;
|
||||
|
||||
//Set cursor to location of selected menu_item
|
||||
glfwSetCursorPos(window, x_pos, y_pos);
|
||||
}
|
||||
}
|
||||
else if (!hand_detection)
|
||||
{
|
||||
std::cout << "hand is closed" << std::endl;
|
||||
|
||||
//Gets selected menu_item
|
||||
chosen_item_gameOver = GetMenuItemGameOver(false);
|
||||
gui::Button* new_button = ConvertGuiTextureToButtonGameOver(chosen_item_gameOver);
|
||||
|
||||
if (new_button != NULL && !hand_closed) {
|
||||
//Run function click
|
||||
new_button->ForceClick(GLFW_MOUSE_BUTTON_LEFT);
|
||||
hand_closed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
gui_shader_gameOver->CleanUp();
|
||||
render_engine::loader::CleanUp();
|
||||
return return_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* renders the models in the start-up scene
|
||||
*/
|
||||
void scene::Game_Over_Scene::render()
|
||||
{
|
||||
render_engine::renderer::Prepare();
|
||||
|
||||
// Render GUI items
|
||||
render_engine::renderer::Render(guis_gameOver, *gui_shader_gameOver);
|
||||
}
|
||||
|
||||
/**
|
||||
* updates the variables for the start-up scene
|
||||
*/
|
||||
void scene::Game_Over_Scene::update(GLFWwindow* window)
|
||||
{
|
||||
for (gui::GuiTexture* button : guis_gameOver) {
|
||||
gui::Button* new_button = ConvertGuiTextureToButtonGameOver(button);
|
||||
if (new_button != NULL)
|
||||
new_button->Update(window);
|
||||
}
|
||||
bool hand_present;
|
||||
objDetect_gameOver.DetectHand(objDetect_gameOver.ReadCamera(), hand_present);
|
||||
}
|
||||
|
||||
/**
|
||||
* manages the key input in the start-up scene
|
||||
*/
|
||||
void scene::Game_Over_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
{
|
||||
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
|
||||
{
|
||||
return_value = scene::Scenes::INGAME;
|
||||
cv::destroyWindow("camera");
|
||||
}
|
||||
else if (glfwGetKey(window, GLFW_KEY_BACKSPACE) == GLFW_PRESS) {
|
||||
hand_mode_gameOver = !hand_mode_gameOver;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
26
src/scenes/game_Over_Scene.h
Normal file
26
src/scenes/game_Over_Scene.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#pragma once
|
||||
#include "scene.h"
|
||||
#include "../gui/gui_element.h"
|
||||
|
||||
namespace scene
|
||||
{
|
||||
extern GLFWwindow* window;
|
||||
|
||||
class Game_Over_Scene : public scene::Scene
|
||||
{
|
||||
private:
|
||||
scene::Scenes return_value = scene::Scenes::GAMEOVER;
|
||||
|
||||
public:
|
||||
Game_Over_Scene();
|
||||
|
||||
Scenes start(GLFWwindow* window) override;
|
||||
|
||||
void render() override;
|
||||
|
||||
void update(GLFWwindow* window) override;
|
||||
|
||||
void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) override;
|
||||
|
||||
};
|
||||
}
|
||||
@@ -31,6 +31,9 @@ namespace scene
|
||||
{
|
||||
std::shared_ptr<entities::MainCharacter>main_character;
|
||||
std::vector<std::shared_ptr<entities::CollisionEntity>> collision_entities;
|
||||
|
||||
//std::deque<std::shared_ptr<entities::CollisionEntity>> furniture_collision;
|
||||
|
||||
entities::HouseGenerator* house_generator;
|
||||
std::deque<std::shared_ptr<entities::Entity>> house_models;
|
||||
|
||||
@@ -135,10 +138,11 @@ namespace scene
|
||||
|
||||
std::deque<std::shared_ptr<entities::Entity>> furniture = house_generator->GenerateHouse(glm::vec3(0, -75, -50 - z_offset), 90);
|
||||
furniture_count = furniture.size();
|
||||
|
||||
|
||||
house_models.insert(house_models.end(), furniture.begin(), furniture.end());
|
||||
std::cout << "funriture_count in load chunk (house included): " << furniture_count << std::endl;
|
||||
furniture_count_old = furniture_count - 1;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -270,6 +274,10 @@ namespace scene
|
||||
{
|
||||
//camera.Move(window);
|
||||
main_character->Move(window);
|
||||
if (!main_character.get()->GetOnCollide())
|
||||
{
|
||||
return_value = scene::Scenes::GAMEOVER;
|
||||
}
|
||||
|
||||
//std::cout << "x get: " << movement.x << "\ny get: " << movement.y << "\nz get: " << movement.z << "\n";
|
||||
camera->Follow(main_character->GetPosition());
|
||||
@@ -291,6 +299,7 @@ namespace scene
|
||||
last_model_pos = model_pos;
|
||||
|
||||
collision::CheckCollisions(collision_entities);
|
||||
|
||||
update_hand_detection();
|
||||
|
||||
|
||||
@@ -352,11 +361,8 @@ namespace scene
|
||||
|
||||
toolbox::GetDigitsFromNumber(score, digits);
|
||||
|
||||
std::cout << "Digits size: " << digits.size() << std::endl;
|
||||
|
||||
for (int i = digits.size()-1; i >= 0; i--)
|
||||
{
|
||||
std::cout << "Digit in digits: " << i << std::endl;
|
||||
score_textures[digits[i]].get()->position.x = 0.15 * i -0.9;
|
||||
render_engine::renderer::Render(score_textures[digits[i]], *gui_shader);
|
||||
|
||||
|
||||
@@ -103,6 +103,10 @@ namespace scene
|
||||
*/
|
||||
void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) override;
|
||||
|
||||
/**
|
||||
* @brief: This method renders the score points onto the game window
|
||||
* @param score: Score to show
|
||||
*/
|
||||
void DrawScore(int score);
|
||||
|
||||
};
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
<ClCompile Include="src\entities\house_generator.cpp" />
|
||||
<ClCompile Include="src\computervision\calibration\HandCalibrator.cpp" />
|
||||
<ClCompile Include="src\computervision\HandDetectRegion.cpp" />
|
||||
<ClCompile Include="src\scenes\game_Over_Scene.cpp" />
|
||||
<ClCompile Include="src\scenes\in_Game_Scene.cpp" />
|
||||
<ClCompile Include="src\computervision\MenuTest.cpp" />
|
||||
<ClCompile Include="src\computervision\async\async_arm_detection.cpp" />
|
||||
@@ -55,6 +56,7 @@
|
||||
<ClInclude Include="src\computervision\calibration\HandCalibrator.h" />
|
||||
<ClInclude Include="src\computervision\calibration\StaticSkinTreshold.h" />
|
||||
<ClInclude Include="src\computervision\HandDetectRegion.h" />
|
||||
<ClInclude Include="src\scenes\game_Over_Scene.h" />
|
||||
<ClInclude Include="src\scenes\in_Game_Scene.h" />
|
||||
<ClInclude Include="src\scenes\scene.h" />
|
||||
<ClInclude Include="src\computervision\async\async_arm_detection.h" />
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
<ClCompile Include="src\entities\house_generator.cpp" />
|
||||
<ClCompile Include="src\computervision\MenuTest.cpp" />
|
||||
<ClCompile Include="src\scenes\scene.cpp" />
|
||||
<ClCompile Include="src\scenes\game_Over_Scene.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\entities\Camera.cpp">
|
||||
@@ -148,6 +149,7 @@
|
||||
<ClInclude Include="src\toolbox\Timer.h" />
|
||||
<ClInclude Include="src\toolbox\toolbox.h" />
|
||||
<ClInclude Include="src\scenes\startup_Scene.h" />
|
||||
<ClInclude Include="src\scenes\game_Over_Scene.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Xml Include="res\haarcascade_frontalface_alt.xml" />
|
||||
|
||||
Reference in New Issue
Block a user