Kern Fowler / Mbed 2 deprecated Donkey_Kong_Game

Dependencies:   mbed

Revision:
3:b248dc1f3e8d
Parent:
2:6baf849b0270
Child:
4:59175720d8ee
diff -r 6baf849b0270 -r b248dc1f3e8d main.cpp
--- a/main.cpp	Sun May 05 01:03:27 2019 +0000
+++ b/main.cpp	Sun May 05 02:16:51 2019 +0000
@@ -15,8 +15,11 @@
 
 int fps = 24;
 int direction;
-int option_pos = 0;
+int menu_option_pos = 0;
 int arrow_pos = 0;
+float brightness = 0.5;
+float contrast = 0.430;
+int volume = 1;
 
 int main() {
     init();  // initialise peripherals
@@ -41,40 +44,40 @@
 void arrow_location() {
     direction  = pad.get_direction();
     if (direction == N) {
-        option_pos = option_pos - 1;
+        menu_option_pos = menu_option_pos - 1;
         // printf("North Pressed");
         wait_ms(250);
     }
     if (direction == S) {
-        option_pos = option_pos + 1;
+        menu_option_pos = menu_option_pos + 1;
         // printf("South Pressed");
         wait_ms(250);
     }
-    if (option_pos > 3) {
-        option_pos = 0;
+    if (menu_option_pos > 3) {
+        menu_option_pos = 0;
     }
-    if (option_pos < 0) {
-        option_pos = 3;
+    if (menu_option_pos < 0) {
+        menu_option_pos = 3;
     }
-    arrow_pos = 16 + (option_pos * 8);
-    // printf("Option Num = %d", option_pos)
+    arrow_pos = 16 + (menu_option_pos * 8);
+    // printf("Option Num = %d", menu_option_pos)
 }
 
 void arrow_select() {
     if (pad.check_event(Gamepad::A_PRESSED) == true) {
-        if (option_pos == 0) {
+        if (menu_option_pos == 0) {
             // printf("GameEngine");
             game_engine_run();
         }
-        if (option_pos == 1) {
+        if (menu_option_pos == 1) {
             // printf("Controls");
             controls_run();
         }
-        if (option_pos == 2) {
+        if (menu_option_pos == 2) {
             // printf("Instructions");
             instructions_run();
         }
-        if (option_pos == 3) {
+        if (menu_option_pos == 3) {
             // printf("Options");
             options_run();
         }
@@ -84,7 +87,7 @@
 
 void print_menu() {
     lcd.clear();
-    lcd.printString("Main Menu",18,0);
+    lcd.printString("Main Menu",19,0);
     lcd.printString("Start Game",8,2);
     lcd.printString("Controls",8,3);
     lcd.printString("Instructions",8,4);
@@ -114,7 +117,7 @@
     while (pad.check_event(Gamepad::BACK_PRESSED) == false) {
         //printf("Game State");
         lcd.clear();
-        lcd.printString("  Game",0,0);
+        lcd.printString("Game",0,0);
         lcd.refresh();
         wait_ms(1.0f/fps);
     }
@@ -126,7 +129,7 @@
     while (pad.check_event(Gamepad::BACK_PRESSED) == false) {
         //printf("Control State");
         lcd.clear();
-        lcd.printString("  Controls",0,0);
+        lcd.printString("Controls",19,0);
         lcd.refresh();
         wait_ms(1.0f/fps);
     }
@@ -138,7 +141,7 @@
     while (pad.check_event(Gamepad::BACK_PRESSED) == false) {
         //printf("Instructions State");
         lcd.clear();
-        lcd.printString("  Instructions",0,0);
+        lcd.printString("Instructions",7,0);
         lcd.refresh();
         wait_ms(1.0f/fps);
     }
@@ -146,12 +149,52 @@
 
 void options_run() {
     wait_ms(250);
-
     while (pad.check_event(Gamepad::BACK_PRESSED) == false) {
         //printf("Options State");
         lcd.clear();
-        lcd.printString("  Options",0,0);
+        lcd.printString("Options",21,0);
+        options_brightness();
+        options_contrast();
+        options_volume();
         lcd.refresh();
         wait_ms(1.0f/fps);
     }
+}
+
+void options_brightness() {
+    if (pad.check_event(Gamepad::B_PRESSED) == true) {
+        brightness = 0;
+    }
+    if (pad.check_event(Gamepad::A_PRESSED) == true) {
+        brightness = 0.5;
+    }
+    lcd.setBrightness(brightness);
+    lcd.printString("A/B = BackLite",0,2);
+}
+
+void options_contrast() {
+    contrast = pad.read_pot();
+    lcd.setContrast(contrast);
+    lcd.printString("Pot = Contrast",0,3);
+}
+
+void options_volume() {
+    if (pad.check_event(Gamepad::Y_PRESSED) == true) {
+        volume = 0;
+    }
+    if (pad.check_event(Gamepad::X_PRESSED) == true) {
+        volume = 1;
+        pad.tone(2400, 0.2);
+        wait_ms(200);
+        pad.tone(2400, 0.2);
+        wait_ms(200);
+        pad.tone(2400, 0.2);
+    }
+    lcd.printString("X/Y = Volume",0,4);
+    if (volume == 0) {
+        lcd.printString("Off",36,5);
+    } else {
+        lcd.printString("On",36,5);
+    }
+    
 }
\ No newline at end of file