Kern Fowler / Mbed 2 deprecated Donkey_Kong_Game

Dependencies:   mbed

Revision:
16:3abc974e8f69
Parent:
14:d6fbbb912425
Child:
17:ac0cb2980f6e
--- a/main.cpp	Wed May 08 20:24:57 2019 +0000
+++ b/main.cpp	Wed May 08 21:35:51 2019 +0000
@@ -6,10 +6,12 @@
 Name: Kern Fowler
 Username: el17kjtf
 Student ID Number: 201116686
-Date: 19/02/2019
-Version: 1.2
+Date: 08/05/2019
+Version: 1.4
 
 */
+
+// Includes all required classes in their respective libraries.
 #include "mbed.h"
 #include "N5110.h"
 #include "Gamepad.h"
@@ -17,33 +19,38 @@
 #include "Options.h"
 #include "Controls.h"
 #include "Instructions.h"
+#include "HighScores.h"
 #include "Banana.h"
 #include "Barrel.h" 
 #include "GameEngine.h"
 
-N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
-Gamepad pad; 
-Donkey dky;
-Barrel barrel;
-Banana banana;
-GameEngine eng;
-Options opt;
-Controls cont;
-Instructions instr;
+// Define all objects.
+N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // LCD class object- pins format required only in define. 
+Gamepad pad; // Gamepad class obejct.
+Donkey dky; // Donkey Kong class object.
+Barrel barrel; // Barrel class object.
+Banana banana; // Banana class object.
+GameEngine eng; // GameEngine class object.
+Options opt; // Options Menu class object.
+Controls cont; // Controls Menu class object.
+Instructions instr; // Instructions Menu class object.
+HighScores high; // HighScores Menu class object.
+Serial pc(USBTX, USBRX); // Used for testing.
 
-
-void init();
+// Prototypes
+void init(); // 
 void print_menu();
 void welcome();
 void arrow_location();
 void arrow_select();
 
+// Intialise Menu Variables
 int fps = 24;
 int direction;
 int menu_option_pos = 0;
 int arrow_pos = 0;
 
-int menu_arrow[7][7] = { // Arrow pointer used in main menu
+int menu_arrow[7][7] = { // Arrow pointer sprite used in main menu.
 {0,0,0,0,0,0,0,},
 {0,0,0,0,1,0,0,},
 {0,0,0,0,1,1,0,},
@@ -53,7 +60,7 @@
 {0,0,0,0,0,0,0,},
 };
 
-int menu_dk_face[36][34] =   { // donkey kong face for menu
+int menu_dk_face[36][34] =   { // Donkey Kong face sprite used in opening scene.
     { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0 },
     { 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0 },
     { 0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0 },
@@ -92,41 +99,34 @@
     { 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0 },
     };
 
-
-
-
-// High Scores-----------------------
-void high_scores_run();
-
-// Main Menu --------------------------------------------------------------
+// Functions
 int main() {
-    init();  // initialise peripherals
-    welcome();  // display welcome message
- 
-    while(1) {  // infinite loop
-    arrow_location();
-    print_menu();  // this re-prints the menu at the start of every loop
-    arrow_select();
+    init();  // Initialises the LCD and Gamepad.
+    welcome();  // Displays welcome screen, has information about the creator and title screen.
+    while(1) {  // Main menu loop
+    arrow_location(); // Determines arrow position on screen, will go up and down with joystick commands.
+    print_menu();  // This re-prints the menu at the start of every loop.
+    arrow_select(); // Will select the current menu options when A button pressed.
     wait_ms(1.0f/fps);
     }
 }
- 
+
+// Initialises Gamepad and LCD.
 void init() {
-    // initialise LCD
     lcd.init();
-    // initialise Gamepad
     pad.init();
     wait(2.5);
 }
 
+// Moves arrow sprite up or down depending on joystick commands. If reaches the bottom will go back to top position.
 void arrow_location() {
     direction  = pad.get_direction();
-    if (direction == N) {
+    if (direction == N) { // Will occur if the joystick is pushed up.
         menu_option_pos = menu_option_pos - 1;
         // printf("North Pressed");
         wait_ms(250);
     }
-    if (direction == S) {
+    if (direction == S) { // Will occur if the joystick is pushed down.
         menu_option_pos = menu_option_pos + 1;
         // printf("South Pressed");
         wait_ms(250);
@@ -137,36 +137,38 @@
     if (menu_option_pos < 0) {
         menu_option_pos = 4;
     }
-    arrow_pos = 8 + (menu_option_pos * 8);
+    arrow_pos = 8 + (menu_option_pos * 8); // Sets and offset due to sprite and font size.
     // printf("Option Num = %d", menu_option_pos)
 }
 
+// Runs the current menu option the arrow has selected when A is pressed.
 void arrow_select() {
     if (pad.check_event(Gamepad::A_PRESSED) == true) {
-        if (menu_option_pos == 0) {
+        if (menu_option_pos == 0) { // Start Game option.
             // printf("GameEngine");
-            eng.gameengine_run(pad, lcd, barrel, banana, dky);
-            eng.gameengine_score(pad, lcd, banana);
+            eng.gameengine_run(pad, lcd, barrel, banana, dky); // Runs the main game loop in the GameEngine class.
+            eng.gameengine_score(pad, lcd, banana); // When gameover is reached, runs the end game screen.
         }
-        if (menu_option_pos == 1) {
+        if (menu_option_pos == 1) { // Controls option.
             // printf("Controls");
-            cont.controls_run(pad, lcd);
+            cont.controls_run(pad, lcd); // Runs the controls screen loop.
         }
-        if (menu_option_pos == 2) {
+        if (menu_option_pos == 2) { // Instructions option.
             // printf("Instructions");
-            instr.instructions_run(pad, lcd);
+            instr.instructions_run(pad, lcd); // Runs the instructions screen loop.
         }
-        if (menu_option_pos == 3) {
+        if (menu_option_pos == 3) { // Options option.
             // printf("Options");
-            opt.options_run(pad, lcd);
+            opt.options_run(pad, lcd); // Runs the options screen loop.
         }
-        if (menu_option_pos == 4) {
+        if (menu_option_pos == 4) { // High Scores option.
             // printf("High Scores");
-            high_scores_run();
+            high.highscores_run(pad, lcd, banana); // Runs the highscores screen loop.
         }
     }
 }
 
+// Prints the main menu, with options and the selector arrow.
 void print_menu() {
     lcd.clear();
     lcd.printString("Main Menu",19,0);
@@ -179,52 +181,21 @@
     lcd.refresh();
 }
  
+// Prints basic information about the game, and plays title screen.
 void welcome() {
     lcd.clear();
-    lcd.drawSprite(24,0,36,34,(int *)menu_dk_face); 
-    lcd.printString("  Donkey Kong",0,5);
+    lcd.drawSprite(24,0,36,34,(int *)menu_dk_face); // Donkey Kong sprite for main menu
+    lcd.printString("Donkey Kong",0,5); // Game title.
     lcd.refresh();
-    wait(1.0); //edit back to longer
+    wait(4.0); 
     lcd.clear();
-    lcd.printString("  Created",0,0);
+    lcd.printString("  Created",0,0); // Information about creator.
     lcd.printString("  By",0,1);
     lcd.printString("  Kern Fowler",0,3);
     lcd.printString("  201116686",0,4);
     lcd.refresh();
-    wait(1.0);
+    wait(4.0);
 }
 
 
-// Donkey -----------
-
-// Barrel -----------
-
-
-
-// Banana -----------
-
-
-
-// Game State--------------------------------------------------------------
-
-
-
 
-
-// Instructions State------------------------------------------------------
-
-
-// Options State-----------------------------------------------------------
-
-
-// High Score State--------------------------------------------------------
-void high_scores_run() {
-    while (pad.check_event(Gamepad::BACK_PRESSED) == false) {
-        //printf("High Score State");
-        lcd.clear();
-        lcd.printString("High Scores",12,0);
-        lcd.refresh();
-        wait_ms(1.0f/fps);
-    }
-}
-