Added music and jumpscares

This commit is contained in:
2025-09-13 21:17:56 -05:00
parent 27b2ee70d1
commit 3af24e812f
4 changed files with 40 additions and 1 deletions

39
main.c
View File

@@ -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;
};
@@ -548,6 +577,11 @@ int main(void)
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));
DrawRectangleLines(5, 5, 330*1.5, 75*1.25, BLUE);
@@ -589,6 +623,11 @@ int main(void)
UnloadModel(wall);
UnloadModel(acorn);
UnloadSound(g.jumpScare);
StopMusicStream(g.bgm);
UnloadMusicStream(g.bgm);
CloseAudioDevice();
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;

Binary file not shown.

Binary file not shown.

Binary file not shown.