Arturs Kozlovskis / Mbed 2 deprecated ELEC2645_Project_el18ak

Dependencies:   mbed

Revision:
19:913d123554ee
Parent:
18:8f7291885e19
Child:
21:32429d8e90ff
--- a/main.cpp	Sat May 09 08:19:00 2020 +0000
+++ b/main.cpp	Sat May 09 10:09:35 2020 +0000
@@ -34,7 +34,10 @@
 //variables
 bool game_check = false;
 bool game_playing = false;
-
+int pause_return_value = 0;
+int game_return_value = 2;
+string game_speed;
+float extra_speed = 0.5;
 
 int main()
 {
@@ -43,6 +46,13 @@
     while(1) {
         //menu
         menu.menu_screen();
+        game_speed = menu.get_game_speed();
+        if (game_speed == "fast"){
+            extra_speed = 0.0f;
+        }else{
+            //decreasesn the speed
+            extra_speed = 0.05f;
+        }
         //create the game
         game();
     }
@@ -58,11 +68,11 @@
 
 void game()
 {
-    
+
     Objects objects;
     Functions functions;
     while(game_check == false) {
-        
+
         lcd.clear();
 
         objects.draw_shots(lcd,pad, true);// draws the shot
@@ -77,7 +87,7 @@
         objects.draw_cannon(lcd);//draws the cannon
         game_check = functions.cannon_smash(lcd, objects); //checks if the cannon has been hit by a ball
         lcd.refresh();
-        wait(0.15);
+        wait(0.1 + extra_speed);
 
         lcd.clear();
         //added this so the cannon moves faster than the balls
@@ -85,14 +95,18 @@
         objects.draw_cannon(lcd);//draws the cannon
         lcd.refresh();
         wait(0.005);
+        
+        pause_return_value = menu.pause_screen();
+        if(pause_return_value == 1) {
+            break;
+        }
     }
-    //prints the the score and game over and the continue option
-    lcd.printString("Game over!", 15,2);
-    char buf_score[4];
-    sprintf(buf_score,"%d",functions.get_score());
-    lcd.printString("Score:",0,0);
-    lcd.printString(buf_score,36,0);
-    lcd.refresh();
-    wait(2);
-    game_check = false;
+    if(pause_return_value == 0) {
+        //prints the the score and game over
+        game_return_value = menu.game_over_screen(functions.get_score());
+        if (game_return_value == 2) {
+            game_check = false;
+        }
+    } 
+    
 }