Meteor defense project

Dependencies:   N5110 mbed

Revision:
34:6ac9541d4c31
Parent:
33:61c69c46a941
Child:
39:f92b93efbc72
--- a/Spawn/Spawn.cpp	Fri Apr 21 14:12:28 2017 +0000
+++ b/Spawn/Spawn.cpp	Sun Apr 23 21:09:32 2017 +0000
@@ -10,24 +10,26 @@
 
 }
 void Spawn::init(int w) {
-    healthA = 7 + w * 2;
-    healthC = 150 + w * 5;
-    healthDE = 20 + w ;
-    spawnRateA = 32 + w; //32
-    spawnRateB = 1 + w / 2; //1
-    spawnRateC = 1 + w ; //2
-    spawnRateDE = 1 + w/ 2; //1
+    A.health = 7 + 2 * w;
+    A.spawnRate = 35 + w;
+    B.health = 0;
+    B.spawnRate = 1 + w / 2;
+    C.health = 150 + w * 5;
+    C.spawnRate = 1 + w;
+    DE.health = 20 + w;
+    DE.spawnRate = 1 + w / 2;
     //randomise the seed. To get different spawn pattern all the time.
     int t = time(NULL);
     //printf("t = %d \n",t);
     srand(t);
 }
+
 void Spawn::randomizeSpawn(int Arr[][Rows], char cArr[][Rows]) {
         //there is 4 kind of different spawn - a, b, c and d/e.
-        if (stopSpawnA == 1) { //spawn for this row
+        if (stopSpawnA == 1) { //spawn spawnA for this row
             spawnA(Arr, cArr);
             stopSpawnA= 0;
-        } else { //stop spawn for the next row
+        } else { //spawn spawnC for this next row
             stopSpawnA = 1;
             spawnC(Arr, cArr);
         }
@@ -39,19 +41,19 @@
 }
 void Spawn::spawnA(int Arr[][Rows],char cArr[][Rows]) {
     for ( int x = 0; x < Cols; x++) {
-        //32/200 chance of spawning for A.
-        //can depends on level
-        bool TrueFalseA = (rand() % 220) < spawnRateA;
+        //35/220 chance of spawning for A.
+        //depends on wave number
+        bool TrueFalseA = (rand() % 220) < A.spawnRate;
         if (TrueFalseA) {
             //spawning from the top of the screen
-            Arr[x][0] = healthA;
+            Arr[x][0] = A.health;
             cArr[x][0] = 'a';
             //printf("spawn set at x = is %d \n",x);
         }
     }    
 }
 void Spawn::spawnB(int x, int Arr[][Rows],char cArr[][Rows]) {
-    bool TrueFalseB = (rand() % 220) < spawnRateB;
+    bool TrueFalseB = (rand() % 220) < B.spawnRate;
     if (TrueFalseB) {
         Arr[x][0] = 100000;
         cArr[x][0] = 'b';
@@ -59,9 +61,9 @@
 }
 void Spawn::spawnC(int Arr[][Rows],char cArr[][Rows]) {
     for ( int x = 0; x < Cols; x++) {
-    bool TrueFalseC = (rand() % 220) < spawnRateC;
+    bool TrueFalseC = (rand() % 220) < C.spawnRate;
         if (TrueFalseC) {
-            Arr[x][1] = healthC;
+            Arr[x][1] = C.health;
             cArr[x][1] = 'c';
             cArr[x-1][0] = 'l';
             cArr[x+1][0] = 'r';
@@ -69,14 +71,14 @@
     }
 }
 void Spawn::spawnDE(int x, int Arr[][Rows], char cArr[][Rows]) {
-    bool TrueFalseD = (rand() % 220) < spawnRateDE;
+    bool TrueFalseD = (rand() % 220) < DE.spawnRate;
     if (TrueFalseD) {
         bool LeftRightD = (rand() % 10) <5; //its a 50-50 chance 
         if (LeftRightD) {
-            Arr[x][0] = healthDE;
+            Arr[x][0] = DE.health;
             cArr[x][0] = 'd'; //d denotes spawnD starts by moving left
         } else {
-            Arr[x][0] = healthDE;
+            Arr[x][0] = DE.health;
             cArr[x][0] = 'e'; //e denotes spawnD starts by moving right          
         }
     }
@@ -177,8 +179,7 @@
                 lcd.setPixel(x,y); lcd.setPixel(x,y-1);
                 lcd.setPixel(x+1,y-1); lcd.setPixel(x-1,y-1);
             } else {
-                Arr[x][y] = 0;
-                cArr[x][y] = '\0';
+                Arr[x][y] = 0; cArr[x][y] = '\0';
             }
         }
     }
@@ -188,6 +189,4 @@
         cArr2[x][y] = '\0';
     //printf("char at Arr2[%d][%d] cleared for good. \n",x,y);
     }  
-}
-
-                
\ No newline at end of file
+}          
\ No newline at end of file