Initial publish

Dependencies:   mbed

Fork of el17dg by Dmitrijs Griskovs

Revision:
34:754915ce9de5
Parent:
33:c623c6d5ed16
Child:
35:172db1608332
--- a/game/gameovermanager.h	Mon Apr 29 08:10:52 2019 +0000
+++ b/game/gameovermanager.h	Tue Apr 30 19:24:41 2019 +0000
@@ -2,13 +2,31 @@
 #define GAMEOVERMANAGER_H
 
 #include "main.h"
-
+/** 
+ * GameOverManager Class
+ * @brief A class for updating and drawing GameOver state.
+ * @author Dmitrijs Griskovs
+ * @date 30/04/2019
+ */
 class GameOverManager {
 public:
+    /** 
+     * Constructor. 
+     * @brief It init the GameOver with reseting 
+     * the statrting sequence of the gameOver state.
+     */ 
     GameOverManager() { reset(); }
     
+    /** 
+     * @brief Resets the gameOver to the animiation to appear again
+     * @returns bool started, when GameOver begins.
+     */
     void reset() { started = false; }
-    
+    /** 
+     * @brief Updates and draws the game over animation.
+     * @details It draws "GameOver" sprite from the leftside of the screen to the center
+     * and "youDied" sprite from the right side to the center.  
+     */
     void updateAndDraw() {
         if (!started) {
             startAnimation();
@@ -18,6 +36,7 @@
             if (gamepad.check_event(gamepad.START_PRESSED)) {
                 gameOverLogo.pos.x = game_area_x - 29 + 42;
                 youDied.pos.x = game_area_width - 42;
+                animation_counter = animation_length;
             } else {
                 animation_counter++;
                 gameOverLogo.pos.x += 1;
@@ -28,7 +47,8 @@
         drawSprite(youDied.pos, you_died_sprite);
 
         char buffer[32];
-        sprintf(buffer,"Your Score %i", GameGlobals::game_score);
+        sprintf(buffer,"Score: %i", GameGlobals::game_score);
+        updateHighScore();
         lcd.printString(buffer,0,3);   
         lcd.printString("Press Y",0,4);
         lcd.printString("to restart",0,5);
@@ -37,6 +57,12 @@
         ledsGameOver();   
     }
     
+    /** 
+     * @brief Checks for whether the animation of GameOver has stoped drawing or not
+     * @details It check the value of the counter against the total length of the
+     * animation play. When the counter equals to the total length, it indicates that
+     * the animation has stopped  
+     */
     bool isPlayingAnimation() {
         return animation_counter < animation_length;
     };
@@ -106,6 +132,11 @@
             high_frequency_music_counter = 0;
         }
     }
+     void updateHighScore(){
+        if (GameGlobals::high_score < GameGlobals::game_score){
+            GameGlobals::high_score = GameGlobals::game_score;
+        }
+    }
     
     bool started;
     static const int animation_length = 42;