FINAL VERSION

Dependencies:   mbed

Revision:
111:4848c399fae0
Parent:
110:780fdecd9171
Child:
112:26961473eae8
--- a/main.cpp	Wed May 08 01:57:25 2019 +0000
+++ b/main.cpp	Wed May 08 02:50:07 2019 +0000
@@ -280,7 +280,7 @@
         if (breakout.check_loss(pad) == true) { // if life lost flash screen
             flash_screen(lcd);
         }
-        if (pad.check_event(Gamepad::START_PRESSED) == true) { // if BACK pressed, toggle pause
+        if (pad.check_event(Gamepad::START_PRESSED)) { // if BACK pressed, toggle pause
             pause = !pause;
             wait(0.4); // delay to help with button bounce
         }
@@ -291,11 +291,11 @@
             lcd.printString(" START = PLAY",0,3);
             lcd.printString("  BACK = MENU",0,4);
             lcd.refresh();
-            if (pad.check_event(Gamepad::START_PRESSED) == true) { // if START pressed, toggle pause, leaving pause screen
+            if (pad.check_event(Gamepad::START_PRESSED)) { // if START pressed, toggle pause, leaving pause screen
                 pause = !pause;
                 wait(0.4); // delay to help with button bounce
             }
-            if (pad.check_event(Gamepad::BACK_PRESSED) == true) { // if BACK pressed, return to the title screen
+            if (pad.check_event(Gamepad::BACK_PRESSED)) { // if BACK pressed, return to the title screen
                 breakout.set_mult_zero(); // reset multiplier
                 breakout.set_prev_score(0);
                 breakout.reset_game(); //reset game to initial positions
@@ -309,7 +309,6 @@
         }
 
         if (breakout.get_num_left() == 0) { // when all bricks destroyed, display victory screen
-            
             victory_screen();
         }
         number_of_frames ++; // track the number of frames passed to add to the score (inversely proportional)
@@ -364,9 +363,9 @@
     }
     
     lcd.clear();
-    char buffer1[14];
-    sprintf(buffer1,"%2d",breakout.get_score());
-    lcd.printString(buffer1,WIDTH/2 - 12,2);
+    char buffer[14]; // init the buffer
+    sprintf(buffer,"%2d",breakout.get_score());  // print the score to the buffer
+    lcd.printString(buffer,WIDTH/2 - 12,2);  // print buffer on lcd
     lcd.printString("   RESTART? ",2,1);
     lcd.printString("  PRESS START ",1,4);
     lcd.refresh();
@@ -386,19 +385,18 @@
         wait(0.4);
 
         lcd.clear();
-
-        char buffer1[14];
-        sprintf(buffer1,"%2d",breakout.get_score());
-        lcd.printString(buffer1,WIDTH/2 - 12,2);
-        lcd.printString("   RESTART? ",2,1); //print score here
+        
+        lcd.printString(buffer,WIDTH/2 - 12,2);  
+        lcd.printString("   RESTART? ",2,1); 
         lcd.printString("  PRESS START ",1,4);
         lcd.refresh();
 
         wait(0.4);
     }
+    breakout.set_prev_score(0);   // resets prev score to 0
+    number_of_frames = 0;
     breakout.set_mult_zero(); // reset multiplier
     breakout.reset_game(); // return game to initial positions 
-    breakout.set_prev_score(0);   // resets prev score to 0
     title_screen();
 }
 
@@ -406,14 +404,14 @@
 {
     int bonus = NULL;
     
-    if (breakout.get_score()/2 - ((breakout.get_score()/2) * number_of_frames)/720 > 0) {   // beat within 90 seconds and you get a bonus
+    if (breakout.get_score()/2 - ((breakout.get_score()/2) * number_of_frames)/720 > 0) {   // beat within 90 seconds (8 fps) and you get a bonus
         bonus = breakout.get_score()/2 - ((breakout.get_score()/2) * number_of_frames)/720;
     }
     else {
-        bonus = 0;
+        bonus = 0; // else u get no bonus
     }
     
-    if (compare_to_hi_score(bonus+breakout.get_score()) == true) {
+    if (compare_to_hi_score(bonus+breakout.get_score()) == true) {   // little hi-score sequence if current score is higher than prev
         lcd.clear();
         lcd.printString("      NEW ",0,2);
         lcd.printString("   HI-SCORE! ",0,3);
@@ -459,7 +457,7 @@
     
     lcd.clear();
     
-    char buffer1[14];
+    char buffer1[14];  
     sprintf(buffer1,"%2d",breakout.get_score());
     lcd.printString(buffer1,WIDTH/2 - 12,2);