Commit b3a5282b authored by Fan FEI's avatar Fan FEI

Version "2.0"

  add soundtrack
parent 67c5b302
......@@ -13,14 +13,19 @@
* Expanded on this basis by Fan FEI
*
*
*
*
*
*
********************************************************************************************/
#include "raylib.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <errno.h>
#include <string.h>
#include <stdbool.h>
#if defined(PLATFORM_WEB)
#include <emscripten/emscripten.h>
#endif
......@@ -31,6 +36,8 @@
#define SNAKE_LENGTH 256
#define SQUARE_SIZE 31
Music soundtrack;
//----------------------------------------------------------------------------------
// Types and Structures Definition
//----------------------------------------------------------------------------------
......@@ -83,6 +90,11 @@ int main(void)
//---------------------------------------------------------
InitWindow(screenWidth, screenHeight, "sample game: snake By FanFEI"); // Initialize the interface and title
InitAudioDevice();
char *music = "Music_snake_FanFEI.mp3";
soundtrack = LoadMusicStream(music);
PlayMusicStream(soundtrack);
InitGame(); //Initialize the game
#if defined(PLATFORM_WEB)
......@@ -97,6 +109,7 @@ int main(void)
// Update and Draw
//----------------------------------------------------------------------------------
UpdateDrawFrame();
UpdateMusicStream(soundtrack);
//----------------------------------------------------------------------------------
}
#endif
......@@ -117,6 +130,7 @@ int main(void)
// Initialize game variables
void InitGame(void)
{
framesCounter = 0;
gameOver = false; // Game state
pause = false;
......@@ -183,7 +197,7 @@ void UpdateGame(void)
// Snake movement
for (int i = 0; i < counterTail; i++) snakePosition[i] = snake[i].position;
if ((framesCounter%10) == 0)
if ((framesCounter%5) == 0)
{
for (int i = 0; i < counterTail; i++)
{
......@@ -222,7 +236,6 @@ void UpdateGame(void)
while ((fruit.position.x == snake[i].position.x) && (fruit.position.y == snake[i].position.y))
{
fruit.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;
}
}
}
......@@ -241,10 +254,12 @@ void UpdateGame(void)
}
else
{
StopMusicStream(soundtrack);
if (IsKeyPressed(KEY_ENTER)) //Press enter to start the game
{
InitGame();
gameOver = false;
PlayMusicStream(soundtrack);
}
}
}
......@@ -285,6 +300,7 @@ void DrawGame(void)
// Unload game variables
void UnloadGame(void)
{
UnloadMusicStream(soundtrack);
// TODO: Unload all dynamic loaded data (textures, sounds, models...)
}
......
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