Meteor defense project

Dependencies:   N5110 mbed

Revision:
13:38cbce17d7d7
Parent:
9:4c4d787c7a8b
Child:
14:064b8d7f348d
diff -r a187ba9783f4 -r 38cbce17d7d7 Spawn/Spawn.cpp
--- a/Spawn/Spawn.cpp	Wed Mar 29 22:36:41 2017 +0000
+++ b/Spawn/Spawn.cpp	Thu Mar 30 11:13:20 2017 +0000
@@ -10,34 +10,48 @@
 
 }
 
-void Spawn::randomizeSpawn(int Arr1[][Rows], int Arr2[][Rows]) {
-    
-    if (stopSpawn ==0) {
-        stopSpawn = 1;
+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++) {
+                //16/200 chance of spawning for A.
+                //can depends on level
+                bool TrueFalseA = (rand() % 200) < 16;
+                if (TrueFalseA) {
+                    //spawning from the top of the screen
+                    Arr2[x][0] = 1;
+                    Arr3[x][0] = 'a';
+                    //printf("spawn set at x = is %d \n",x);
+                }
+            }    
+            stopSpawnA= 1;
+        } else {
+            stopSpawnA = 0;
+        }
         for ( int x = 0; x < Cols; x++) {
-            //10% chance of spawning
-            //can depends on level 
-            bool TrueFalse = (rand() % 100) < 10;
-            if (TrueFalse) {
-                //spawning from the top of the screen
-                Arr2[x][0] = 1;
-                //printf("spawn set at x = is %d \n",x);
+            bool TrueFalseB = (rand() % 200) < 1;
+            if (TrueFalseB) {
+                Arr2[x][0] = 10000;
+                Arr3[x][0] = 'b';
+            }
+            bool TrueFalseC = (rand() % 200) < 1;
+            if (TrueFalseC) {
+                Arr2[x][0] = 10;
+                Arr3[x][0] = 'c';
             }
         }
         //printf("at x=2, y=0. value = %d \n",Arr1[2][0]);
-    } else {
-        stopSpawn = 0;
-    }
-    
 }
-void Spawn::moveSpawn(int Arr1[][Rows], int Arr2[][Rows]) {
+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
-    for ( int x = 0; x < Cols; x++) {
-        for ( int y = 0; y < Rows; y++) {
+    for (int x = 0; x < Cols; x++) {
+        for (int y = 0; y < Rows; y++) {
             if (Arr2[x][y] > 0) {
                 //move it down a row
                 Arr1[x][y+1] = Arr2[x][y];       
+                Arr3[x][y+1] = Arr3[x][y];
+                Arr3[x][y] = '\0';
             } else {
                 Arr1[x][y+1] = 0;
             }
@@ -45,20 +59,48 @@
     }
     printf("at x=2, y=47. number is =%d \n",Arr2[2][47]);  
 }
+void Spawn::moveSpawnB(int Arr1[][Rows], int Arr2[][Rows], char Arr3[][Rows]){
+    //printf("moving spawn B \n");
+    for (int x = 0; x < Cols; x++) {
+        for (int y = 0; y < Rows; y++) {
+            if (Arr2[x][y] > 8000) {
+                Arr1[x][y+1] = Arr2[x][y];
+                Arr1[x][y] = 0;
+                Arr3[x][y+1] = 'b';
+                Arr3[x][y] = '\0';
+            }
+        }
+    }            
+}
 
-void Spawn::updateSpawn(int Arr1[][Rows], int Arr2[][Rows],N5110 &lcd) {
+void Spawn::updateSpawn(int Arr1[][Rows], int Arr2[][Rows], char Arr3[][Rows],N5110 &lcd) {
     for ( int x = 0; x < Cols; x++) {
         for ( int y = 0; y < Rows; y++) {
-            if (Arr1[x][y] > 0) {
+            if (Arr3[x][y] == 'a') {
                 lcd.setPixel(x,y);
                 //to update array1 
                 Arr2[x][y] = Arr1[x][y];
-            } else {
+            } else if (Arr3[x][y] == 'b') {
+                lcd.setPixel(x,y);
+                lcd.setPixel(x,y+1);
+                Arr2[x][y] = Arr1[x][y];                
+            } else if (Arr3[x][y] == 'c') {
+                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];
+            }else {
                 Arr2[x][y] = 0;
             }
+            deleteChar(x, y, Arr1, Arr3);
         }
     }
 }
-
+void Spawn::deleteChar(int x, int y, int Arr1[][Rows], char Arr3[][Rows]) {
+    if (Arr1[x][y] == 0) {
+        Arr3[x][y] = '\0';
+    }   
+}
 
                 
\ No newline at end of file