Meteor defense project

Dependencies:   N5110 mbed

Revision:
15:c68a5c22a2a2
Parent:
14:064b8d7f348d
Child:
16:ddc4d5669a6e
--- a/GameEngine/GameEngine.cpp	Mon Apr 03 12:48:54 2017 +0000
+++ b/GameEngine/GameEngine.cpp	Mon Apr 03 15:52:59 2017 +0000
@@ -50,10 +50,23 @@
 }
 void GameEngine::bombAndShield(Gamepad &pad, N5110 &lcd) { //cooldown not yet implemented.
     weap.bombCooldown(Array1, pad, lcd);
+    weap.shieldInit(); //only need to run once.
     if (pad.check_event(Gamepad::X_PRESSED)) {
-        //to prevent from detonating the bomb at instant when button is accidentally pressed 
+        //to prevent from detonating the bomb at instant when button X is accidentally pressed 
     }
-    if (pad.buttonhold_B == 1) {
-        weap.energyShield(Array1, Array2, charArray, lcd);
+    if (pad.buttonhold_B == 1) { //if B pressed, generate shield
+        if (weap._shield > 0) { //shield will only activate if the shield has not depleted.
+            weap.energyShield(Array1, Array2, charArray, lcd);
+        } else { //or else, deactivate the shield and recharge the shield.
+            pad.buttonhold_B = 0;
+        }    
+    } 
+    if (pad.buttonhold_B == 0) { // recharge shield 
+        if (weap._shield < weap._shieldCapacity ) {
+            weap._shield = weap._shield + weap._shieldRegenRate;
+            //printf("current shield = %d \n",weap._shield); 
+            printf("shield regen rate = %d \n",weap._shieldRegenRate);
+        }    
     }
+    weap.shieldMeter(lcd);
 }
\ No newline at end of file