Commit 61af3c7b authored by Benjamin LEROUX's avatar Benjamin LEROUX

ajout bande son

parent 4ebd12c1
...@@ -69,6 +69,9 @@ static int highscore; ...@@ -69,6 +69,9 @@ static int highscore;
static Sound fruitSound ; static Sound fruitSound ;
static Sound goldenFruitSound; static Sound goldenFruitSound;
static Sound deathSound; static Sound deathSound;
static Music music;
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Module Functions Declaration (local) // Module Functions Declaration (local)
...@@ -89,7 +92,11 @@ int main(void) ...@@ -89,7 +92,11 @@ int main(void)
InitWindow(screenWidth, screenHeight, "sample game: snake"); InitWindow(screenWidth, screenHeight, "sample game: snake");
InitGame(); InitGame();
InitAudioDevice(); // Initialize audio device InitAudioDevice(); // Initialize audio device
StopMusicStream(music);
PlayMusicStream(music);
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 0, 1); emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
...@@ -150,6 +157,7 @@ void InitGame(void) ...@@ -150,6 +157,7 @@ void InitGame(void)
snakePosition[i] = (Vector2){ 0.0f, 0.0f }; snakePosition[i] = (Vector2){ 0.0f, 0.0f };
} }
//fruits
fruit.size = (Vector2){ SQUARE_SIZE, SQUARE_SIZE }; fruit.size = (Vector2){ SQUARE_SIZE, SQUARE_SIZE };
fruit.color = GREEN; fruit.color = GREEN;
fruit.active = false; fruit.active = false;
...@@ -162,6 +170,7 @@ void InitGame(void) ...@@ -162,6 +170,7 @@ void InitGame(void)
deadFruit.color=BLACK; deadFruit.color=BLACK;
deadFruit.active=false; deadFruit.active=false;
//murs
recTab[0].x=2*SQUARE_SIZE + offset.x/2; //mur haut gauche recTab[0].x=2*SQUARE_SIZE + offset.x/2; //mur haut gauche
recTab[0].y=2*SQUARE_SIZE + offset.y/2; recTab[0].y=2*SQUARE_SIZE + offset.y/2;
recTab[0].width=(SQUARE_SIZE)-0.1; recTab[0].width=(SQUARE_SIZE)-0.1;
...@@ -204,9 +213,11 @@ void InitGame(void) ...@@ -204,9 +213,11 @@ void InitGame(void)
highscore=LoadStorageValue(0); highscore=LoadStorageValue(0);
//sons
fruitSound = LoadSound("SnakeSounds\\coin.wav"); // Load audio files fruitSound = LoadSound("SnakeSounds\\coin.wav"); // Load audio files
goldenFruitSound = LoadSound("SnakeSounds\\sound.wav"); goldenFruitSound = LoadSound("SnakeSounds\\sound.wav");
deathSound = LoadSound("SnakeSounds\\tanatana.ogg"); deathSound = LoadSound("SnakeSounds\\tanatana.ogg");
music = LoadMusicStream("SnakeSounds\\mini1111.xm");
} }
void drawWalls(){ void drawWalls(){
...@@ -245,6 +256,8 @@ void UpdateGame(void) ...@@ -245,6 +256,8 @@ void UpdateGame(void)
if (!pause) if (!pause)
{ {
UpdateMusicStream(music);
// Player control // Player control
if (IsKeyPressed(KEY_RIGHT) && (snake[0].speed.x == 0) && allowMove) if (IsKeyPressed(KEY_RIGHT) && (snake[0].speed.x == 0) && allowMove)
{ {
...@@ -400,6 +413,8 @@ void UpdateGame(void) ...@@ -400,6 +413,8 @@ void UpdateGame(void)
if (IsKeyPressed(KEY_ENTER)) if (IsKeyPressed(KEY_ENTER))
{ {
InitGame(); InitGame();
StopMusicStream(music);
PlayMusicStream(music);
gameOver = false; gameOver = false;
} }
} }
...@@ -467,6 +482,7 @@ void UnloadGame(void) ...@@ -467,6 +482,7 @@ void UnloadGame(void)
UnloadSound(fruitSound); UnloadSound(fruitSound);
UnloadSound(goldenFruitSound); UnloadSound(goldenFruitSound);
UnloadSound(deathSound); UnloadSound(deathSound);
CloseAudioDevice();
} }
// Update and Draw (one frame) // Update and Draw (one frame)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment