Added music and jumpscares
This commit is contained in:
39
main.c
39
main.c
@@ -98,6 +98,11 @@ typedef struct
|
|||||||
int shouldExit;
|
int shouldExit;
|
||||||
Player player;
|
Player player;
|
||||||
int nearAcorn;
|
int nearAcorn;
|
||||||
|
int isJumpscared;
|
||||||
|
float jumpscareTimer;
|
||||||
|
|
||||||
|
Sound jumpScare;
|
||||||
|
Music bgm;
|
||||||
} Master;
|
} Master;
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------
|
||||||
@@ -155,6 +160,7 @@ int main(void)
|
|||||||
g.state = STATE_MENU;
|
g.state = STATE_MENU;
|
||||||
g.shouldExit = 0;
|
g.shouldExit = 0;
|
||||||
g.nearAcorn = 0;
|
g.nearAcorn = 0;
|
||||||
|
g.isJumpscared = 0;
|
||||||
|
|
||||||
//Define player values
|
//Define player values
|
||||||
g.player.sensitivity = (Vector2){ 0.001f, 0.001f };
|
g.player.sensitivity = (Vector2){ 0.001f, 0.001f };
|
||||||
@@ -320,6 +326,16 @@ int main(void)
|
|||||||
SetShaderValue(fog, locMinShadow, &minShadow, SHADER_UNIFORM_FLOAT);
|
SetShaderValue(fog, locMinShadow, &minShadow, SHADER_UNIFORM_FLOAT);
|
||||||
SetShaderValue(fog, locFogColor, &fogColor, SHADER_UNIFORM_VEC4);
|
SetShaderValue(fog, locFogColor, &fogColor, SHADER_UNIFORM_VEC4);
|
||||||
SetShaderValue(fog, locSharpness, &sharpness, SHADER_UNIFORM_FLOAT);
|
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
|
// Main game loop
|
||||||
@@ -401,8 +417,19 @@ int main(void)
|
|||||||
{
|
{
|
||||||
acorn_position.x = 15;
|
acorn_position.x = 15;
|
||||||
acorn_position.z = 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
|
// put near your update logic
|
||||||
float B = 122;
|
float B = 122;
|
||||||
float T = 1.0f; // wall half-thickness
|
float T = 1.0f; // wall half-thickness
|
||||||
@@ -476,6 +503,8 @@ int main(void)
|
|||||||
if (IsKeyDown(KEY_E)) wall_yaw += rotSpeed;
|
if (IsKeyDown(KEY_E)) wall_yaw += rotSpeed;
|
||||||
//
|
//
|
||||||
|
|
||||||
|
UpdateMusicStream(g.bgm);
|
||||||
|
|
||||||
UpdateCameraAngle(&g);
|
UpdateCameraAngle(&g);
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
@@ -548,6 +577,11 @@ int main(void)
|
|||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
|
if(g.isJumpscared == 1 | g.isJumpscared == 2)
|
||||||
|
{
|
||||||
|
DrawTextureEx(sign, (Vector2){700, 300}, /*rotation*/0.0f, /*scale*/50.0f, WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
// Draw info box
|
// Draw info box
|
||||||
DrawRectangle(5, 5, 330*1.5, 75*1.25, Fade(SKYBLUE, 0.5f));
|
DrawRectangle(5, 5, 330*1.5, 75*1.25, Fade(SKYBLUE, 0.5f));
|
||||||
DrawRectangleLines(5, 5, 330*1.5, 75*1.25, BLUE);
|
DrawRectangleLines(5, 5, 330*1.5, 75*1.25, BLUE);
|
||||||
@@ -589,6 +623,11 @@ int main(void)
|
|||||||
UnloadModel(wall);
|
UnloadModel(wall);
|
||||||
UnloadModel(acorn);
|
UnloadModel(acorn);
|
||||||
|
|
||||||
|
UnloadSound(g.jumpScare);
|
||||||
|
StopMusicStream(g.bgm);
|
||||||
|
UnloadMusicStream(g.bgm);
|
||||||
|
CloseAudioDevice();
|
||||||
|
|
||||||
CloseWindow(); // Close window and OpenGL context
|
CloseWindow(); // Close window and OpenGL context
|
||||||
//--------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
BIN
resources/music/background.mp3
Normal file
BIN
resources/music/background.mp3
Normal file
Binary file not shown.
BIN
resources/sound_effects/fnaf.mp3
Normal file
BIN
resources/sound_effects/fnaf.mp3
Normal file
Binary file not shown.
BIN
resources/sound_effects/fnaf.wav
Normal file
BIN
resources/sound_effects/fnaf.wav
Normal file
Binary file not shown.
Reference in New Issue
Block a user