Meteor defense project

Dependencies:   N5110 mbed

Revision:
19:7ccbb19703f9
Parent:
18:d82059ce929b
Child:
20:32f115462bbc
--- a/Spawn/Spawn.cpp	Mon Apr 10 11:13:10 2017 +0000
+++ b/Spawn/Spawn.cpp	Wed Apr 12 13:53:37 2017 +0000
@@ -16,38 +16,47 @@
     spawnRateB = 1;
     spawnRateC = 2;
 }
-void Spawn::randomizeSpawn(int Arr2[][Rows], char Arr3[][Rows]) {
+void Spawn::randomizeSpawn(char Arr2[][Rows], char Arr3[][Rows]) {
         //there is 3 kind of different spawn - a, b and c.
-        if (stopSpawnA == 0) {
-            for ( int x = 0; x < Cols; x++) {
-                //32/200 chance of spawning for A.
-                //can depends on level
-                bool TrueFalseA = (rand() % 200) < spawnRateA;
-                if (TrueFalseA) {
-                    //spawning from the top of the screen
-                    Arr2[x][0] = healthA;
-                    Arr3[x][0] = 'a';
-                    //printf("spawn set at x = is %d \n",x);
-                }
-            }    
+        if (stopSpawnA == 0) { //spawn for this row
+            spawnA(Arr2, Arr3);
             stopSpawnA= 1;
-        } else {
+        } else { //stop spawn for the next row
             stopSpawnA = 0;
         }
         for ( int x = 0; x < Cols; x++) {
-            bool TrueFalseB = (rand() % 200) < spawnRateB;
-            if (TrueFalseB) {
-                Arr2[x][0] = 100000;
-                Arr3[x][0] = 'b';
-            }
-            bool TrueFalseC = (rand() % 200) < spawnRateC;
-            if (TrueFalseC) {
-                Arr2[x][0] = healthC;
-                Arr3[x][0] = 'c';
-            }
+            spawnB(Arr2, Arr3);
+            spawnC(Arr2, Arr3);
         }
         //printf("at x=2, y=0. value = %d \n",Arr1[2][0]);
 }
+void Spawn::spawnA(int Arr2[][Rows],char Arr3[][Rows]) {
+    for ( int x = 0; x < Cols; x++) {
+        //32/200 chance of spawning for A.
+        //can depends on level
+        bool TrueFalseA = (rand() % 200) < spawnRateA;
+        if (TrueFalseA) {
+            //spawning from the top of the screen
+            Arr2[x][0] = healthA;
+            Arr3[x][0] = 'a';
+            //printf("spawn set at x = is %d \n",x);
+        }
+    }    
+}
+void Spawn::spawnB(int Arr2[][Rows],char Arr3[][Rows]) {
+    bool TrueFalseB = (rand() % 200) < spawnRateB;
+    if (TrueFalseB) {
+        Arr2[x][0] = 100000;
+        Arr3[x][0] = 'b';
+    }
+}
+void Spawn:spawnC(int Arr2[][Rows],char Arr3[][Rows]) {
+    bool TrueFalseC = (rand() % 200) < spawnRateC;
+    if (TrueFalseC) {
+        Arr2[x][0] = healthC;
+        Arr3[x][0] = 'c';
+    }
+}
 void Spawn::moveSpawnABC(int Arr1[][Rows], int Arr2[][Rows], char Arr3[][Rows]) {
     //printf("x=2,y =0. value = %d \n",array[2][0]);
     //scan through the whole array