Meteor defense project

Dependencies:   N5110 mbed

Revision:
36:2608622e5018
Parent:
34:6ac9541d4c31
Child:
37:45da88e36d1d
--- a/GameEngine/GameEngine.cpp	Sun Apr 23 21:10:37 2017 +0000
+++ b/GameEngine/GameEngine.cpp	Sun Apr 23 22:52:48 2017 +0000
@@ -44,7 +44,7 @@
         _gui.preventDoubleClick(pad);
         while (_gui.upgrading == 1) {
             Variables copyVar = weap.getVar(); //this shit is not working.
-            printf("copyvar %d \n",copyVar.laserDamage);
+            //printf("copyvar %d \n",copyVar.laserDamage);
             _gui.upgrades(copyVar, pad, lcd); //go to the main upgrade page
             if (_gui.saveTheData == 1) {
                 Data _upgrades = _gui.savedata(); //saving data
@@ -66,11 +66,15 @@
 }
 void GameEngine::drawSpawn(N5110 &lcd){
     updateArray(); //clean up & update the array after the spawn took damage.
-    if (drawit == 0) { //DONT FORGET TO CHANGE THIS TO TICKER. MORE EFFICIENT.
+    if (drawit == 0) { //
         drawit = 30;
         spa.randomizeSpawn(Array, charArray);
         spa.moveSpawnABC(Array, Array2, charArray, charArray2);
         spa.moveSpawnDE(Array, Array2, charArray, charArray2);
+        //printf("why u do this to cannon_Firing?? cannon_Firing = %d \n",weap.cannon_Firing);
+        if ( fireInTheHole_flag ==1) { //this code because whenever spawn ABCDE moves, weap.cannon_Firing goes to 0 automatically (NO IDEA WHY)
+            weap.cannon_Firing = 1;    
+        }
     } else {
         drawit -= 0.5;
         spa.moveSpawnDE(Array, Array2, charArray, charArray2);
@@ -86,6 +90,17 @@
         //printf("hi, button is working \n");
         weap.weaponMath(pad);
         weap.drawLaser(Array2, charArray2, lcd);
+        
+        //cannon can only be fired when the laser is switched on.
+        if ( pad.check_event(Gamepad::Y_PRESSED)) { //press button to set flag (fire the cannon)
+            fireInTheHole_flag = 1; 
+        }
+    }
+    if ( fireInTheHole_flag == 1) {
+        weap.cannon(lcd);    
+    }
+    if ( weap.cannon_Firing == 0) { //clear flag when cannon is done 
+        fireInTheHole_flag = 0;
     }
 }
 void GameEngine::checkGameRule(Gamepad &pad, N5110 &lcd) {