Meteor defense project

Dependencies:   N5110 mbed

Revision:
19:7ccbb19703f9
Parent:
18:d82059ce929b
Child:
20:32f115462bbc
diff -r d82059ce929b -r 7ccbb19703f9 GameEngine/GameEngine.cpp
--- a/GameEngine/GameEngine.cpp	Mon Apr 10 11:13:10 2017 +0000
+++ b/GameEngine/GameEngine.cpp	Wed Apr 12 13:53:37 2017 +0000
@@ -14,6 +14,7 @@
     _d2.droneInit(62, 46, 83);   
     weap.init();
     spa.init();
+    //printf("init completed \n");
 }
 void GameEngine::update(Gamepad &pad, N5110 &lcd) {
     _d1.drone(Array1, charArray, lcd);
@@ -23,21 +24,23 @@
     bombAndShield(pad, lcd);
 }
 void GameEngine::drawSpawn(N5110 &lcd){
-    //spawning every 2 second, moving every 1 seconds at 15 fps & drawit=15. 
+    //spawning every 2 second, moving spawn at every 1 seconds when fps = 15 & drawit=30. 
     //It changes depending on the game FPS.
-    if (drawit ==0) {
-        drawit =30;
+    if (drawit == 0) {
+        drawit = 30;
         spa.randomizeSpawn(Array2, charArray);
         spa.moveSpawnABC(Array1, Array2, charArray);
+        
     } else {
-        drawit -=0.5;
+        drawit -= 0.5;
         spa.moveSpawnB(Array1, Array2, charArray);
+        //printf("moving spawn b \n");
     }
     spa.updateSpawn(Array1, Array2, charArray, lcd); 
     //checkGameRule(lcd);
 }
 void GameEngine::drawLaserPlayer(Gamepad &pad, N5110 &lcd) {
-    weap.drawWeapon(pad, lcd);
+    weap.drawPlayer(pad, lcd);
     //draw a line for the laser when button is pressed
     if (pad.buttonhold_A == 1) {
         //printf("hi, button is working \n");
@@ -45,7 +48,6 @@
         weap.drawLaser(Array1, charArray, lcd);
     }
 }
-
 void GameEngine::checkGameRule(N5110 &lcd) {
     //the only way to lose is when the spawn reaches y = 46.
     for ( int x = 0; x < 84; x ++) {
@@ -64,7 +66,7 @@
     if (pad.check_event(Gamepad::X_PRESSED)) {
         //to prevent from detonating the bomb at instant when button X is accidentally pressed 
     }
-    if (pad.buttonhold_B == 1) { //if B pressed, generate shield
+    if (pad.buttonhold_B == 1) { //if B pressed, generate shield. Shield doesnt have to be fully charged to be activated
         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.
@@ -76,7 +78,9 @@
             weap._shield = weap._shield + weap._shieldRegenRate;
             //printf("current shield = %d \n",weap._shield); 
             //printf("shield regen rate = %d \n",weap._shieldRegenRate);
-        }    
+        } else { //when the shield is fully charged. It will automatically activate the shield.
+            pad.buttonhold_B = 1;
+        }
     }
     weap.shieldMeter(lcd);
 }
\ No newline at end of file