diff --git a/res/background_grey.png b/res/background_grey.png new file mode 100644 index 0000000..d32155f Binary files /dev/null and b/res/background_grey.png differ diff --git a/src/main.cpp b/src/main.cpp index 7300b1b..f0e7f94 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -63,7 +63,7 @@ int main(void) current_scene->onKey(window, key, scancode, action, mods); }); - + bool window_open = true; diff --git a/src/scenes/in_Game_Scene.cpp b/src/scenes/in_Game_Scene.cpp index 0e7c268..6c61674 100644 --- a/src/scenes/in_Game_Scene.cpp +++ b/src/scenes/in_Game_Scene.cpp @@ -14,18 +14,13 @@ namespace scene { - std::vector entities; - std::vector lights; - models::RawModel raw_model; - models::ModelTexture texture; - shaders::EntityShader *shader; - shaders::GuiShader *gui_shader; - entities::Camera camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0)); - std::vector guis; - - + /** + * sets up the first things when the objects has been made + */ In_Game_Scene::In_Game_Scene() { + camera = new entities::Camera(glm::vec3(0, 0, 0), glm::vec3(0, 0, 0)); + shader = new shaders::EntityShader; shader->Init(); render_engine::renderer::Init(*shader); @@ -33,7 +28,19 @@ namespace scene gui_shader = new shaders::GuiShader(); gui_shader->Init(); } + /** + * deletes certain veriables when the object will be deleted, prevents memory leaks + */ + In_Game_Scene::~In_Game_Scene() + { + delete camera; + delete shader; + delete gui_shader; + } + /** + * starts the game scene, calls the render and update methods in a while loop + */ scene::Scenes scene::In_Game_Scene::start(GLFWwindow* window) { raw_model = render_engine::LoadObjModel("res/House.obj"); @@ -45,7 +52,7 @@ namespace scene int z = 0; for (int i = 0; i < 5; ++i) { - entities.push_back(entities::Entity(model, glm::vec3(0, -50, -50 - z), glm::vec3(0, 90, 0), 20)); + entities_to_render.push_back(entities::Entity(model, glm::vec3(0, -50, -50 - z), glm::vec3(0, 90, 0), 20)); z += (raw_model.model_size.x * 20); } @@ -54,7 +61,7 @@ namespace scene lights.push_back(entities::Light(glm::vec3(0, 0, -200), glm::vec3(0, 2, 0), glm::vec3(0.0001f, 0.0001f, 0.0001f))); // GUI stuff - gui::Button button(render_engine::loader::LoadTexture("res/Mayo.png"), glm::vec2(0.5f, 0.0f), glm::vec2(0.25f, 0.25f)); + gui::Button button(render_engine::loader::LoadTexture("res/Mayo.png"), glm::vec2(0.5f, 0.0f), glm::vec2(1, 1)); button.SetHoverTexture(render_engine::loader::LoadTexture("res/Texture.png")); button.SetClickedTexture(render_engine::loader::LoadTexture("res/Mayo.png")); button.SetOnClickAction([]() @@ -64,11 +71,54 @@ namespace scene guis.push_back(&button); + //guis for the pause menu + gui::GuiTexture background(render_engine::loader::LoadTexture("res/background_grey.png"), glm::vec2(0, 0), glm::vec2(1, 1)); + pause_guis.push_back(&background); + + gui::Button pause_button_resume(render_engine::loader::LoadTexture("res/Mayo.png"), glm::vec2(0, 0), glm::vec2(0.25f, 0.25f)); + pause_button_resume.SetHoverTexture(render_engine::loader::LoadTexture("res/Texture.png")); + pause_button_resume.SetClickedTexture(render_engine::loader::LoadTexture("res/Mayo.png")); + pause_button_resume.SetOnClickAction([]() + { + std::cout << "I got clicked on the resume button!" << std::endl; + }); + pause_guis.push_back(&pause_button_resume); + + gui::Button pause_button_quit(render_engine::loader::LoadTexture("res/Mayo.png"), glm::vec2(0.3f, 0.0f), glm::vec2(0.25f, 0.25f)); + pause_button_quit.SetHoverTexture(render_engine::loader::LoadTexture("res/Texture.png")); + pause_button_quit.SetClickedTexture(render_engine::loader::LoadTexture("res/Mayo.png")); + pause_button_quit.SetOnClickAction([]() + { + std::cout << "I got clicked on the quit button!" << std::endl; + }); + pause_guis.push_back(&pause_button_quit); + + + //the scene loop, this while loop represent the scene while (return_value == scene::Scenes::INGAME) { - update(window); - button.Update(window); - render(); + //checks the current game state, so it can render the correct models for each state + switch (game_state) + { + /*case scene::Game_State::IDLE: + break;*/ + + case scene::Game_State::PAUSED: + render(); + render_pause_menu(); + break; + + case scene::Game_State::RUNNING: + update(window); + button.Update(window); + render(); + break; + + default: + std::cout << "Game state unknown" << std::endl; + break; + } + glfwSwapBuffers(window); glfwPollEvents(); @@ -79,40 +129,58 @@ namespace scene return return_value; } + /** + * renders the game models + */ void scene::In_Game_Scene::render() { // Render render_engine::renderer::Prepare(); - + //starts the shader and begins to render shader->Start(); shader->LoadSkyColor(render_engine::renderer::SKY_COLOR); shader->LoadLights(lights); - shader->LoadViewMatrix(camera); + shader->LoadViewMatrix(*camera); // Renders each entity in the entities list - for (entities::Entity& entity : entities) + for (entities::Entity& entity : entities_to_render) { render_engine::renderer::Render(entity, *shader); } // Render GUI items - render_engine::renderer::Render(guis, *gui_shader); + //render_engine::renderer::Render(guis, *gui_shader); // Stop rendering the entities shader->Stop(); } + //updates certain variables void scene::In_Game_Scene::update(GLFWwindow* window) { - camera.Move(window); + camera->Move(window); } + //renders the models for the pause menu + void In_Game_Scene::render_pause_menu() + { + render_engine::renderer::Render(pause_guis, *gui_shader); + } + + //manages the key input in the game scene void scene::In_Game_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods) { if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) { return_value = scene::Scenes::STOP; } + if (glfwGetKey(window, GLFW_KEY_P) == GLFW_PRESS) + { + game_state = scene::Game_State::PAUSED; + } + if (glfwGetKey(window, GLFW_KEY_O) == GLFW_PRESS) + { + game_state = scene::Game_State::RUNNING; + } } - } diff --git a/src/scenes/in_Game_Scene.h b/src/scenes/in_Game_Scene.h index 4581855..e3b1812 100644 --- a/src/scenes/in_Game_Scene.h +++ b/src/scenes/in_Game_Scene.h @@ -1,20 +1,100 @@ #pragma once +#include +#include +#include #include "scene.h" +#include "../gui/gui_interactable.h" +#include "../models/model.h" +#include "../renderEngine/loader.h" +#include "../renderEngine/obj_loader.h" +#include "../renderEngine/renderer.h" +#include "../shaders/entity_shader.h" +#include "../toolbox/toolbox.h" + namespace scene { + /** + * This enum is for managing the game scene state. + * for example: when pressed on a specific button, the game will be in a paused state and nothing about the player or the speed of the game will be updated + * and the pause screen will show up. + **/ + enum class Game_State + { + //IDLE, + RUNNING, + PAUSED + }; + class In_Game_Scene : public scene::Scene { private: + //return_value is an enum that is necessary for the scene switching. Whenever this changes, the scene will change to a different scene. scene::Scenes return_value = scene::Scenes::INGAME; + //game_state is an enum that keeps track of the current game state. For example: is the game running(thus the user is playing the game) of is the game paused. + scene::Game_State game_state = scene::Game_State::RUNNING; + + //entities_to_render is a list of entities, those entities will be rendered in the 3D environment. + std::vector entities_to_render; + //lights is a lost of light points in the game, for example the sun or it can be used to attach light effects to lamps. + std::vector lights; + + models::RawModel raw_model; + models::ModelTexture texture; + //the shader that is used for rendering the models. + shaders::EntityShader* shader; + //the gui_shader is used of rendering the gui models (for example the pause buttons). + shaders::GuiShader* gui_shader; + //camera is the camera view of the game scene, this camera will be behind the main character. + entities::Camera *camera; + //guis is a list of all the gui components that needs to be load in the scene. + std::vector guis; + //pause_guis is a list of components that will be rendered when the game is paused. + std::vector pause_guis; + + /** + * @brief renders the objects/gui models + * @param + * @return void + */ + void render_pause_menu(); + public: In_Game_Scene(); + ~In_Game_Scene(); + /** + * @brief the method start is the start of the scene where a while loop runs, this runs the scene. + * @param window the main window of the application + * @return Scene value that indicates in which scene the application is + */ Scenes start(GLFWwindow* window) override; + + /** + * @brief this method renders the models for the game scene + * @param + * @return void + */ void render() override; + + /** + * @brief this method updates the models/variables for the game scene + * @param window the main window of the application + * @return void + */ void update(GLFWwindow* window) override; + + /** + * @brief this method updates the models/variables for the game scene + * @param window the main window of the application + * @param key this is the keycode on which key has been pressed + * @param scancode - + * @param action- + * @param mods - + * @return void + */ void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) override; }; } diff --git a/src/scenes/scene.cpp b/src/scenes/scene.cpp new file mode 100644 index 0000000..12f4435 --- /dev/null +++ b/src/scenes/scene.cpp @@ -0,0 +1,7 @@ +#include +#include "scene.h" + +scene::Scene::~Scene() +{ + std::cout << "Main scene class gone!" << std::endl; +} diff --git a/src/scenes/scene.h b/src/scenes/scene.h index a4d07bd..4db2fe5 100644 --- a/src/scenes/scene.h +++ b/src/scenes/scene.h @@ -6,6 +6,9 @@ namespace scene { + /** + * this enum represents the scenes in the game, those wil help to keep track in which scene the game is. + */ enum class Scenes { STARTUP, @@ -18,14 +21,40 @@ namespace scene { class Scene { public: + virtual ~Scene() = 0; + + /** + * @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 + * @return Scene value that indicates in which scene the application is + */ virtual Scenes start(GLFWwindow* window) = 0; + + /** + * @brief this method renders the models for a scene + * @param + * @return void + */ virtual void render() = 0; + + /** + * @brief this method updates the models/variables for a scene + * @param window the main window of the application + * @return void + */ virtual void update(GLFWwindow* window) = 0; + + /** + * @brief this method updates the models/variables for a scene + * @param window the main window of the application + * @param key this is the keycode on which key has been pressed + * @param scancode - + * @param action- + * @param mods - + * @return void + */ virtual void onKey(GLFWwindow* window, int key, int scancode, int action, int mods) {}; - }; - - } diff --git a/src/scenes/startup_Scene.cpp b/src/scenes/startup_Scene.cpp index 61da1f5..30f9c35 100644 --- a/src/scenes/startup_Scene.cpp +++ b/src/scenes/startup_Scene.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -164,6 +165,9 @@ namespace scene return return_value; } + /** + * renders the models in the start-up scene + */ void scene::Startup_Scene::render() { render_engine::renderer::Prepare(); @@ -172,6 +176,9 @@ namespace scene render_engine::renderer::Render(guis1, *gui_shader1); } + /** + * updates the variables for the start-up scene + */ void scene::Startup_Scene::update(GLFWwindow* window) { for (gui::GuiTexture* button : guis1) { @@ -181,6 +188,9 @@ namespace scene } } + /** + * manages the key input in the start-up scene + */ void scene::Startup_Scene::onKey(GLFWwindow* window, int key, int scancode, int action, int mods) { if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS) diff --git a/src/scenes/startup_Scene.h b/src/scenes/startup_Scene.h index 789f7c5..b38fb39 100644 --- a/src/scenes/startup_Scene.h +++ b/src/scenes/startup_Scene.h @@ -9,6 +9,7 @@ namespace scene class Startup_Scene : public scene::Scene { private: + //return_value is an enum that is necessary for the scene switching. Whenever this changes, the scene will change to a different scene. scene::Scenes return_value = scene::Scenes::STARTUP; public: diff --git a/wk2_fps.vcxproj b/wk2_fps.vcxproj index 58608cf..0033037 100644 --- a/wk2_fps.vcxproj +++ b/wk2_fps.vcxproj @@ -35,6 +35,7 @@ + diff --git a/wk2_fps.vcxproj.filters b/wk2_fps.vcxproj.filters index d21165d..eb6010f 100644 --- a/wk2_fps.vcxproj.filters +++ b/wk2_fps.vcxproj.filters @@ -78,6 +78,9 @@ Source Files + + Source Files +