Skip to content

Commit

Permalink
Final Version
Browse files Browse the repository at this point in the history
  • Loading branch information
boiled-fish committed Dec 7, 2023
1 parent 2a5f7b6 commit 93c5f02
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 41 deletions.
8 changes: 4 additions & 4 deletions Configs/game_logic_config.json
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions Configs/game_logic_config_GL.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"GameTime": 3000,
"FreddyDeathDistance" : 20.0,
"BunnyShowTime": 150,
"BunnyShowRate": 6,
"BunnyReactTime": 60,
"SpeedIncreaseRate": 5.0
}
8 changes: 8 additions & 0 deletions Configs/game_logic_config_VR.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"GameTime": 1200,
"FreddyDeathDistance" : 20.0,
"BunnyShowTime": 150,
"BunnyShowRate": 6,
"BunnyReactTime": 60,
"SpeedIncreaseRate": 5.0
}
77 changes: 46 additions & 31 deletions src/FNAF-Game/Game/Game.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "Game.h"
#include "Game/GlobalObjects.h"
#include "Objects/LightManager.h"

void Game::Init()
{
Expand All @@ -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;
Expand All @@ -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()
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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++;

Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -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;
Expand All @@ -196,6 +213,7 @@ void Game::UpdateDynamicStep(float deltaTime)
} else {
WinCase(deltaTime);
}
return;
} else {
GeneraCase(deltaTime);
}
Expand All @@ -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()
Expand Down
14 changes: 11 additions & 3 deletions src/FNAF-Game/Game/GameScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
10 changes: 9 additions & 1 deletion src/FNAF-Game/Game/GlobalObjects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion src/FNAF-Game/Objects/Pawn.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/FNAF-Game/Window/DrawGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 93c5f02

Please sign in to comment.