Adam Baker 201166301

Dependencies:   mbed Gamepad N5110

Revision:
41:4b20f909bbcb
Parent:
40:f53c70793975
Child:
43:11c5d098ce9d
diff -r f53c70793975 -r 4b20f909bbcb Menu/Menu.cpp
--- a/Menu/Menu.cpp	Tue May 07 18:07:39 2019 +0000
+++ b/Menu/Menu.cpp	Wed May 08 15:22:53 2019 +0000
@@ -1,5 +1,6 @@
 #include "Menu.h"
 
+//nothing needed doing in the constructor or deconstructor 
 Menu::Menu()
 {
 
@@ -10,7 +11,7 @@
 
 }
 
-void Menu::init()               //initialise Menu variables
+void Menu::init()                                                               //initialise Menu variables
 {
     _select = 1;
     _input = 0;
@@ -19,7 +20,7 @@
 }
 
 
-void Menu::title_intro(N5110 &lcd, Gamepad &pad)                //run intro sequence
+void Menu::title_intro(N5110 &lcd, Gamepad &pad)                                //runs intro sequence
 {
     intro_b(lcd, pad);
     intro_bl(lcd, pad);
@@ -32,93 +33,93 @@
     intro_block_head(lcd, pad);
 }
 
-void Menu::intro_b(N5110 &lcd, Gamepad &pad)                    //display b with note
+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);
+    pad.tone(261.3, 0.1);                                                       //plays C, on beat 1
+    B(1,15,lcd);                                                                //displays B sprite
     lcd.refresh();
 }
 
-void Menu::intro_bl(N5110 &lcd, Gamepad &pad)                   //display bl with note
+void Menu::intro_bl(N5110 &lcd, Gamepad &pad)                                   //display bl with note
 {
-    wait(0.2);
+    wait(0.2);  
 
     lcd.clear();
-    pad.tone(293.66, 0.1); //D beat 1.5
-    BL(1,15,lcd);
+    pad.tone(293.66, 0.1);                                                      //plays D, beat 1.5
+    BL(1,15,lcd);                                                               //displays BL sprite                     
     lcd.refresh();
 }
 
-void Menu::intro_blo(N5110 &lcd, Gamepad &pad)                  //display blo with note
+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);
+    pad.tone(440.00, 0.1);                                                      //plays G, beat 2.5
+    BLO(1,15,lcd);                                                              //displays BLO sprite
     lcd.refresh();
 }
 
-void Menu::intro_bloc(N5110 &lcd, Gamepad &pad)                 //display bloc with note
+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);
+    pad.tone(392.00, 0.1);                                                      //Plays A, beat 3.5
+    BLOC(1,15,lcd);                                                             //displays BLOC sprite
     lcd.refresh();
 }
 
-void Menu::intro_block(N5110 &lcd, Gamepad &pad)                //display block with note
+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);
+    pad.tone(220.00, 0.1);                                                      //plays A, beat 4
+    BLOCK(1,15,lcd);                                                            //displays BLOCK sprite
     lcd.refresh();
 }
 
-void Menu::intro_block_h(N5110 &lcd, Gamepad &pad)              //display block h with note
+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
-    BLOCK_H(1,15,lcd);
+    pad.tone(196.00, 0.1);                                                      //plays G, beat 1
+    BLOCK_H(1,15,lcd);                                                          //displays BLOCK H sprite
     lcd.refresh();
 }
 
-void Menu::intro_block_he(N5110 &lcd, Gamepad &pad)              //display block he with note
+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
-    BLOCK_HE(1,15,lcd);
+    pad.tone(220.00, 0.1);                                                      //plays A, beat 1.33
+    BLOCK_HE(1,15,lcd);                                                         //displays BLOCK HE sprite
     lcd.refresh();
 }
 
-void Menu::intro_block_hea(N5110 &lcd, Gamepad &pad)            //display block hea with note
+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);                                                      //plays B, beat 1.66
+    BLOCK_HEA(1,15,lcd);                                                        //displays BLOCK HEA sprite
+    lcd.refresh();
+}
+
+void Menu::intro_block_head(N5110 &lcd, Gamepad &pad)                           //display block head with note
 {
     wait(0.133);
 
     lcd.clear();
-    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);
+    pad.tone(261.63, 0.1);                                                      //plays C, beat 2
+    BLOCK_HEAD(1,15,lcd);                                                       //displays B sprite
     lcd.refresh();
 }
 
@@ -153,7 +154,7 @@
 
 
 
-int Menu::select_input_main(Gamepad &pad, N5110 &lcd)                //selects input using button and joystick 
+int Menu::select_input_main(Gamepad &pad, N5110 &lcd)           //selects input using button and joystick 
 {
 
     if (pad.check_event(Gamepad::A_PRESSED)) {                  //if a button pressed,
@@ -187,20 +188,20 @@
     return _input;
 }
 
-void Menu::print_main_menu(N5110 &lcd)   //can go in menu class.
+void Menu::print_main_menu(N5110 &lcd)                          //prints menu class visuals
 {
     lcd.clear();
 
-    menu_decoration(lcd);
+    menu_decoration(lcd);                                       //top and bottom flashing decoative part
 
-    lcd.printString("   Play Game  ",0,1);
+    lcd.printString("   Play Game  ",0,1);                      //prints menu options
     lcd.printString("  Highscore   ",0,2);
     lcd.printString("    Settings  ",0,3);
     lcd.printString("   Quit...    ",0,4);
 
-    if (_select == 1) {
-        lcd.drawRect(3,10,3,3,FILL_BLACK);
-    } else if (_select == 2) {
+    if (_select == 1) {                                         //depending on _select value, 
+        lcd.drawRect(3,10,3,3,FILL_BLACK);                      //cursor changes position,
+    } else if (_select == 2) {                                  //stays in line with what ever text selected corresponds too
         lcd.drawRect(3,18,3,3,FILL_BLACK);
     } else if (_select == 3) {
         lcd.drawRect(3,26,3,3,FILL_BLACK);
@@ -212,27 +213,27 @@
 
 }
 
-void Menu::menu_decoration(N5110 &lcd) 
+void Menu::menu_decoration(N5110 &lcd)                          //displays animated borders for menu pages 
 {
     
     _count++;                                                   //count increments
 
-    if (_count == 3) {                                          //flash inverts ever 3rd count
+    if (_count == 3) {                                          //flash inverts every 3rd count
         _flash = !_flash;                                       //and count resets to 0
         _count = 0;
     }
 
-    if (_flash) {
+    if (_flash) {                                               //when flash is true displays one version of boarder
         lcd.printString("<><><><><><><>",0,0);
         lcd.printString("><><><><><><><",0,5);
-    } else {
+    } else {                                                    //when false, displays inverted version of boarder, creating an animation 
         lcd.printString("><><><><><><><",0,0);
         lcd.printString("<><><><><><><>",0,5);
     }
     
 }
 
-int Menu::select_input_continue(Gamepad &pad, N5110 &lcd)                //selects input using button and joystick 
+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,
@@ -261,23 +262,23 @@
         _stop = 0;
     }
 
-    print_continue_menu(lcd);                                       //print main menu
+    print_continue_menu(lcd);                                   //print continue menu
 
     return _input;
 }
 
-void Menu::print_continue_menu(N5110 &lcd)   //can go in menu class.
+void Menu::print_continue_menu(N5110 &lcd)                      //prints continues menu's visuals 
 {
     lcd.clear();
 
-    menu_decoration(lcd);
+    menu_decoration(lcd);                                       //prints decorative border 
 
 
-    lcd.printString("   Continue   ",0,2);                      
-    lcd.printString("   Go  back   ",0,3);
+    lcd.printString("   Continue   ",0,2);                      //prints continue menus options   
+    lcd.printString("   Go  back   ",0,3);                      
 
 
-    if (_select == 1) {
+    if (_select == 1) {                                         //prints cursor in correct possition according to _select
         lcd.drawRect(3,18,3,3,FILL_BLACK);
     } else if (_select == 2) {
         lcd.drawRect(3,26,3,3,FILL_BLACK);
@@ -288,43 +289,43 @@
 
 }
 
-void Menu::print_highscore(N5110 &lcd, int highscore)
+void Menu::print_highscore(N5110 &lcd, int highscore)           //prints highscore menu 
 {
     lcd.clear();
     
-    menu_decoration(lcd);
+    menu_decoration(lcd);                                       //prints decorative border
     
-    lcd.printString("  Highscore.. ", 0,1);
+    lcd.printString("  Highscore.. ", 0,1);                     
     lcd.printString("   ..is.. ", 0,2);
     char buffer[14];
-            sprintf(buffer,"%i", highscore);
+            sprintf(buffer,"%i", highscore);                    //displays high score
             lcd.printString(buffer,35,3);
     
-    lcd.printString("  B to go back", 0,4);
+    lcd.printString("  B to go back", 0,4);                     
     
     lcd.refresh();
     
 }   
 
-float Menu::print_settings(Gamepad &pad, N5110 &lcd)
+float Menu::print_settings(Gamepad &pad, N5110 &lcd)            //prints settings menu 
 {
     lcd.clear();
     
-    menu_decoration(lcd);
+    menu_decoration(lcd);                                       //prints decorative border
     
     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);
+    float pot = pad.read_pot();                                 //read pot value
+    float contrast = (pot*0.2f)+0.47f;                          //scale to 0.47 - 0.67  (contrast out side of this makes screen unreadable)
+    int width = int(pot*84.0f);                                 //scale pot tp 0 - 84 in integer steps 
     
-    lcd.drawRect(1,26,80,15,FILL_TRANSPARENT);
-    lcd.drawRect(1,26,width,15,FILL_BLACK);
+    lcd.drawRect(1,26,80,10,FILL_TRANSPARENT);                  //draw rectangle
+    lcd.drawRect(1,26,width,10,FILL_BLACK);                     //fill rectangle, depending where the pot is 
     
     lcd.refresh();
     
-    return contrast;
+    return contrast;                                            //returns contrast
     
 }
     
@@ -332,7 +333,7 @@
 
 
 
-void Menu::B(int x, int y, N5110 &lcd)
+void Menu::B(int x, int y, N5110 &lcd)                          //prints B sprite
 {
 
     const int B[48][84] =   {
@@ -364,7 +365,7 @@
 
 }
 
-void Menu::BL(int x, int y, N5110 &lcd)
+void Menu::BL(int x, int y, N5110 &lcd)                         //prints BL sprite
 {
 
     const int BL[48][84] =   {
@@ -396,7 +397,7 @@
 
 }
 
-void Menu::BLO(int x, int y, N5110 &lcd)
+void Menu::BLO(int x, int y, N5110 &lcd)                        //prints BLO sprite
 {
 
     const int BLO[48][84] =   {
@@ -428,7 +429,7 @@
 
 }
 
-void Menu::BLOC(int x, int y, N5110 &lcd)
+void Menu::BLOC(int x, int y, N5110 &lcd)                       //prints BLOC sprite
 {
 
     const int BLOC[48][84] =   {
@@ -460,7 +461,7 @@
 
 }
 
-void Menu::BLOCK(int x, int y, N5110 &lcd)
+void Menu::BLOCK(int x, int y, N5110 &lcd)                      //prints BLOCK sprite
 {
 
     const int BLOCK[48][84] =   {
@@ -488,13 +489,13 @@
 
     };
 
-    lcd.drawSprite(x,y,48,84,(int *)BLOCK);
+    lcd.drawSprite(x,y,48,84,(int *)BLOCK);                     
 
 }
 
 
 
-void Menu::BLOCK_H(int x, int y, N5110 &lcd)
+void Menu::BLOCK_H(int x, int y, N5110 &lcd)                    //prints BLOCK H sprite
 {
 
     const int BLOCK_H[48][84] =   {
@@ -526,7 +527,7 @@
 
 }
 
-void Menu::BLOCK_HE(int x, int y, N5110 &lcd)
+void Menu::BLOCK_HE(int x, int y, N5110 &lcd)                    //prints BLOCK HE sprite
 {
 
     const int BLOCK_HE[48][84] =   {
@@ -558,7 +559,7 @@
 
 }
 
-void Menu::BLOCK_HEA(int x, int y, N5110 &lcd)
+void Menu::BLOCK_HEA(int x, int y, N5110 &lcd)                      //prints BLOCK HEA sprite
 {
 
     const int BLOCK_HEA[48][84] =   {
@@ -590,7 +591,7 @@
 
 }
 
-void Menu::BLOCK_HEAD(int x, int y, N5110 &lcd)
+void Menu::BLOCK_HEAD(int x, int y, N5110 &lcd)                      //prints BLOCK HEAD sprite
 {
 
     const int BLOCK_HEAD[48][84] =   {