My ELEC2645 project. Nikollao Sulollari. 200804685

Dependencies:   N5110 SoftPWM mbed

Fork of Treasure_Hunt by ELEC2645 (2015/16)

Revision:
9:ce2d9c42edea
Parent:
8:606a488fa720
Child:
10:1d229362c134
--- a/main.h	Mon Apr 18 09:59:32 2016 +0000
+++ b/main.h	Mon Apr 18 11:04:35 2016 +0000
@@ -77,6 +77,7 @@
 */
 Ticker ticker;
 
+
 /**
 @nameSpace game_ticker
 @brief interrupt executes a time-triggered task
@@ -180,6 +181,7 @@
 */
 void timeout_isr();
 
+
 /**
 Set current position to default position of Joystick
 */
@@ -279,7 +281,10 @@
 int objectY = 20; /*!< used to move obstacles in the y-axis */
 
 int state = 0; /*!< controls the direction of the objtacle */
-int countObject = 0;
+
+int objectX1 = 58; /*!< used to move obstacles in the x-axis */
+int state1 = 1; /*!< controls the direction of the objtacle */
+
 
 void enemies()
 
@@ -512,20 +517,33 @@
         lcd.drawRect(28,30 + rand() %4 - 2,2,2,1);
         lcd.drawRect(52 + rand() %4 - 2,30,2,2,1);
     }
-    if (objectX == 0) {
-            state = 0;
+    if (objectX == 0) { ///check position of obstacle
+            state = 0; ///assign states to the position of the obstacle
         } 
-        else if (objectX == 58) {
+        else if (objectX == 60) { 
             state = 1;
         } else {
             state = state;
         }
-       if (state == 0) {
+       if (state == 0) { ///if state is 0 increase position on x-axis
             objectX++;
         } else {
-            objectX--;
-        }   
-        objectY = objectY + rand() %4 - 2;
+            objectX--; ///else if state is 1 decrease position on x-axis
+        } 
+        
+        if (objectX1 == 68) {
+          
+          state1 = 1;
+        }
+         else if (objectX1 == 10) {
+          state1 = 0;
+        }
+        if (state1 == 1) {
+            objectX1--;
+        } else if (state1 == 0) {
+            objectX1++;
+        }
+        objectY = objectY + rand() %4 - 2; ///set poistion of obstacle on y-axis to be valuable
         ///keep moving object within boundaries
         if (objectY <= 10) { 
             objectY = 10;
@@ -538,7 +556,7 @@
         lcd.drawLine(15,10,15,37,1);
         lcd.drawLine(71,10,71,37,1);
         
-        lcd.drawRect(11+objectX,objectY,2,2,1); 
+        lcd.drawRect(11+objectX,objectY,2,2,1); ///draw obstacle
         
         lcd.drawRect(80,10,2,2,1);
         lcd.drawRect(5,10,2,2,1);
@@ -550,11 +568,12 @@
     } 
     else if (level == 6) {
         
-        lcd.drawLine(15,10,15,37,1);
+        lcd.drawLine(15,10,15,37,1); ///draw boundaries
         lcd.drawLine(71,10,71,37,1);
         
-        lcd.drawRect(11+objectX,objectY,2,2,1);    
-        lcd.drawRect(80,10,2,2,1);
+        lcd.drawRect(11+objectX,objectY,2,2,1); /// draw moving obstacles on screen
+        lcd.drawRect(objectX1,10+objectY,2,2,1);    
+        lcd.drawRect(80,10,2,2,1); ///draw stable obstacles 
         lcd.drawRect(5,10,2,2,1);
         lcd.drawRect(80,20,2,2,1);
         lcd.drawRect(5,20,2,2,1);
@@ -671,7 +690,6 @@
     }
 }
 
-
 #endif