From 93c5f0228ce8c4f412e16ae6058ef1884f553b9b Mon Sep 17 00:00:00 2001 From: boiled-fish Date: Thu, 7 Dec 2023 16:20:00 -0500 Subject: [PATCH] Final Version --- Configs/game_logic_config.json | 8 ++-- Configs/game_logic_config_GL.json | 8 ++++ Configs/game_logic_config_VR.json | 8 ++++ src/FNAF-Game/Game/Game.cpp | 77 ++++++++++++++++++------------ src/FNAF-Game/Game/GameScene.cpp | 14 ++++-- src/FNAF-Game/Game/GlobalObjects.h | 10 +++- src/FNAF-Game/Objects/Pawn.h | 2 +- src/FNAF-Game/Window/DrawGui.cpp | 3 +- 8 files changed, 89 insertions(+), 41 deletions(-) create mode 100644 Configs/game_logic_config_GL.json create mode 100644 Configs/game_logic_config_VR.json diff --git a/Configs/game_logic_config.json b/Configs/game_logic_config.json index 7b70bc2..c6ed8df 100644 --- a/Configs/game_logic_config.json +++ b/Configs/game_logic_config.json @@ -1,8 +1,8 @@ { - "GameTime": 8000, - "FreddyDeathDistance" : -10.0, - "BunnyShowTime": 150, - "BunnyShowRate": 6, + "GameTime": 1300, + "FreddyDeathDistance" : 20.0, + "BunnyShowTime": 60, + "BunnyShowRate": 4, "BunnyReactTime": 60, "SpeedIncreaseRate": 5.0 } \ No newline at end of file diff --git a/Configs/game_logic_config_GL.json b/Configs/game_logic_config_GL.json new file mode 100644 index 0000000..bc33423 --- /dev/null +++ b/Configs/game_logic_config_GL.json @@ -0,0 +1,8 @@ +{ + "GameTime": 3000, + "FreddyDeathDistance" : 20.0, + "BunnyShowTime": 150, + "BunnyShowRate": 6, + "BunnyReactTime": 60, + "SpeedIncreaseRate": 5.0 +} \ No newline at end of file diff --git a/Configs/game_logic_config_VR.json b/Configs/game_logic_config_VR.json new file mode 100644 index 0000000..b8e5d68 --- /dev/null +++ b/Configs/game_logic_config_VR.json @@ -0,0 +1,8 @@ +{ + "GameTime": 1200, + "FreddyDeathDistance" : 20.0, + "BunnyShowTime": 150, + "BunnyShowRate": 6, + "BunnyReactTime": 60, + "SpeedIncreaseRate": 5.0 +} \ No newline at end of file diff --git a/src/FNAF-Game/Game/Game.cpp b/src/FNAF-Game/Game/Game.cpp index 0e09b42..30fa6d5 100644 --- a/src/FNAF-Game/Game/Game.cpp +++ b/src/FNAF-Game/Game/Game.cpp @@ -1,6 +1,5 @@ #include "Game.h" #include "Game/GlobalObjects.h" -#include "Objects/LightManager.h" void Game::Init() { @@ -15,15 +14,17 @@ void Game::Init() Scene::gBunny.mStatus.active = false; Scene::EndTitleShow = false; - bool freddy_stop_flag = 0; - bool bunny_show_flag = 1; - int bunny_hold_count = 0; - int game_time_count = 0; - + Scene::freddy_stop_flag = 0; + Scene::bunny_show_flag = 1; + Scene::bunny_hold_count = 0; + Scene::game_time_count = 0; + Scene::rate = 1.f; + Scene::gFreddy.mStatus.speed = Scene::freddy_ini_speed; } void Game::InitGameStart() { + JsonConfig::LoadConfig(R"(Configs\vr_ini_config.json)"); LightManager::use_flash_light = false; Scene::is_game_over = false; Scene::game_result = false; @@ -32,10 +33,12 @@ void Game::InitGameStart() Scene::gBunny.mStatus.active = true; Scene::EndTitleShow = false; - bool freddy_stop_flag = 0; - bool bunny_show_flag = 1; - int bunny_hold_count = 0; - int game_time_count = 0; + Scene::freddy_stop_flag = 0; + Scene::bunny_show_flag = 0; + Scene::bunny_hold_count = 0; + Scene::game_time_count = 0; + Scene::rate = 1.f; + Scene::gFreddy.mStatus.speed = Scene::freddy_ini_speed; } void Game::StartScene() @@ -49,24 +52,15 @@ void Game::EndScene(float deltaTime) void Game::GeneraCase(float deltaTime) { - if ((Scene::gControllerState.squeezeClick_left || Scene::key_flash_light) && Scene::freddy_stop_flag == 0) { - Scene::freddy_stop_flag = 1; - Scene::gFreddy.mStatus.active = false; - if (Scene::gFreddy.mStatus.shock_level <= SHOCK_LEVEL_MAX) { - Scene::gFreddy.mStatus.shock_level++; - Scene::rate = (float)Scene::gFreddy.mStatus.shock_level / Scene::game_loop_config.speed_increase_rate; - Scene::gFreddy.mStatus.speed = Scene::freddy_ini_speed * (1.f + Scene::rate); - } + if ((Scene::gControllerState.squeezeClick_left || Scene::key_flash_light)) { + Scene::rate += Scene::bright_a * deltaTime; LightManager::use_flash_light = true; - } else if ((Scene::gControllerState.squeezeClick_left || Scene::key_flash_light) && Scene::freddy_stop_flag == 1) { - // do nothing - } else if ((!Scene::gControllerState.squeezeClick_left || !Scene::key_flash_light) && Scene::freddy_stop_flag == 1) { - Scene::freddy_stop_flag = 0; - Scene::gFreddy.mStatus.active = true; - LightManager::use_flash_light = false; } else { - Scene::gFreddy.Move(deltaTime, glm::vec3(0.f, 0.f, 1.f)); + Scene::rate += Scene::dark_a * deltaTime; + LightManager::use_flash_light = false; } + Scene::gFreddy.mStatus.speed = Scene::freddy_ini_speed + Scene::rate; + Scene::gFreddy.Move(deltaTime, glm::vec3(0.f, 0.f, 1.f)); if (Scene::gFreddy.mTranslation.z >= Scene::game_loop_config.freddy_death_distance) { Scene::is_game_over = true; @@ -125,7 +119,7 @@ void Game::DeadCase(float deltaTime) static int dead_scene_count = 0; if ((Scene::gControllerState.squeezeClick_left || Scene::key_flash_light)) { dead_scene_count++; - if (dead_scene_count > 30) { + if (dead_scene_count > 60) { dead_scene_count = 0; Scene::is_game_over = false; Scene::is_game_started = false; @@ -135,6 +129,17 @@ void Game::DeadCase(float deltaTime) } else { dead_scene_count = 0; } + + static int exit_count = 0; + if (Scene::gControllerState.squeezeClick_right) { + exit_count++; + if (exit_count > 30) { + exit_count = 0; + exit(0); + } + } else { + exit_count = 0; + } } light_off_count++; @@ -152,7 +157,7 @@ void Game::WinCase(float deltaTime) static int win_scene_count = 0; if ((Scene::gControllerState.squeezeClick_left || Scene::key_flash_light)) { win_scene_count++; - if (win_scene_count > 30) { + if (win_scene_count > 60) { win_scene_count = 0; win_sequence_restart = true; Scene::is_game_over = false; @@ -169,10 +174,23 @@ void Game::WinCase(float deltaTime) } else { LightManager::LightSequenceSuccess(deltaTime); } + + static int exit_count = 0; + if (Scene::gControllerState.squeezeClick_right) { + exit_count++; + if (exit_count > 30) { + exit_count = 0; + exit(0); + } + } else { + exit_count = 0; + } } void Game::UpdateDynamicStep(float deltaTime) { + Scene::camera->Move(deltaTime); + static int start_scene_count = 0; if (!Scene::is_game_started) { StartScene(); @@ -182,7 +200,6 @@ void Game::UpdateDynamicStep(float deltaTime) start_scene_count = 0; Scene::is_game_started = true; InitGameStart(); - return; } } else { start_scene_count = 0; @@ -196,6 +213,7 @@ void Game::UpdateDynamicStep(float deltaTime) } else { WinCase(deltaTime); } + return; } else { GeneraCase(deltaTime); } @@ -206,10 +224,7 @@ void Game::UpdateDynamicStep(float deltaTime) Scene::game_time_count = 0; Scene::is_game_over = true; Scene::game_result = true; - return; } - - Scene::camera->Move(deltaTime); } void Game::UpdateFixedStep() diff --git a/src/FNAF-Game/Game/GameScene.cpp b/src/FNAF-Game/Game/GameScene.cpp index ae76f6c..29eb5b9 100644 --- a/src/FNAF-Game/Game/GameScene.cpp +++ b/src/FNAF-Game/Game/GameScene.cpp @@ -182,22 +182,30 @@ void GameScene::Idle() prev_time_sec = time_sec; time_passed += dt; + static float mesh_start_time; + + if (!Scene::is_game_started) mesh_start_time = 0.0f; + if (Scene::is_game_started && mesh_start_time == 0.0f) { + mesh_start_time = time_sec; + } + float mesh_time_sec = time_sec - mesh_start_time; + // gMapMesh->Update(time_sec); if (!Scene::gFreddy.mStatus.active) { gFreddy.mMesh->Update(0); } else { - gFreddy.mMesh->Update(time_sec * (1.f + Scene::rate)); + gFreddy.mMesh->Update(mesh_time_sec * Scene::rate); } if (!Scene::gBunny.mStatus.active) { gBunny.mMesh->Update(0); } else { - gBunny.mMesh->Update(time_sec); + gBunny.mMesh->Update(mesh_time_sec); } - StaticMesh::sShader()->setUniform("time", time_sec); + //StaticMesh::sShader()->setUniform("time", time_sec); // Pawn } diff --git a/src/FNAF-Game/Game/GlobalObjects.h b/src/FNAF-Game/Game/GlobalObjects.h index a860e6d..0cbf7c0 100644 --- a/src/FNAF-Game/Game/GlobalObjects.h +++ b/src/FNAF-Game/Game/GlobalObjects.h @@ -108,7 +108,7 @@ inline bool is_game_started = false; inline bool is_game_over = false; inline float freddy_ini_speed = 0.6f; -inline float rate = (float)Scene::gFreddy.mStatus.shock_level / 5.f; +inline float rate = 1.f; struct gameLoopConfig { int game_time; @@ -130,4 +130,12 @@ inline int bunny_death_count = 0; constexpr int bunny_clear_time = 60; // frames inline int game_time_count; inline int EndTitleShow; + +// GL speed +inline float dark_a = 0.65f; +inline float bright_a = 0.3f; + +// VR Speed +inline float dark_a_VR = 0.65f; +inline float bright_a_VR = 0.3f; } diff --git a/src/FNAF-Game/Objects/Pawn.h b/src/FNAF-Game/Objects/Pawn.h index a2a0b31..c7dd224 100644 --- a/src/FNAF-Game/Objects/Pawn.h +++ b/src/FNAF-Game/Objects/Pawn.h @@ -8,7 +8,7 @@ #include "SkinnedMesh.h" #include "AIComponent.h" -#define SHOCK_LEVEL_MIN 1 +#define SHOCK_LEVEL_MIN 5 #define SHOCK_LEVEL_MAX 20 class Pawn { diff --git a/src/FNAF-Game/Window/DrawGui.cpp b/src/FNAF-Game/Window/DrawGui.cpp index 71c00c0..1a7090a 100644 --- a/src/FNAF-Game/Window/DrawGui.cpp +++ b/src/FNAF-Game/Window/DrawGui.cpp @@ -29,7 +29,7 @@ void Display(GLFWwindow* window) ImGui_ImplGlfw_NewFrame(); ImGui::NewFrame(); - static bool show_debug_window = true; + static bool show_debug_window = false; static bool show_capture_options = false; static bool show_imgui_test = false; static bool show_spotlight_manager = false; @@ -122,6 +122,7 @@ void Display(GLFWwindow* window) // ImGui::RadioButton("Debug", &mode, 2); // // glUniform1i(SkinnedMesh::UniformLoc::Mode, mode); + ImGui::Text("Rate: <%.2f>", Scene::rate); ImGui::End(); }