Meteor defense project

Dependencies:   N5110 mbed

Revision:
18:d82059ce929b
Parent:
16:ddc4d5669a6e
Child:
19:7ccbb19703f9
--- a/Spawn/Spawn.cpp	Mon Apr 10 09:56:47 2017 +0000
+++ b/Spawn/Spawn.cpp	Mon Apr 10 11:13:10 2017 +0000
@@ -9,17 +9,23 @@
 {
 
 }
-
+void Spawn::init() {
+    healthA = 10;
+    healthC = 100;
+    spawnRateA = 32;
+    spawnRateB = 1;
+    spawnRateC = 2;
+}
 void Spawn::randomizeSpawn(int 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) < 32;
+                bool TrueFalseA = (rand() % 200) < spawnRateA;
                 if (TrueFalseA) {
                     //spawning from the top of the screen
-                    Arr2[x][0] = 1;
+                    Arr2[x][0] = healthA;
                     Arr3[x][0] = 'a';
                     //printf("spawn set at x = is %d \n",x);
                 }
@@ -29,14 +35,14 @@
             stopSpawnA = 0;
         }
         for ( int x = 0; x < Cols; x++) {
-            bool TrueFalseB = (rand() % 200) < 1;
+            bool TrueFalseB = (rand() % 200) < spawnRateB;
             if (TrueFalseB) {
                 Arr2[x][0] = 100000;
                 Arr3[x][0] = 'b';
             }
-            bool TrueFalseC = (rand() % 200) < 1;
+            bool TrueFalseC = (rand() % 200) < spawnRateC;
             if (TrueFalseC) {
-                Arr2[x][0] = 10;
+                Arr2[x][0] = healthC;
                 Arr3[x][0] = 'c';
             }
         }
@@ -48,7 +54,7 @@
     for (int x = 0; x < Cols; x++) {
         for (int y = 0; y < Rows; y++) {
             if (Arr2[x][y] > 0) {
-                //move it down a row
+                //move everything down a row
                 Arr1[x][y+1] = Arr2[x][y];       
                 Arr3[x][y+1] = Arr3[x][y];
                 Arr3[x][y] = '\0';
@@ -63,7 +69,7 @@
     //printf("moving spawn B \n");
     for (int x = 0; x < Cols; x++) {
         for (int y = 0; y < Rows; y++) {
-            if (Arr2[x][y] > 10000) { //any number larger than this must be spawn b.
+            if (Arr2[x][y] > 20000) { //any number larger than this must be spawn b.
                 Arr1[x][y+1] = Arr2[x][y];
                 Arr1[x][y] = 0;
                 Arr3[x][y+1] = 'b';
@@ -81,17 +87,14 @@
                 //to update array1 
                 Arr2[x][y] = Arr1[x][y];
             } else if (Arr3[x][y] == 'b') {
-                lcd.setPixel(x,y);
-                lcd.setPixel(x,y+1);
+                lcd.setPixel(x,y); lcd.setPixel(x,y+1);
                 Arr2[x][y] = Arr1[x][y];                
             } else if (Arr3[x][y] == 'c') {
                 Arr3[x-1][y-1] = 'l';
                 Arr3[x+1][y-1] = 'r';
-                lcd.setPixel(x,y);
-                lcd.setPixel(x,y+1);
-                lcd.setPixel(x+1,y);
-                lcd.setPixel(x-1,y);
                 Arr2[x][y] = Arr1[x][y];
+                lcd.setPixel(x,y); lcd.setPixel(x,y+1);
+                lcd.setPixel(x+1,y); lcd.setPixel(x-1,y);
             }else {
                 Arr2[x][y] = 0;
             }