Commit 0f55a51e authored by Benjamin LEROUX's avatar Benjamin LEROUX

ajout de sons + correction bug apparition des fruits

parent e2285cd3
...@@ -66,6 +66,9 @@ static Food deadFruit = {0}; ...@@ -66,6 +66,9 @@ static Food deadFruit = {0};
static Rectangle recTab[NUMBEROFWALL]; static Rectangle recTab[NUMBEROFWALL];
static int highscore; static int highscore;
static Sound fruitSound ;
static Sound goldenFruitSound;
static Sound deathSound;
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Module Functions Declaration (local) // Module Functions Declaration (local)
...@@ -86,6 +89,7 @@ int main(void) ...@@ -86,6 +89,7 @@ int main(void)
InitWindow(screenWidth, screenHeight, "sample game: snake"); InitWindow(screenWidth, screenHeight, "sample game: snake");
InitGame(); InitGame();
InitAudioDevice(); // Initialize audio device
#if defined(PLATFORM_WEB) #if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 0, 1); emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
...@@ -124,6 +128,7 @@ void InitGame(void) ...@@ -124,6 +128,7 @@ void InitGame(void)
gameOver = false; gameOver = false;
pause = false; pause = false;
counterTail = 1; counterTail = 1;
allowMove = false; allowMove = false;
...@@ -198,6 +203,10 @@ void InitGame(void) ...@@ -198,6 +203,10 @@ void InitGame(void)
recTab[7].height=(SQUARE_SIZE)-0.1; recTab[7].height=(SQUARE_SIZE)-0.1;
highscore=LoadStorageValue(0); highscore=LoadStorageValue(0);
fruitSound = LoadSound("SnakeSounds\\coin.wav"); // Load audio files
goldenFruitSound = LoadSound("SnakeSounds\\sound.wav");
deathSound = LoadSound("SnakeSounds\\tanatana.ogg");
} }
void drawWalls(){ void drawWalls(){
...@@ -276,7 +285,10 @@ void UpdateGame(void) ...@@ -276,7 +285,10 @@ void UpdateGame(void)
} }
//collison mur //collison mur
if(checkCollisionMur(snake[0].position))gameOver=true; if(checkCollisionMur(snake[0].position)){
gameOver = true;
PlaySound(deathSound);
}
//teleport wall //teleport wall
if((snake[0].position.x)>(screenWidth-offset.x)){ if((snake[0].position.x)>(screenWidth-offset.x)){
...@@ -294,7 +306,10 @@ void UpdateGame(void) ...@@ -294,7 +306,10 @@ void UpdateGame(void)
// Collision with yourself // Collision with yourself
for (int i = 1; i < counterTail; i++) for (int i = 1; i < counterTail; i++)
{ {
if ((snake[0].position.x == snake[i].position.x) && (snake[0].position.y == snake[i].position.y)) gameOver = true; if ((snake[0].position.x == snake[i].position.x) && (snake[0].position.y == snake[i].position.y)){
gameOver = true;
PlaySound(deathSound);
}
} }
...@@ -320,7 +335,10 @@ void UpdateGame(void) ...@@ -320,7 +335,10 @@ void UpdateGame(void)
goldenFruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.x/2, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.y/2 }; goldenFruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.x/2, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.y/2 };
for (int i = 0; i < counterTail; i++) for (int i = 0; i < counterTail; i++)
{ {
while (((goldenFruit.position.x == snake[i].position.x) && (goldenFruit.position.y == snake[i].position.y))||((goldenFruit.position.x == fruit.position.x) && (goldenFruit.position.y == fruit.position.y))||checkCollisionMur(goldenFruit.position)) if (checkCollisionMur(goldenFruit.position)){ //permet de ne pas embourber les conditions du while
goldenFruit.position=fruit.position; //si le fruit est sur un mur alors on reste dans le while
}
while (((goldenFruit.position.x == snake[i].position.x) && (goldenFruit.position.y == snake[i].position.y))||((goldenFruit.position.x == fruit.position.x) && (goldenFruit.position.y == fruit.position.y)))
{ {
goldenFruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.x/2, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.y/2 }; goldenFruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.x/2, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.y/2 };
i = 0; i = 0;
...@@ -330,7 +348,10 @@ void UpdateGame(void) ...@@ -330,7 +348,10 @@ void UpdateGame(void)
deadFruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.x/2, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.y/2 }; deadFruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.x/2, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.y/2 };
for (int i = 0; i < counterTail; i++) for (int i = 0; i < counterTail; i++)
{ {
while (((deadFruit.position.x == snake[i].position.x) && (deadFruit.position.y == snake[i].position.y))||((deadFruit.position.x == fruit.position.x) && (goldenFruit.position.y == fruit.position.y))||checkCollisionMur(deadFruit.position)) if (checkCollisionMur(deadFruit.position)){
deadFruit.position=fruit.position;
}
while (((deadFruit.position.x == snake[i].position.x) && (deadFruit.position.y == snake[i].position.y))||((deadFruit.position.x == fruit.position.x) && (goldenFruit.position.y == fruit.position.y)))
{ {
deadFruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.x/2, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.y/2 }; deadFruit.position = (Vector2){ GetRandomValue(0, (screenWidth/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.x/2, GetRandomValue(0, (screenHeight/SQUARE_SIZE) - 1)*SQUARE_SIZE + offset.y/2 };
i = 0; i = 0;
...@@ -348,6 +369,7 @@ void UpdateGame(void) ...@@ -348,6 +369,7 @@ void UpdateGame(void)
counterTail += 1; counterTail += 1;
fruit.active = false; fruit.active = false;
snake[0].score+=100; snake[0].score+=100;
PlaySound(fruitSound);
} }
// Collision goldenFruit // Collision goldenFruit
...@@ -359,6 +381,7 @@ void UpdateGame(void) ...@@ -359,6 +381,7 @@ void UpdateGame(void)
counterTail += 1; counterTail += 1;
goldenFruit.position=(Vector2) {-100,-100}; //disparition du goldenFruit goldenFruit.position=(Vector2) {-100,-100}; //disparition du goldenFruit
snake[0].score+=250; snake[0].score+=250;
PlaySound(goldenFruitSound);
} }
// Collision deadFruit // Collision deadFruit
...@@ -366,6 +389,7 @@ void UpdateGame(void) ...@@ -366,6 +389,7 @@ void UpdateGame(void)
(snake[0].position.y < (deadFruit.position.y + deadFruit.size.y) && (snake[0].position.y + snake[0].size.y) > deadFruit.position.y)) (snake[0].position.y < (deadFruit.position.y + deadFruit.size.y) && (snake[0].position.y + snake[0].size.y) > deadFruit.position.y))
{ {
gameOver=true; gameOver=true;
PlaySound(deathSound);
} }
framesCounter++; framesCounter++;
...@@ -440,6 +464,9 @@ void DrawGame(void) ...@@ -440,6 +464,9 @@ void DrawGame(void)
void UnloadGame(void) void UnloadGame(void)
{ {
// TODO: Unload all dynamic loaded data (textures, sounds, models...) // TODO: Unload all dynamic loaded data (textures, sounds, models...)
UnloadSound(fruitSound);
UnloadSound(goldenFruitSound);
UnloadSound(deathSound);
} }
// 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