Game codes for Pokemon Academy Yiu Fai Kwok - 201198802 I have read the University Regulations on Plagiarism and state that the work covered by this declaration is my own and does not contain any unacknowledged work from other sources.

Dependencies:   mbed FXOS8700CQ mbed-rtos

Revision:
33:f7ec806e14b6
Parent:
29:75a05e9f0e8d
--- a/Game_two/Game_two.cpp	Wed May 08 15:14:55 2019 +0000
+++ b/Game_two/Game_two.cpp	Wed May 08 23:57:04 2019 +0000
@@ -44,6 +44,7 @@
 
 }
 
+// Function to render the images
 void Game_two::render(N5110 &lcd, int cha)
 {
     lcd.clear();
@@ -51,12 +52,14 @@
     lcd.refresh();    
 }
 
+// Function to read the input from the FXOS8700CQ device to get direction and magnitude
 void Game_two::read_input(FXOS8700CQ &device)
 {
     _d = device.get_direction();
     _mag = device.get_mag();
 }
 
+// Function to draw all objects in the game
 void Game_two::draw(N5110 &lcd, int cha)
 {
     int alt = update_alt();
@@ -65,15 +68,19 @@
     else {_p1.draw_alt(lcd, cha);}
     // spawn app icon
     if(_type < _rand) {
-        if (_so == 0) {_insta.draw(lcd);}
-        else if (_so == 1) {_face.draw(lcd);}
-        else if (_so == 2) {_twitt.draw(lcd);}
+        if (_so == 0) {_insta.draw(lcd);}           // Draw instagram if _so is randomized to 0
+        else if (_so == 1) {_face.draw(lcd);}       // Draw facebook if _so is randomized to 1
+        else if (_so == 2) {_twitt.draw(lcd);}      // Draw twitter if _so is randomized to 2
     }
-    else {_yt.draw(lcd);}
+    else {_yt.draw(lcd);}                           // Draw youtube if _type < _rand
 }
 
 void Game_two::update(Gamepad &pad, N5110 &lcd, int cha)
 {
+    // check if the object is dodged
+    // update the player's position
+    // update the object's position
+    // check if the object is collided with the player
     if (_type < _rand) {
         if (_so == 0){
             check_miss_insta(pad);
@@ -112,10 +119,10 @@
     // see if object has hit the player by checking for overlaps
     if (cha == 1){
         if (
-            (insta_pos.y >= p1_pos.y - 4) && //top
-            (insta_pos.y <= p1_pos.y + 13) && //bottom
-            (insta_pos.x >= p1_pos.x - 4) && //left
-            (insta_pos.x <= p1_pos.x + 15)  //right
+            (insta_pos.y >= p1_pos.y - 4) &&        //top
+            (insta_pos.y <= p1_pos.y + 13) &&       //bottom
+            (insta_pos.x >= p1_pos.x - 4) &&        //left
+            (insta_pos.x <= p1_pos.x + 15)          //right
         ) 
         {
             // write new attributes
@@ -125,10 +132,10 @@
     }
     if (cha == 2){
         if (
-            (insta_pos.y >= p1_pos.y - 5) && //top
-            (insta_pos.y <= p1_pos.y + 14) && //bottom
-            (insta_pos.x >= p1_pos.x - 4) && //left
-            (insta_pos.x <= p1_pos.x + 16)  //right
+            (insta_pos.y >= p1_pos.y - 5) &&        //top
+            (insta_pos.y <= p1_pos.y + 14) &&       //bottom
+            (insta_pos.x >= p1_pos.x - 4) &&        //left
+            (insta_pos.x <= p1_pos.x + 16)          //right
         ) 
         {
             // write new attributes
@@ -138,10 +145,10 @@
     }
     if (cha == 3){
         if (
-            (insta_pos.y >= p1_pos.y - 6) && //top
-            (insta_pos.y <= p1_pos.y + 16) && //bottom
-            (insta_pos.x >= p1_pos.x - 4) && //left
-            (insta_pos.x <= p1_pos.x + 23)  //right
+            (insta_pos.y >= p1_pos.y - 6) &&        //top
+            (insta_pos.y <= p1_pos.y + 16) &&       //bottom
+            (insta_pos.x >= p1_pos.x - 4) &&        //left
+            (insta_pos.x <= p1_pos.x + 23)          //right
         ) 
         {
             // write new attributes
@@ -177,10 +184,10 @@
     // see if object has hit the player by checking for overlaps
     if (cha == 1){
         if (
-            (face_pos.y >= p1_pos.y - 8) && //top
-            (face_pos.y <= p1_pos.y + 18) && //bottom
-            (face_pos.x >= p1_pos.x - 6) && //left
-            (face_pos.x <= p1_pos.x + 20)  //right
+            (face_pos.y >= p1_pos.y - 8) &&         //top
+            (face_pos.y <= p1_pos.y + 18) &&        //bottom
+            (face_pos.x >= p1_pos.x - 6) &&         //left
+            (face_pos.x <= p1_pos.x + 20)           //right
         ) 
         {
             // write new attributes
@@ -190,10 +197,10 @@
     }
     if (cha == 2){
         if (
-            (face_pos.y >= p1_pos.y - 8) && //top
-            (face_pos.y <= p1_pos.y + 21) && //bottom
-            (face_pos.x >= p1_pos.x - 6) && //left
-            (face_pos.x <= p1_pos.x + 21)  //right
+            (face_pos.y >= p1_pos.y - 8) &&         //top
+            (face_pos.y <= p1_pos.y + 21) &&        //bottom
+            (face_pos.x >= p1_pos.x - 6) &&         //left
+            (face_pos.x <= p1_pos.x + 21)           //right
         ) 
         {
             // write new attributes
@@ -203,10 +210,10 @@
     }
     if (cha == 3){
         if (
-            (face_pos.y >= p1_pos.y - 8) && //top
-            (face_pos.y <= p1_pos.y + 21) && //bottom
-            (face_pos.x >= p1_pos.x - 6) && //left
-            (face_pos.x <= p1_pos.x + 29)  //right
+            (face_pos.y >= p1_pos.y - 8) &&         //top
+            (face_pos.y <= p1_pos.y + 21) &&        //bottom
+            (face_pos.x >= p1_pos.x - 6) &&         //left
+            (face_pos.x <= p1_pos.x + 29)           //right
         ) 
         {
             // write new attributes
@@ -242,10 +249,10 @@
     // see if object has hit the player by checking for overlaps
     if (cha == 1){
         if (
-            (twitt_pos.y >= p1_pos.y - 8) && //top
-            (twitt_pos.y <= p1_pos.y + 18) && //bottom
-            (twitt_pos.x >= p1_pos.x - 6) && //left
-            (twitt_pos.x <= p1_pos.x + 20)  //right
+            (twitt_pos.y >= p1_pos.y - 8) &&        //top
+            (twitt_pos.y <= p1_pos.y + 18) &&       //bottom
+            (twitt_pos.x >= p1_pos.x - 6) &&        //left
+            (twitt_pos.x <= p1_pos.x + 20)          //right
         ) 
         {
             // write new attributes
@@ -255,10 +262,10 @@
     }
     if (cha == 2){
         if (
-            (twitt_pos.y >= p1_pos.y - 8) && //top
-            (twitt_pos.y <= p1_pos.y + 21) && //bottom
-            (twitt_pos.x >= p1_pos.x - 6) && //left
-            (twitt_pos.x <= p1_pos.x + 21)  //right
+            (twitt_pos.y >= p1_pos.y - 8) &&        //top
+            (twitt_pos.y <= p1_pos.y + 21) &&       //bottom
+            (twitt_pos.x >= p1_pos.x - 6) &&        //left
+            (twitt_pos.x <= p1_pos.x + 21)          //right
         ) 
         {
             // write new attributes
@@ -268,10 +275,10 @@
     }
     if (cha == 3){
         if (
-            (twitt_pos.y >= p1_pos.y - 8) && //top
-            (twitt_pos.y <= p1_pos.y + 21) && //bottom
-            (twitt_pos.x >= p1_pos.x - 6) && //left
-            (twitt_pos.x <= p1_pos.x + 29)  //right
+            (twitt_pos.y >= p1_pos.y - 8) &&        //top
+            (twitt_pos.y <= p1_pos.y + 21) &&       //bottom
+            (twitt_pos.x >= p1_pos.x - 6) &&        //left
+            (twitt_pos.x <= p1_pos.x + 29)          //right
         ) 
         {
             // write new attributes
@@ -307,10 +314,10 @@
     // see if object has hit the player by checking for overlaps
     if (cha == 1){
         if (
-            (yt_pos.y >= p1_pos.y - 8) && //top
-            (yt_pos.y <= p1_pos.y + 18) && //bottom
-            (yt_pos.x >= p1_pos.x - 25) && //left
-            (yt_pos.x <= p1_pos.x + 20)  //right
+            (yt_pos.y >= p1_pos.y - 8) &&       //top
+            (yt_pos.y <= p1_pos.y + 18) &&      //bottom
+            (yt_pos.x >= p1_pos.x - 25) &&      //left
+            (yt_pos.x <= p1_pos.x + 20)         //right
         ) 
         {
             // write new attributes
@@ -320,10 +327,10 @@
     }
     if (cha == 2){
         if (
-            (yt_pos.y >= p1_pos.y - 8) && //top
-            (yt_pos.y <= p1_pos.y + 21) && //bottom
-            (yt_pos.x >= p1_pos.x - 25) && //left
-            (yt_pos.x <= p1_pos.x + 21)  //right
+            (yt_pos.y >= p1_pos.y - 8) &&       //top
+            (yt_pos.y <= p1_pos.y + 21) &&      //bottom
+            (yt_pos.x >= p1_pos.x - 25) &&      //left
+            (yt_pos.x <= p1_pos.x + 21)         //right
         ) 
         {
             // write new attributes
@@ -333,10 +340,10 @@
     }
     if (cha == 3){
         if (
-            (yt_pos.y >= p1_pos.y - 8) && //top
-            (yt_pos.y <= p1_pos.y + 21) && //bottom
-            (yt_pos.x >= p1_pos.x - 25) && //left
-            (yt_pos.x <= p1_pos.x + 29)  //right
+            (yt_pos.y >= p1_pos.y - 8) &&       //top
+            (yt_pos.y <= p1_pos.y + 21) &&      //bottom
+            (yt_pos.x >= p1_pos.x - 25) &&      //left
+            (yt_pos.x <= p1_pos.x + 29)         //right
         ) 
         {
             // write new attributes