Kern Fowler / Mbed 2 deprecated Donkey_Kong_Game

Dependencies:   mbed

Revision:
2:6baf849b0270
Parent:
1:7a0917df015a
Child:
3:b248dc1f3e8d
diff -r 7a0917df015a -r 6baf849b0270 main.cpp
--- a/main.cpp	Tue Apr 23 17:10:14 2019 +0000
+++ b/main.cpp	Sun May 05 01:03:27 2019 +0000
@@ -7,113 +7,151 @@
 Username: el17kjtf
 Student ID Number: 201116686
 Date: 19/02/2019
-Version: 1.1
+Version: 1.2
 
 */
 #include "main.h"
 
-N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
-Gamepad pad; 
-Engine eng;
-Controller cont;
 
-int main()
-{
+int fps = 24;
+int direction;
+int option_pos = 0;
+int arrow_pos = 0;
+
+int main() {
     init();  // initialise peripherals
     welcome();  // display welcome message
  
     while(1) {  // infinite loop
-    
-    if(pad.get_direction() != dirPos){
-        dirPos = pad.get_direction();
-        menuPos = modf(menuPos - (dirPos == N) + (dirPos == S), 3);
-    }
-    if()
-        print_menu();  // this re-prints the menu at the start of every loop
-        switch(choice) {
-            case 0: gamerun(); break
-            case 1: controls(); break
-            case 2: instructions(); break
-            case 3: options(); break
-        }
-        // delay to prevent multiple button presses being detected
-        wait_ms(1.0f/fps);
- 
+    arrow_location();
+    print_menu();  // this re-prints the menu at the start of every loop
+    arrow_select();
+    wait_ms(1.0f/fps);
     }
 }
  
-void init()
-{
- 
+void init() {
     // initialise LCD
     lcd.init();
-
     // initialise Gamepad
     pad.init();
-    int fps = 24
-    int menuPos = 0;
-    int selected = -1;
-    Direction dirPos = CENTRE;
+    wait(2.5);
+}
+
+void arrow_location() {
+    direction  = pad.get_direction();
+    if (direction == N) {
+        option_pos = option_pos - 1;
+        // printf("North Pressed");
+        wait_ms(250);
+    }
+    if (direction == S) {
+        option_pos = option_pos + 1;
+        // printf("South Pressed");
+        wait_ms(250);
+    }
+    if (option_pos > 3) {
+        option_pos = 0;
+    }
+    if (option_pos < 0) {
+        option_pos = 3;
+    }
+    arrow_pos = 16 + (option_pos * 8);
+    // printf("Option Num = %d", option_pos)
+}
+
+void arrow_select() {
+    if (pad.check_event(Gamepad::A_PRESSED) == true) {
+        if (option_pos == 0) {
+            // printf("GameEngine");
+            game_engine_run();
+        }
+        if (option_pos == 1) {
+            // printf("Controls");
+            controls_run();
+        }
+        if (option_pos == 2) {
+            // printf("Instructions");
+            instructions_run();
+        }
+        if (option_pos == 3) {
+            // printf("Options");
+            options_run();
+        }
+    }
+}
 
 
-    wait(2.5)
-
-    
+void print_menu() {
+    lcd.clear();
+    lcd.printString("Main Menu",18,0);
+    lcd.printString("Start Game",8,2);
+    lcd.printString("Controls",8,3);
+    lcd.printString("Instructions",8,4);
+    lcd.printString("Options",8,5);
+    lcd.drawSprite(0,arrow_pos,7,7,(int *)menu_arrow);
+    lcd.refresh();
 }
  
-void print_menu()
-{
+void welcome() {
     lcd.clear();
-    lcd.printString("Main Menu",0,0);
-    lcd.printString("Start Game",0,2);
-    lcd.printString("Controls",0,3);
-    lcd.printString("Instructions",0,4);
-    lcd.printString("Options",0,5);
-    lcd.refresh();
-    
-}
- 
-void welcome()
-{
-
-    lcd.clear();
-    lcd.drawSprite(24,0,36,34,(int *)dk_menu_face); 
+    lcd.drawSprite(24,0,36,34,(int *)menu_dk_face); 
     lcd.printString("  Donkey Kong",0,5);
     lcd.refresh();
-    wait(5.0);
+    wait(1.0); //edit back to longer
     lcd.clear();
-    lcd.printString("  Created",0,2);
-    lcd.printString("  By",0,3);
-    lcd.printString("  Kern Fowler",0,4);
-    lcd.printString("  201116686",0,5);
-    lcd.refresh();
-    wait(5.0);
-}
-void print_menu()
-{
-    lcd.clear();
-    lcd.printString("Main Menu",0,0);
-    lcd.printString("Start Game",0,2);
-    lcd.printString("Controls",0,3);
-    lcd.printString("Instructions",0,4);
-    lcd.printString("Options",0,5);
+    lcd.printString("  Created",0,0);
+    lcd.printString("  By",0,1);
+    lcd.printString("  Kern Fowler",0,3);
+    lcd.printString("  201116686",0,4);
     lcd.refresh();
-    
+    wait(1.0);
 }
- 
-void welcome()
-{
+
+void game_engine_run() {
+    wait_ms(250);
+
+    while (pad.check_event(Gamepad::BACK_PRESSED) == false) {
+        //printf("Game State");
+        lcd.clear();
+        lcd.printString("  Game",0,0);
+        lcd.refresh();
+        wait_ms(1.0f/fps);
+    }
+}
+
+void controls_run() {
+    wait_ms(250);
 
-    lcd.clear();
-    lcd.drawSprite(24,0,36,34,(int *)dk_menu_face); 
-    lcd.printString("  Donkey Kong",0,5);
-    lcd.refresh();
-    wait(5.0);
-    lcd.clear();
-    lcd.printString("  Created",0,2);
-    lcd.printString("  By",0,3);
-    lcd.printString("  Kern Fowler",0,4);
-    lcd.printString("  201116686",0,5);
-    lcd.refresh();
-    wait(5.0);
+    while (pad.check_event(Gamepad::BACK_PRESSED) == false) {
+        //printf("Control State");
+        lcd.clear();
+        lcd.printString("  Controls",0,0);
+        lcd.refresh();
+        wait_ms(1.0f/fps);
+    }
+}
+
+void instructions_run() {
+    wait_ms(250);
+
+    while (pad.check_event(Gamepad::BACK_PRESSED) == false) {
+        //printf("Instructions State");
+        lcd.clear();
+        lcd.printString("  Instructions",0,0);
+        lcd.refresh();
+        wait_ms(1.0f/fps);
+    }
+}
+
+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.refresh();
+        wait_ms(1.0f/fps);
+    }
 }
\ No newline at end of file