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

ajout difficultes et menu de demarrage

parent a1ecc9bf
...@@ -24,8 +24,6 @@ ...@@ -24,8 +24,6 @@
#define SQUARE_SIZE 31 #define SQUARE_SIZE 31
#define NUMBEROFWALL 8 #define NUMBEROFWALL 8
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Types and Structures Definition // Types and Structures Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
...@@ -71,8 +69,8 @@ static Sound goldenFruitSound; ...@@ -71,8 +69,8 @@ static Sound goldenFruitSound;
static Sound deathSound; static Sound deathSound;
static Music music; static Music music;
static bool isMute; static bool isMute;
static bool isReady=false;
static int level; //easy = 1 AND hard =2
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Module Functions Declaration (local) // Module Functions Declaration (local)
...@@ -82,6 +80,7 @@ static void UpdateGame(void); // Update game (one frame) ...@@ -82,6 +80,7 @@ static void UpdateGame(void); // Update game (one frame)
static void DrawGame(void); // Draw game (one frame) static void DrawGame(void); // Draw game (one frame)
static void UnloadGame(void); // Unload game static void UnloadGame(void); // Unload game
static void UpdateDrawFrame(void); // Update and Draw (one frame) static void UpdateDrawFrame(void); // Update and Draw (one frame)
static void SelectScreen();
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Program main entry point // Program main entry point
...@@ -92,13 +91,18 @@ int main(void) ...@@ -92,13 +91,18 @@ int main(void)
//--------------------------------------------------------- //---------------------------------------------------------
InitWindow(screenWidth, screenHeight, "sample game: snake"); InitWindow(screenWidth, screenHeight, "sample game: snake");
// Select screen loop
while (!WindowShouldClose() && !isReady) // Detect window close button or ESC key
{
SelectScreen();
}
InitGame(); InitGame();
InitAudioDevice(); // Initialize audio device InitAudioDevice(); // Initialize audio device
StopMusicStream(music); StopMusicStream(music);
PlayMusicStream(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);
#else #else
...@@ -137,7 +141,6 @@ void InitGame(void) ...@@ -137,7 +141,6 @@ void InitGame(void)
pause = false; pause = false;
isMute=false; isMute=false;
counterTail = 1; counterTail = 1;
allowMove = false; allowMove = false;
...@@ -173,6 +176,7 @@ void InitGame(void) ...@@ -173,6 +176,7 @@ void InitGame(void)
deadFruit.active=false; deadFruit.active=false;
//murs //murs
if(level==2){
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;
...@@ -212,6 +216,7 @@ void InitGame(void) ...@@ -212,6 +216,7 @@ void InitGame(void)
recTab[7].y=screenHeight-(offset.y/2)-(3*SQUARE_SIZE); recTab[7].y=screenHeight-(offset.y/2)-(3*SQUARE_SIZE);
recTab[7].width=(SQUARE_SIZE*3)-0.1; recTab[7].width=(SQUARE_SIZE*3)-0.1;
recTab[7].height=(SQUARE_SIZE)-0.1; recTab[7].height=(SQUARE_SIZE)-0.1;
}
highscore=LoadStorageValue(0); highscore=LoadStorageValue(0);
...@@ -502,3 +507,25 @@ void UpdateDrawFrame(void) ...@@ -502,3 +507,25 @@ void UpdateDrawFrame(void)
DrawGame(); DrawGame();
} }
void SelectScreen(){
BeginDrawing();
ClearBackground(RAYWHITE);
DrawText("SNAKE", screenWidth/2 - MeasureText("SNAKE", 120)/2, screenHeight - 440, 120, BLACK);
DrawText("1: EASY", screenWidth/2 - MeasureText("1: EASY", 60)/2, screenHeight - 300, 60, GREEN);
DrawText("2: HARD", screenWidth/2 - MeasureText("2: HARD", 60)/2, screenHeight - 230, 60, RED);
DrawText("PRESS 1 OR 2", screenWidth/2 - MeasureText("PRESS 1 OR 2", 40)/2, screenHeight - 140, 40, GRAY);
DrawText("TO SELECT YOUR LEVEL", screenWidth/2 - MeasureText("TO SELECT YOUR LEVEL", 40)/2, screenHeight - 100, 40, GRAY);
if(IsKeyPressed(KEY_ONE)||IsKeyPressed(KEY_KP_1)){ //niveau facile
isReady=true;
level=1;
}
if(IsKeyPressed(KEY_TWO)||IsKeyPressed(KEY_KP_2)){ //niveau difficile
isReady=true;
level=2;
}
EndDrawing();
}
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