Commit 933ba8b1 authored by Lila NICKLER's avatar Lila NICKLER

Ajout du score a la fin + highscore sauvgardé

parent d3d56a45
...@@ -79,6 +79,7 @@ static bool gameOver = false; ...@@ -79,6 +79,7 @@ static bool gameOver = false;
static bool pause = false; static bool pause = false;
static int score = 0; static int score = 0;
static bool victory = false; static bool victory = false;
static int highscore;
static Player player = { 0 }; static Player player = { 0 };
static Enemy enemy[NUM_MAX_ENEMIES] = { 0 }; static Enemy enemy[NUM_MAX_ENEMIES] = { 0 };
...@@ -157,6 +158,7 @@ void InitGame(void) ...@@ -157,6 +158,7 @@ void InitGame(void)
enemiesKill = 0; enemiesKill = 0;
score = 0; score = 0;
alpha = 0; alpha = 0;
highscore =LoadStorageValue(0);
// Initialize player // Initialize player
player.rec.x = 20; player.rec.x = 20;
...@@ -367,7 +369,19 @@ void UpdateGame(void) ...@@ -367,7 +369,19 @@ void UpdateGame(void)
} }
if (smooth) alpha -= 0.02f; if (smooth) alpha -= 0.02f;
if (enemy[0].life == 0) victory = true; if (enemy[0].life == 0){
victory = true;
if (score > highscore )
{
highscore = score;
SaveStorageValue(0,highscore);
gameOver = true;
}
}
} }
...@@ -447,7 +461,6 @@ void UpdateGame(void) ...@@ -447,7 +461,6 @@ void UpdateGame(void)
break; break;
default: default:
break; break;
} }
} }
} }
...@@ -612,9 +625,16 @@ void DrawGame(void) ...@@ -612,9 +625,16 @@ void DrawGame(void)
DrawText("Life:",20,40,30, GRAY); DrawText("Life:",20,40,30, GRAY);
DrawText(TextFormat("%i",player.life),100,40,30,RED); DrawText(TextFormat("%i",player.life),100,40,30,RED);
if (victory) DrawText("YOU WIN", screenWidth/2 - MeasureText("YOU WIN", 40)/2, screenHeight/2 - 40, 40, BLACK); if (pause){
DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/3 - 40, 40, GRAY);
if (pause) DrawText("GAME PAUSED", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, screenHeight/2 - 40, 40, GRAY); DrawText("SCORE", screenWidth/2 - MeasureText("GAME PAUSED", 40)/2, 2*screenHeight/3, 40, BLACK);
DrawText(TextFormat("%04i", score), screenWidth/2+MeasureText("SCORE:", 40)/2, 2*screenHeight/3, 40, RED);
}
}else if (victory)
{
DrawText("YOU WIN", screenWidth/2 - MeasureText("YOU WIN", 40)/2, screenHeight/4 - 40, 40, BLACK);
DrawText(TextFormat("SCORE:%04i",score), screenWidth/2 - MeasureText("SCORE:%04i", 40)/2, 2*screenHeight/4, 40, BLACK);
DrawText(TextFormat("HIGHSCORE:%04i",highscore), screenWidth/2 - MeasureText("HIGHSCORE:%04i", 40)/2, 3*screenHeight/4, 40, RED);
} }
else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY); else DrawText("PRESS [ENTER] TO PLAY AGAIN", GetScreenWidth()/2 - MeasureText("PRESS [ENTER] TO PLAY AGAIN", 20)/2, GetScreenHeight()/2 - 50, 20, GRAY);
......
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