diff --git a/main.c b/main.c index 395bdad..b7267c2 100644 --- a/main.c +++ b/main.c @@ -98,6 +98,11 @@ typedef struct int shouldExit; Player player; int nearAcorn; + int isJumpscared; + float jumpscareTimer; + + Sound jumpScare; + Music bgm; } Master; //------------------------------------------------------------------------------------ @@ -155,6 +160,7 @@ int main(void) g.state = STATE_MENU; g.shouldExit = 0; g.nearAcorn = 0; + g.isJumpscared = 0; //Define player values g.player.sensitivity = (Vector2){ 0.001f, 0.001f }; @@ -320,6 +326,16 @@ int main(void) SetShaderValue(fog, locMinShadow, &minShadow, SHADER_UNIFORM_FLOAT); SetShaderValue(fog, locFogColor, &fogColor, SHADER_UNIFORM_VEC4); SetShaderValue(fog, locSharpness, &sharpness, SHADER_UNIFORM_FLOAT); + + //Music and audio + InitAudioDevice(); + + g.jumpScare = LoadSound("resources/sound_effects/fnaf.wav"); + SetSoundVolume(g.jumpScare, 0.8); + + g.bgm = LoadMusicStream("resources/music/background.mp3"); + SetMusicVolume(g.bgm, 0.4f); + PlayMusicStream(g.bgm); //-------------------------------------------------------------------------------------- // Main game loop @@ -401,8 +417,19 @@ int main(void) { acorn_position.x = 15; acorn_position.z = 15; + + g.isJumpscared = 1; + g.jumpscareTimer = 5.0f; // show overlay for 1s + PlaySound(g.jumpScare); // <-- trigger ONCE here } + if (g.isJumpscared == 1) + { + g.jumpscareTimer -= GetFrameTime(); + if (g.jumpscareTimer <= 0.0f) g.isJumpscared = 0; + } + + // put near your update logic float B = 122; float T = 1.0f; // wall half-thickness @@ -476,6 +503,8 @@ int main(void) if (IsKeyDown(KEY_E)) wall_yaw += rotSpeed; // + UpdateMusicStream(g.bgm); + UpdateCameraAngle(&g); break; }; @@ -546,7 +575,12 @@ int main(void) // Restore opaque cutoff for anything else you draw with that material later SetShaderValue(fog, locCutoff_fog, &cutoffOpaque, SHADER_UNIFORM_FLOAT); - EndMode3D(); + EndMode3D(); + + if(g.isJumpscared == 1 | g.isJumpscared == 2) + { + DrawTextureEx(sign, (Vector2){700, 300}, /*rotation*/0.0f, /*scale*/50.0f, WHITE); + } // Draw info box DrawRectangle(5, 5, 330*1.5, 75*1.25, Fade(SKYBLUE, 0.5f)); @@ -588,6 +622,11 @@ int main(void) UnloadTexture(sign); UnloadModel(wall); UnloadModel(acorn); + + UnloadSound(g.jumpScare); + StopMusicStream(g.bgm); + UnloadMusicStream(g.bgm); + CloseAudioDevice(); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/resources/music/background.mp3 b/resources/music/background.mp3 new file mode 100644 index 0000000..d0de1c9 Binary files /dev/null and b/resources/music/background.mp3 differ diff --git a/resources/sound_effects/fnaf.mp3 b/resources/sound_effects/fnaf.mp3 new file mode 100644 index 0000000..8fad1c0 Binary files /dev/null and b/resources/sound_effects/fnaf.mp3 differ diff --git a/resources/sound_effects/fnaf.wav b/resources/sound_effects/fnaf.wav new file mode 100644 index 0000000..aac356d Binary files /dev/null and b/resources/sound_effects/fnaf.wav differ