Adam Baker 201166301

Dependencies:   mbed Gamepad N5110

Revision:
40:f53c70793975
Parent:
37:23b6312c8315
Child:
41:4b20f909bbcb
diff -r 500da3d26267 -r f53c70793975 Menu/Menu.cpp
--- a/Menu/Menu.cpp	Tue May 07 16:23:00 2019 +0000
+++ b/Menu/Menu.cpp	Tue May 07 18:07:39 2019 +0000
@@ -10,164 +10,188 @@
 
 }
 
-void Menu::init()
+void Menu::init()               //initialise Menu variables
 {
     _select = 1;
     _input = 0;
-    _stop = 0; 
+    _stop = 0;
 
 }
 
 
-void Menu::title_intro(N5110 &lcd, Gamepad &pad)
+void Menu::title_intro(N5110 &lcd, Gamepad &pad)                //run intro sequence
+{
+    intro_b(lcd, pad);
+    intro_bl(lcd, pad);
+    intro_blo(lcd, pad);
+    intro_bloc(lcd, pad);
+    intro_block(lcd, pad);
+    intro_block_h(lcd, pad);
+    intro_block_he(lcd, pad);
+    intro_block_hea(lcd, pad);
+    intro_block_head(lcd, pad);
+}
+
+void Menu::intro_b(N5110 &lcd, Gamepad &pad)                    //display b with note
 {
     wait(0.5);
-    
+
     lcd.clear();
     pad.tone(261.3, 0.1); //C   beat 1
     B(1,15,lcd);
     lcd.refresh();
-    
+}
+
+void Menu::intro_bl(N5110 &lcd, Gamepad &pad)                   //display bl with note
+{
     wait(0.2);
-    
+
     lcd.clear();
     pad.tone(293.66, 0.1); //D beat 1.5
     BL(1,15,lcd);
     lcd.refresh();
-    
+}
+
+void Menu::intro_blo(N5110 &lcd, Gamepad &pad)                  //display blo with note
+{
     wait(0.4);
-    
+
     lcd.clear();
     pad.tone(440.00, 0.1); //G beat 2.5
     BLO(1,15,lcd);
     lcd.refresh();
-    
-    wait(0.4);  
-        
-    lcd.clear();      
+}
+
+void Menu::intro_bloc(N5110 &lcd, Gamepad &pad)                 //display bloc with note
+{
+    wait(0.4);
+
+    lcd.clear();
     pad.tone(392.00, 0.1); //A beat 3.5
     BLOC(1,15,lcd);
     lcd.refresh();
-    
+}
+
+void Menu::intro_block(N5110 &lcd, Gamepad &pad)                //display block with note
+{
     wait(0.2);
-    
+
     lcd.clear();
     pad.tone(220.00, 0.1); //A beat 4
     BLOCK(1,15,lcd);
     lcd.refresh();
-    
+}
+
+void Menu::intro_block_h(N5110 &lcd, Gamepad &pad)              //display block h with note
+{
     wait(0.4);
-    
+
     lcd.clear();
-    pad.tone(196.00, 0.1); //G beat 
+    pad.tone(196.00, 0.1); //G beat
     BLOCK_H(1,15,lcd);
     lcd.refresh();
-    
+}
+
+void Menu::intro_block_he(N5110 &lcd, Gamepad &pad)              //display block he with note
+{
     wait(0.133);
-    
+
     lcd.clear();
-    pad.tone(220.00, 0.1); //A 
+    pad.tone(220.00, 0.1); //A
     BLOCK_HE(1,15,lcd);
     lcd.refresh();
-    
+}
+
+void Menu::intro_block_hea(N5110 &lcd, Gamepad &pad)            //display block hea with note
+{
     wait(0.133);
-    
+
     lcd.clear();
-    pad.tone(246.94, 0.1); //B 
+    pad.tone(246.94, 0.1); //B
     BLOCK_HEA(1,15,lcd);
     lcd.refresh();
-   
+}
+
+void Menu::intro_block_head(N5110 &lcd, Gamepad &pad)           //display block head with note
+{
     wait(0.133);
-    
+
     lcd.clear();
     pad.tone(261.63, 0.1); //C
     BLOCK_HEAD(1,15,lcd);
     lcd.refresh();
-    
 }
 
-int Menu::press_start(N5110 &lcd, Gamepad &pad)
-{   
 
-    if (pad.check_event(Gamepad::START_PRESSED)) {
+int Menu::press_start(N5110 &lcd, Gamepad &pad)                 //flash start untill start button is pressed  
+{
+
+    if (pad.check_event(Gamepad::START_PRESSED)) {              //return 1 when start is pressed
         _start = 1;
     } else {
         _start = 0;
     }
-    
-    lcd.clear();
-    BLOCK_HEAD(1,15,lcd);
-    
-    _count++;
-    
-    if (_count == 3) {
+
+    lcd.clear();                                                
+    BLOCK_HEAD(1,15,lcd);                                       //print blockhead
+
+    _count++;                                                   //increment count
+
+    if (_count == 3) {                                          //every 3 refreshes, invert flash 
         _flash = !_flash;
-        _count = 0;
+        _count = 0;                                             //and set count back to 0
     }
-    
+
     if (_flash) {
-    lcd.printString(" Press  Start ",0,5);
+        lcd.printString(" Press  Start ",0,5);                  //if flash is true, print 'press start'
     }
-    
+
     lcd.refresh();
-    
+
     return _start;
 }
 
 
 
-int Menu::select_input(Gamepad &pad, N5110 &lcd)
+int Menu::select_input_main(Gamepad &pad, N5110 &lcd)                //selects input using button and joystick 
 {
 
-    if (pad.check_event(Gamepad::A_PRESSED)) {
-        _input = _select;
+    if (pad.check_event(Gamepad::A_PRESSED)) {                  //if a button pressed,
+        _input = _select;                                       //input = select
     }   else {
         _input = 0;
     }
 
     Vector2D updown = pad.get_coord();
 
-    if (updown.y <= -0.5f && _stop == 0 ) {
-        _select++;
-        _stop = 1;
-    } else if (updown.y >= 0.5f && _stop == 0) {
-        _select--;
-        _stop = 1;
+    if (updown.y <= -0.5f && _stop == 0 ) {                     //if joystick moved down
+        _select++;                                              //select incrments
+        _stop = 1;                                              //stop = 1,prevent from moving too quickly 
+    } else if (updown.y >= 0.5f && _stop == 0) {                // if joy stick moved up
+        _select--;                                              //selecet decrements 
+        _stop = 1;                                              //stop - 1, prevent from moving too quickly
     }
-
-    if (_select == 0) {
+                                                                //select runs between 1 - 4
+    if (_select == 0) {                                         //when select reaches 0, it becomes 4
         _select = 4;
-    } else if (_select == 5) {
+    } else if (_select == 5) {                                  //when select reaches 5, it becomes 1
         _select = 1;
     }
 
-    if (updown.y < 0.5f && updown.y > -0.5 && _stop == 1) {
+    if (updown.y < 0.5f && updown.y > -0.5 && _stop == 1) {     //reset stop
         _stop = 0;
     }
-    
-    print_main_menu(lcd);
-    
+
+    print_main_menu(lcd);                                       //print main menu
+
     return _input;
 }
 
 void Menu::print_main_menu(N5110 &lcd)   //can go in menu class.
 {
     lcd.clear();
-    
-    _count++;
-    
-    if (_count == 3) {
-        _flash = !_flash;
-        _count = 0;
-    }
-    
-    if (_flash) {
-        lcd.printString("<><><><><><><>",0,0);
-        lcd.printString("><><><><><><><",0,5);
-    } else {
-        lcd.printString("><><><><><><><",0,0);
-        lcd.printString("<><><><><><><>",0,5);
-    }
+
+    menu_decoration(lcd);
 
     lcd.printString("   Play Game  ",0,1);
     lcd.printString("  Highscore   ",0,2);
@@ -183,11 +207,129 @@
     } else if (_select == 4) {
         lcd.drawRect(3,34,3,3,FILL_BLACK);
     }
+
+    lcd.refresh();
+
+}
+
+void Menu::menu_decoration(N5110 &lcd) 
+{
+    
+    _count++;                                                   //count increments
+
+    if (_count == 3) {                                          //flash inverts ever 3rd count
+        _flash = !_flash;                                       //and count resets to 0
+        _count = 0;
+    }
+
+    if (_flash) {
+        lcd.printString("<><><><><><><>",0,0);
+        lcd.printString("><><><><><><><",0,5);
+    } else {
+        lcd.printString("><><><><><><><",0,0);
+        lcd.printString("<><><><><><><>",0,5);
+    }
+    
+}
+
+int Menu::select_input_continue(Gamepad &pad, N5110 &lcd)                //selects input using button and joystick 
+{
+
+    if (pad.check_event(Gamepad::A_PRESSED)) {                  //if a button pressed,
+        _input = _select;                                       //input = select
+    }   else {
+        _input = 0;
+    }
+
+    Vector2D updown = pad.get_coord();
+
+    if (updown.y <= -0.5f && _stop == 0 ) {                     //if joystick moved down
+        _select++;                                              //select incrments
+        _stop = 1;                                              //stop = 1,prevent from moving too quickly 
+    } else if (updown.y >= 0.5f && _stop == 0) {                // if joy stick moved up
+        _select--;                                              //selecet decrements 
+        _stop = 1;                                              //stop - 1, prevent from moving too quickly
+    }
+                                                                //select runs between 1 - 2
+    if (_select == 3) {                                         //when select reaches 3, it becomes 2
+        _select = 2;
+    } else if (_select == 0) {                                  //when select reaches 0, it becomes 1
+        _select = 1;
+    }
+
+    if (updown.y < 0.5f && updown.y > -0.5 && _stop == 1) {     //reset stop
+        _stop = 0;
+    }
+
+    print_continue_menu(lcd);                                       //print main menu
+
+    return _input;
+}
+
+void Menu::print_continue_menu(N5110 &lcd)   //can go in menu class.
+{
+    lcd.clear();
+
+    menu_decoration(lcd);
+
+
+    lcd.printString("   Continue   ",0,2);                      
+    lcd.printString("   Go  back   ",0,3);
+
+
+    if (_select == 1) {
+        lcd.drawRect(3,18,3,3,FILL_BLACK);
+    } else if (_select == 2) {
+        lcd.drawRect(3,26,3,3,FILL_BLACK);
+    } 
     
     lcd.refresh();
 
+
 }
 
+void Menu::print_highscore(N5110 &lcd, int highscore)
+{
+    lcd.clear();
+    
+    menu_decoration(lcd);
+    
+    lcd.printString("  Highscore.. ", 0,1);
+    lcd.printString("   ..is.. ", 0,2);
+    char buffer[14];
+            sprintf(buffer,"%i", highscore);
+            lcd.printString(buffer,35,3);
+    
+    lcd.printString("  B to go back", 0,4);
+    
+    lcd.refresh();
+    
+}   
+
+float Menu::print_settings(Gamepad &pad, N5110 &lcd)
+{
+    lcd.clear();
+    
+    menu_decoration(lcd);
+    
+    lcd.printString("  Use POT for ", 0,1);
+    lcd.printString("Contrast level", 0,2);
+    
+    float pot = pad.read_pot();
+    float contrast = (pot*0.2f)+0.47f; //scale to 0.47 - 0.67
+    int width = int(pot*84.0f);
+    
+    lcd.drawRect(1,26,80,15,FILL_TRANSPARENT);
+    lcd.drawRect(1,26,width,15,FILL_BLACK);
+    
+    lcd.refresh();
+    
+    return contrast;
+    
+}
+    
+    
+
 
 
 void Menu::B(int x, int y, N5110 &lcd)