FINAL VERSION

Dependencies:   mbed

Revision:
53:8e3da0b58fe9
Parent:
52:652b5f51319d
Child:
54:d96f68f4735b
diff -r 652b5f51319d -r 8e3da0b58fe9 main.cpp
--- a/main.cpp	Sat Apr 27 09:42:36 2019 +0000
+++ b/main.cpp	Sat Apr 27 20:56:03 2019 +0000
@@ -31,7 +31,7 @@
 void init();
 void update_game(UserInput input);
 void render();
-bool main_menu();
+void main_menu();
 void settings();
 void how_to_play();
 void end_screen();
@@ -76,7 +76,7 @@
 }
 
 // simple splash screen displayed on start-up
-bool main_menu() {
+void main_menu() {
     // wait flashing LEDs until start button is pressed 
     //bool joy = true;
     
@@ -85,47 +85,38 @@
     lcd.printString("   SETTINGS ",0,3);   // choose between joystick and tilt
     lcd.printString("   HOW TO PLAY ",0,4);  // brief text on how to do stuff
     lcd.refresh();  
+    wait(0.1);
     
-    int pointer = 0;
+    int pointer = 2;
     
     while (pad.check_event(Gamepad::A_PRESSED) == false) {  //maybe add a jingle
-        if (pad.check_event(Gamepad::L_PRESSED) && pointer > 0) {  // change to joystick
+        lcd.clear();
+        lcd.printString("   START ",0,2);    // start with default as joystick
+        lcd.printString("   SETTINGS ",0,3);   // choose between joystick and tilt
+        lcd.printString("   HOW TO PLAY ",0,4);  // brief text on how to do stuff
+        lcd.printString("->",0,pointer);
+        lcd.refresh();  
+        wait(0.1);
+        if (pad.check_event(Gamepad::L_PRESSED) && pointer > 2) {  // change to joystick
             pointer -= 1;
-        } else if (pad.check_event(Gamepad::R_PRESSED) == S && pointer < 2) {
+            pad.tone(750.0,0.3);
+            wait(0.1);
+        } else if (pad.check_event(Gamepad::R_PRESSED) && pointer < 4) {
             pointer += 1;
-        }
-        
-        switch(pointer){
-            case 0:
-                lcd.printString("->",0,2);
-                
-                pad.tone(750.0,0.3);
-                break;
-            case 1:
-                lcd.printString("->",0,3);
-                
-                pad.tone(750.0,0.3);
-                break;
-            case 2:
-                lcd.printString("->",0,4);
-                
-                pad.tone(750.0,0.3);
-                break;
+            pad.tone(750.0,0.3);
+            wait(0.1);
         }
         
     }
-    if (pointer == 0) {
+    if (pointer == 2) {
         main_game(tilt);
     }
-    else if (pointer == 1){
+    else if (pointer == 3){
         settings();
     }
-    else if (pointer == 2){
+    else if (pointer == 4){
         how_to_play();
     }
-    
-    
-    return tilt;
 }
 
 void settings() {
@@ -134,38 +125,43 @@
     lcd.printString("   JOYSTICK ",0,2);    // start with default as joystick
     lcd.printString("   TILT ",0,3);   // choose between joystick and tilt
     lcd.refresh();  
+    wait(0.1);
+    
+    int pointer = 2;
     
     while (pad.check_event(Gamepad::A_PRESSED) || pad.check_event(Gamepad::B_PRESSED) == false) {
-        int pointer = 0;
-        if (pad.check_event(Gamepad::L_PRESSED)  == N && pointer > 0) {
+        lcd.clear();
+        lcd.printString("   JOYSTICK ",0,2);    // start with default as joystick
+        lcd.printString("   TILT ",0,3);   // choose between joystick and tilt
+        lcd.printString("->",0,pointer);
+        lcd.refresh();  
+        wait(0.1);
+        
+        if (pad.check_event(Gamepad::L_PRESSED) && pointer > 2) {
             pointer -= 1;
-        } else if (pad.check_event(Gamepad::R_PRESSED)  == S && pointer < 1) {
+            pad.tone(750.0,0.3);
+            wait(0.1);
+        } else if (pad.check_event(Gamepad::R_PRESSED) && pointer < 3) {
             pointer += 1;
+            pad.tone(750.0,0.3);
+            wait(0.1);
         }
         
-        switch(pointer){
-            case 0:
-                lcd.printString("->",0,2);
-                
-                pad.tone(750.0,0.3);
-                
-                break;
-            case 1:
-                lcd.printString("->",0,3);
-                
-                pad.tone(750.0,0.3);
-                break; 
-        }
-        if (pad.check_event(Gamepad::A_PRESSED) && pointer == 0) {
+        if (pad.check_event(Gamepad::A_PRESSED) && pointer == 2) {
+            pad.tone(750.0,0.3);
+            wait(0.1);
             tilt = false;
         }
-        else if (pad.check_event(Gamepad::A_PRESSED) && pointer == 1) {
+        else if (pad.check_event(Gamepad::A_PRESSED) && pointer == 3) {    // this one doesnt work because of the order??
+            pad.tone(750.0,0.3);
+            wait(0.1);
             tilt = true;
         }
-        else if (pad.check_event(Gamepad::B_PRESSED)) {
+        if (pad.check_event(Gamepad::B_PRESSED)) {
             main_menu();
         }
     }
+    settings(); //sometimes the button bounce causes it to skip the while loop (could add wait in at the top)
 }
 
 void how_to_play() {
@@ -174,6 +170,7 @@
         lcd.printString("  explain ",2,2);
         lcd.printString(" PRESS B ",1,4);
         lcd.refresh();
+        wait(0.1);
     }
     main_menu();
 }
@@ -239,7 +236,7 @@
     Bitmap breakwhite(breakwhite_data, 48, 84);
     Bitmap breakblack(breakblack_data, 48, 84);
     
-    while (pad.check_event(Gamepad::L_PRESSED) || pad.check_event(Gamepad::R_PRESSED) || pad.check_event(Gamepad::START_PRESSED) || pad.check_event(Gamepad::BACK_PRESSED)== false) {  //maybe add a jingle
+    while (pad.check_event(Gamepad::START_PRESSED) == false) {  //maybe add a jingle
         
         breakwhite.render(lcd, 0, 0);
         lcd.refresh();
@@ -253,13 +250,9 @@
         pad.leds_off();
         wait(0.5);
     }
-     
-    if (main_menu() == true) {
-        tilt = true;
-    }  // waiting for the user to start
-    
-    main_game(tilt);
-    
+    pad.tone(2000.0,0.2);
+    wait(0.2);
+    main_menu();
 }
 
 void main_game(bool tilt) {