Dependencies:   mbed

Revision:
7:8d381315f72c
Parent:
6:a2c72def99f9
--- a/main.cpp	Tue May 26 18:14:03 2020 +0000
+++ b/main.cpp	Tue May 26 22:53:42 2020 +0000
@@ -1,4 +1,4 @@
-/* 
+/*
 ELEC2645 Embedded Systems Project
 School of Electronic & Electrical Engineering
 University of Leeds
@@ -10,6 +10,7 @@
 Date: 10/03/2020
 */
 
+// includes
 #include "mbed.h"
 #include "Gamepad.h"
 #include "N5110.h"
@@ -17,27 +18,30 @@
 #include "Menu.h"
 #include "Game.h"
 
+//objects
 N5110 lcd;
 Gamepad pad;
 Menu menu(lcd,pad);
 
 
-//prototypes
+//functions
 void init();
 void game_function();
 
 //variables
 int g_check = 0;
 
-// functions
+
 int main()
 {
+    //initialises the lcd and the gamepad
     init();
-
     lcd.clear();
+    //creates the initial screen
     menu.initscreen();
-
+    //infinite loop for the game and menu
     while(1) {
+        //checks if the gameover function is returning new game or menu
         if (g_check == 2 || g_check == 0) {
             menu.menu_screen();
             game_function();
@@ -48,12 +52,13 @@
 }
 void init()
 {
-    lcd.init();
-    pad.init();
+    lcd.init();//initialises the screen
+    pad.init();//initialises the gamepad
 }
 
 void game_function()
 {
+    //creates class objects
     Game game;
     game.movement(pad);
     game.draw(lcd, pad);
@@ -66,19 +71,26 @@
         //printf("updating_position");
         game.draw(lcd, pad);
         //printf("draw\n");
+        /*this part is executed if you die, and
+        chose to return to the main menu*/
         if (game.death(lcd, pad) == 2) {
-            g_check = 2;                            //this part is executed if you die, and  
-            break;                                  //chose to return to the main menu
+            g_check = 2;
+            break;
+            /*this part is executed if you die, and
+            chose to play again*/
         } else if (game.death(lcd, pad) == 1) {
-            g_check = 1;                            //this part is executed if you die, and
-            break;                                  //chose to play again
+            g_check = 1;
+            break;
         }
         //printf("death\n");
         game.point(lcd, pad);
         //printf("point\n");
         lcd.refresh();
-        for(int i = 0; i < 25; i++) {
-            wait(pad.read_pot2()/50);
+        /*based on the value of the potentiometer
+        the refresh rate can be increased and
+        by doing so you can increase the speed*/
+        for(int i = 0; i < pad.read_pot2()*50; i++) {
+            wait(0.01);
             game.movement(pad);
         }
     }