[ADD] gameover scene shows the points

This commit is contained in:
DESKTOP-EBR7IVA\kimve
2021-06-18 13:35:19 +02:00
parent ca61dfc781
commit 824f9a2433
6 changed files with 75 additions and 30 deletions

View File

@@ -28,6 +28,7 @@
#include "scenes/in_Game_Scene.h" #include "scenes/in_Game_Scene.h"
#include "scenes/startup_Scene.h" #include "scenes/startup_Scene.h"
#include "scenes/game_Over_Scene.h" #include "scenes/game_Over_Scene.h"
#include "entities/collision_entity.h"
#include "computervision/ObjectDetection.h" #include "computervision/ObjectDetection.h"
//#include "computervision/OpenPoseImage.h" //#include "computervision/OpenPoseImage.h"
@@ -39,6 +40,7 @@
#pragma comment(lib, "glew32s.lib") #pragma comment(lib, "glew32s.lib")
#pragma comment(lib, "opengl32.lib") #pragma comment(lib, "opengl32.lib")
int score;
static double UpdateDelta(); static double UpdateDelta();
static GLFWwindow* window; static GLFWwindow* window;
@@ -73,7 +75,8 @@ int main(void)
glGetError(); glGetError();
#pragma endregion #pragma endregion
//TODO change back to 0, only to show how score is visible on end screen
score = 30;
current_scene = new scene::Startup_Scene(); current_scene = new scene::Startup_Scene();
glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods) glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods)
@@ -88,8 +91,6 @@ int main(void)
bool window_open = true; bool window_open = true;
// Main game loop // Main game loop
while (!glfwWindowShouldClose(window) && window_open) while (!glfwWindowShouldClose(window) && window_open)
{ {
@@ -110,11 +111,11 @@ int main(void)
case scene::Scenes::INGAME: case scene::Scenes::INGAME:
current_scene = new scene::In_Game_Scene(); current_scene = new scene::In_Game_Scene(&score);
break; break;
case scene::Scenes::GAMEOVER: case scene::Scenes::GAMEOVER:
current_scene = new scene::Game_Over_Scene(); current_scene = new scene::Game_Over_Scene(score);
break; break;
default: default:

View File

@@ -22,12 +22,12 @@ namespace scene
shaders::GuiShader* gui_shader_gameOver; shaders::GuiShader* gui_shader_gameOver;
std::vector<gui::GuiTexture*> guis_gameOver; std::vector<gui::GuiTexture*> guis_gameOver;
computervision::ObjectDetection objDetect_gameOver; computervision::ObjectDetection objDetect_gameOver;
std::vector<std::shared_ptr<gui::GuiTexture>> score_textures_gameOver;
float item_number_gameOver = 0; float item_number_gameOver = 0;
bool hand_mode_gameOver = false; bool hand_mode_gameOver = false;
Game_Over_Scene::Game_Over_Scene() Game_Over_Scene::Game_Over_Scene(int score)
{ {
shaders::EntityShader shader; shaders::EntityShader shader;
shader.Init(); shader.Init();
@@ -36,13 +36,28 @@ namespace scene
gui_shader_gameOver = new shaders::GuiShader(); gui_shader_gameOver = new shaders::GuiShader();
gui_shader_gameOver->Init(); gui_shader_gameOver->Init();
for (int i = 0; i <= 9; i++)
{
std::shared_ptr<gui::GuiTexture> score_pointer;
std::string texture_path = "res/";
texture_path += std::to_string(i);
texture_path += ".png";
score_pointer = std::make_unique<gui::GuiTexture>(render_engine::loader::LoadTexture(texture_path), glm::vec2(0.0f, 0.2f), glm::vec2(0.07, 0.15));
score_textures_gameOver.push_back(score_pointer);
}
game_over_texture = std::make_unique<gui::GuiTexture>(render_engine::loader::LoadTexture("res/game_over.png"), glm::vec2(0.0f, 0.6f), glm::vec2(0.50f, 0.50f));
end_score = score;
} }
gui::Button* ConvertGuiTextureToButtonGameOver(gui::GuiTexture* texture) { gui::Button* ConvertGuiTextureToButtonGameOver(gui::GuiTexture* texture) {
gui::Button* button; gui::Button* button;
if (texture != NULL) if (texture != NULL)
{ {
if (texture->GetType() == gui::GuiType::BUTTON) { if (texture->GetType() == gui::GuiType::BUTTON) {
button = (gui::Button*)texture; button = (gui::Button*)texture;
@@ -75,12 +90,13 @@ namespace scene
} }
scene::Scenes scene::Game_Over_Scene::start(GLFWwindow* window) { 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)); gui::Button button_start_scene(render_engine::loader::LoadTexture("res/Birb1.jpg"), glm::vec2(0.0f, -0.5f), glm::vec2(0.25f, 0.25f));
button_start_scene.SetHoverTexture(render_engine::loader::LoadTexture("res/Birb2.jpg")); 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.SetClickedTexture(render_engine::loader::LoadTexture("res/Birb3.jpg"));
button_start_scene.SetOnClickAction([]() button_start_scene.SetOnClickAction([]()
{ {
std::cout << "Back to start screen!!" << std::endl; std::cout << "Back to start screen!!" << std::endl;
}); });
guis_gameOver.push_back(&button_start_scene); guis_gameOver.push_back(&button_start_scene);
@@ -134,7 +150,7 @@ namespace scene
} }
} }
glfwSwapBuffers(window); glfwSwapBuffers(window);
glfwPollEvents(); glfwPollEvents();
} }
gui_shader_gameOver->CleanUp(); gui_shader_gameOver->CleanUp();
@@ -165,7 +181,10 @@ namespace scene
} }
bool hand_present; bool hand_present;
objDetect_gameOver.DetectHand(objDetect_gameOver.ReadCamera(), hand_present); objDetect_gameOver.DetectHand(objDetect_gameOver.ReadCamera(), hand_present);
}
render_engine::renderer::Render(game_over_texture, *gui_shader_gameOver);
DrawScore(end_score);
}
/** /**
* manages the key input in the start-up scene * manages the key input in the start-up scene
@@ -174,12 +193,26 @@ namespace scene
{ {
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
{ {
return_value = scene::Scenes::INGAME; return_value = scene::Scenes::STARTUP;
cv::destroyWindow("camera"); cv::destroyWindow("camera");
} }
else if (glfwGetKey(window, GLFW_KEY_BACKSPACE) == GLFW_PRESS) { else if (glfwGetKey(window, GLFW_KEY_BACKSPACE) == GLFW_PRESS) {
hand_mode_gameOver = !hand_mode_gameOver; hand_mode_gameOver = !hand_mode_gameOver;
} }
} }
void Game_Over_Scene::DrawScore(int score)
{
std::vector<int> digits;
score_guis_gameOver.clear();
toolbox::GetDigitsFromNumber(score, digits);
for (int i = digits.size() - 1; i >= 0; i--)
{
score_textures_gameOver[digits[i]].get()->position.x = (0.15 * i - 0.05);
render_engine::renderer::Render(score_textures_gameOver[digits[i]], *gui_shader_gameOver);
}
}
} }

View File

@@ -9,10 +9,15 @@ namespace scene
class Game_Over_Scene : public scene::Scene class Game_Over_Scene : public scene::Scene
{ {
private: private:
int end_score;
scene::Scenes return_value = scene::Scenes::GAMEOVER; scene::Scenes return_value = scene::Scenes::GAMEOVER;
std::vector<std::shared_ptr<gui::GuiTexture>> score_guis_gameOver;
std::shared_ptr<gui::GuiTexture> game_over_texture;
public: public:
Game_Over_Scene(); Game_Over_Scene(int score);
Scenes start(GLFWwindow* window) override; Scenes start(GLFWwindow* window) override;
@@ -21,6 +26,10 @@ namespace scene
void update(GLFWwindow* window) override; void update(GLFWwindow* window) override;
void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) override; 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);
}; };
} }

View File

@@ -46,6 +46,7 @@ namespace scene
int furniture_count_old; int furniture_count_old;
int score; int score;
int* ptr;
std::vector<computervision::HandDetectRegion> regions; std::vector<computervision::HandDetectRegion> regions;
computervision::HandDetectRegion reg_left("left", 0, 0, 150, 150), reg_right("right", 0, 0, 150, 150), reg_up("up", 0, 0, 150, 150); computervision::HandDetectRegion reg_left("left", 0, 0, 150, 150), reg_right("right", 0, 0, 150, 150), reg_up("up", 0, 0, 150, 150);
@@ -53,8 +54,9 @@ namespace scene
/** /**
* sets up the first things when the objects has been made * sets up the first things when the objects has been made
*/ */
In_Game_Scene::In_Game_Scene() In_Game_Scene::In_Game_Scene(int *score_ptr)
{ {
ptr = score_ptr;
camera = std::make_unique<entities::Camera>(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0)); camera = std::make_unique<entities::Camera>(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0));
shader = new shaders::EntityShader; shader = new shaders::EntityShader;
@@ -76,12 +78,7 @@ namespace scene
score_pointer = std::make_unique<gui::GuiTexture>(render_engine::loader::LoadTexture(texture_path), glm::vec2(-0.9f, 0.8f), glm::vec2(0.07, 0.15)); score_pointer = std::make_unique<gui::GuiTexture>(render_engine::loader::LoadTexture(texture_path), glm::vec2(-0.9f, 0.8f), glm::vec2(0.07, 0.15));
score_textures.push_back(score_pointer); score_textures.push_back(score_pointer);
std::cout << "Add to score_pointer: " << texture_path << std::endl;
} }
std::cout << "Size textures: " << score_textures.size() << std::endl;
} }
/** /**
@@ -275,11 +272,12 @@ namespace scene
//camera.Move(window); //camera.Move(window);
main_character->Move(window); main_character->Move(window);
if (!main_character.get()->GetOnCollide()) if (!main_character.get()->GetOnCollide())
{ {
*ptr = score;
std::cout << "Score: " << score << std::endl;
return_value = scene::Scenes::GAMEOVER; 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()); camera->Follow(main_character->GetPosition());
// calculate where the next house model should be loaded // calculate where the next house model should be loaded
@@ -301,8 +299,6 @@ namespace scene
collision::CheckCollisions(collision_entities); collision::CheckCollisions(collision_entities);
update_hand_detection(); update_hand_detection();
} }
//manages the key input in the game scene //manages the key input in the game scene

View File

@@ -30,7 +30,6 @@ namespace scene
PAUSED PAUSED
}; };
class In_Game_Scene : public scene::Scene class In_Game_Scene : public scene::Scene
{ {
private: private:
@@ -68,7 +67,7 @@ namespace scene
void update_hand_detection(); void update_hand_detection();
public: public:
In_Game_Scene(); In_Game_Scene(int *score_ptr);
~In_Game_Scene(); ~In_Game_Scene();
/** /**

View File

@@ -19,10 +19,11 @@ namespace scene {
}; };
class Scene class Scene
{ {
static int END_SCORE;
public: public:
virtual ~Scene() = 0; virtual ~Scene() = 0;
/** /**
* @brief the method start is the start of a scene where a while loop runs, this runs the scene. * @brief the method start is the start of a scene where a while loop runs, this runs the scene.
* @param window the main window of the application * @param window the main window of the application
@@ -54,7 +55,13 @@ namespace scene {
* @return void * @return void
*/ */
virtual void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) {}; virtual void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) {};
static void SetEndScore(int score) {
END_SCORE = score;
}
static int GetEndScore() {
return END_SCORE;
}
}; };
} }