[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/startup_Scene.h"
#include "scenes/game_Over_Scene.h"
#include "entities/collision_entity.h"
#include "computervision/ObjectDetection.h"
//#include "computervision/OpenPoseImage.h"
@@ -39,6 +40,7 @@
#pragma comment(lib, "glew32s.lib")
#pragma comment(lib, "opengl32.lib")
int score;
static double UpdateDelta();
static GLFWwindow* window;
@@ -73,7 +75,8 @@ int main(void)
glGetError();
#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();
glfwSetKeyCallback(window, [](GLFWwindow* window, int key, int scancode, int action, int mods)
@@ -88,8 +91,6 @@ int main(void)
bool window_open = true;
// Main game loop
while (!glfwWindowShouldClose(window) && window_open)
{
@@ -110,11 +111,11 @@ int main(void)
case scene::Scenes::INGAME:
current_scene = new scene::In_Game_Scene();
current_scene = new scene::In_Game_Scene(&score);
break;
case scene::Scenes::GAMEOVER:
current_scene = new scene::Game_Over_Scene();
current_scene = new scene::Game_Over_Scene(score);
break;
default:

View File

@@ -22,12 +22,12 @@ namespace scene
shaders::GuiShader* gui_shader_gameOver;
std::vector<gui::GuiTexture*> guis_gameOver;
computervision::ObjectDetection objDetect_gameOver;
std::vector<std::shared_ptr<gui::GuiTexture>> score_textures_gameOver;
float item_number_gameOver = 0;
bool hand_mode_gameOver = false;
Game_Over_Scene::Game_Over_Scene()
Game_Over_Scene::Game_Over_Scene(int score)
{
shaders::EntityShader shader;
shader.Init();
@@ -36,13 +36,28 @@ namespace scene
gui_shader_gameOver = new shaders::GuiShader();
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* button;
if (texture != NULL)
{
if (texture->GetType() == gui::GuiType::BUTTON) {
button = (gui::Button*)texture;
@@ -75,12 +90,13 @@ namespace scene
}
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.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);
@@ -165,6 +181,9 @@ namespace scene
}
bool hand_present;
objDetect_gameOver.DetectHand(objDetect_gameOver.ReadCamera(), hand_present);
render_engine::renderer::Render(game_over_texture, *gui_shader_gameOver);
DrawScore(end_score);
}
/**
@@ -174,7 +193,7 @@ namespace scene
{
if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
{
return_value = scene::Scenes::INGAME;
return_value = scene::Scenes::STARTUP;
cv::destroyWindow("camera");
}
else if (glfwGetKey(window, GLFW_KEY_BACKSPACE) == GLFW_PRESS) {
@@ -182,4 +201,18 @@ namespace scene
}
}
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
{
private:
int end_score;
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:
Game_Over_Scene();
Game_Over_Scene(int score);
Scenes start(GLFWwindow* window) override;
@@ -21,6 +26,10 @@ namespace scene
void update(GLFWwindow* window) 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 score;
int* ptr;
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);
@@ -53,8 +54,9 @@ namespace scene
/**
* 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));
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_textures.push_back(score_pointer);
std::cout << "Add to score_pointer: " << texture_path << std::endl;
}
std::cout << "Size textures: " << score_textures.size() << std::endl;
}
/**
@@ -276,10 +273,11 @@ namespace scene
main_character->Move(window);
if (!main_character.get()->GetOnCollide())
{
*ptr = score;
std::cout << "Score: " << score << std::endl;
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());
// calculate where the next house model should be loaded
@@ -301,8 +299,6 @@ namespace scene
collision::CheckCollisions(collision_entities);
update_hand_detection();
}
//manages the key input in the game scene

View File

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

View File

@@ -20,6 +20,7 @@ namespace scene {
class Scene
{
static int END_SCORE;
public:
virtual ~Scene() = 0;
@@ -54,7 +55,13 @@ namespace scene {
* @return void
*/
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;
}
};
}