Commit 24374b9d authored by Benjamin LEROUX's avatar Benjamin LEROUX

ajout: retour a la selection de niveau

parent 8c2a6ab1
......@@ -81,6 +81,7 @@ static void DrawGame(void); // Draw game (one frame)
static void UnloadGame(void); // Unload game
static void UpdateDrawFrame(void); // Update and Draw (one frame)
static void SelectScreen();
static void Launch();
//------------------------------------------------------------------------------------
// Program main entry point
......@@ -90,18 +91,11 @@ int main(void)
// Initialization (Note windowTitle is unused on Android)
//---------------------------------------------------------
InitWindow(screenWidth, screenHeight, "sample game: snake");
// Select screen loop
while (!WindowShouldClose() && !isReady) // Detect window close button or ESC key
{
SelectScreen();
}
InitGame();
InitAudioDevice(); // Initialize audio device
StopMusicStream(music);
PlayMusicStream(music);
// Select screen loop
SelectScreen();
Launch();
#if defined(PLATFORM_WEB)
emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
......@@ -381,7 +375,7 @@ void UpdateGame(void)
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)))
while (((deadFruit.position.x == snake[i].position.x) && (deadFruit.position.y == snake[i].position.y))||((deadFruit.position.x == fruit.position.x) && (deadFruit.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 };
i = 0;
......@@ -429,10 +423,20 @@ void UpdateGame(void)
{
if (IsKeyPressed(KEY_ENTER))
{
InitGame();
StopMusicStream(music);
PlayMusicStream(music);
gameOver = false;
Launch();
}
if (IsKeyPressed(KEY_SPACE))
{
gameOver = false;
isReady=false;
//disparition des murs
for(int i=0; i< NUMBEROFWALL;i++){
recTab[i].x=-100;
recTab[i].y=-100;
}
SelectScreen();
Launch();
}
}
}
......@@ -479,7 +483,8 @@ void DrawGame(void)
}
}
else {
DrawText("PRESS [ENTER] TO PLAY AGAIN", screenWidth/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 40)/2, screenHeight - 200, 40, BLACK);
DrawText("PRESS [ENTER] TO PLAY AGAIN", screenWidth/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 40)/2, screenHeight - 240, 40, BLACK);
DrawText("PRESS [SPACE] TO SELECT A LEVEL", screenWidth/2 - MeasureText("PRESS [SPACE] TO SELECT A LEVEL", 40)/2, screenHeight - 180, 40, BLACK);
DrawText(TextFormat("TIME: %.02f", (float)framesCounter/60), screenWidth/2 - MeasureText("TIME: 00.00", 60)/2, screenHeight/2 - 120, 60, BLUE);
DrawText(TextFormat("SCORE: %04i",snake[0].score ), screenWidth/2 - MeasureText("SCORE: 0000", 60)/2, screenHeight/2 - 180, 60, BLUE);
if(highscore<snake[0].score){
......@@ -514,24 +519,32 @@ void UpdateDrawFrame(void)
}
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();
while (!WindowShouldClose() && !isReady) // tant que la fenetre n'est pas fermé et qu'aucun choix n'a été fait
{
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();
}
}
void Launch(){
InitGame();
StopMusicStream(music);
PlayMusicStream(music);
}
\ No newline at end of file
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