Meteor defense project

Dependencies:   N5110 mbed

Revision:
27:d4926f19c12a
Parent:
26:140515d80457
Child:
29:6632dd9c48d8
--- a/Spawn/Spawn.cpp	Fri Apr 14 15:42:37 2017 +0000
+++ b/Spawn/Spawn.cpp	Fri Apr 14 21:43:05 2017 +0000
@@ -82,7 +82,7 @@
     //scan through the whole array
     for (int x = 0; x < Cols; x++) {
         for (int y = 0; y < Rows; y++) {
-            if (cArr[x][y] == 'a' || cArr[x][y] == 'b' || cArr[x][y] == 'c' || cArr[x][y] == 'l' || cArr[x][y] == 'r') {
+            if (cArr[x][y] == 'a' || cArr[x][y] == 'b' || cArr[x][y] == 'c' || cArr[x][y] == 'l' || cArr[x][y] == 'r' || cArr[x][y] == 'm') {
                 Arr2[x][y+1] = Arr[x][y]; cArr2[x][y+1] = cArr[x][y]; //move everything down a row
             } else {
                 Arr2[x][y+1] = 0; cArr2[x][y+1] = '\0';
@@ -102,12 +102,12 @@
         }
     }        
 }
-void Spawn::movementD(int x, int y, int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]) {
-    if (cArr[x-1][y+1] == 'a' || cArr[x-1][y+1] == 'b' ) { //if the path is blocked by spawnA or spawnB 
+void Spawn::movementD(int x, int y, int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]) { //d = move left & down
+    if (cArr[x-1][y+1] == 'a' || cArr[x-1][y] == 'b' ) { //if the path is blocked by spawnA or spawnB 
         cArr2[x-2][y+2] = 'd'; Arr2[x-2][y+2] = Arr[x][y]; //jumps over it
         cArr2[x][y] = '\0'; Arr2[x][y] = 0;
         //printf("jump over at [%d][%d] \n",x-1,y+1);
-    } else if (x == 0 || x == 83 || cArr[x-1][y+1] == 'l' || cArr[x-1][y+1] == 'r') { //if it hits the wall or 'l' or 'r'.
+    } else if (x == 0 || x == 83 || cArr[x-1][y+1] == 'l' || cArr[x-1][y+1] == 'r' || cArr[x-1][y+1] == 'm') { //if it hits the wall or 'l' or 'r' or 'm'.
         if (cArr[x-1][y+1] == 'l' || cArr[x-1][y+1] == 'r') {
             //printf("char = %c \n",cArr[x-1][y+1]);
         }
@@ -120,12 +120,12 @@
         //printf("work pls. \n");
     }
 }
-void Spawn::movementE(int x, int y, int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]) {
-    if (cArr[x+1][y+1] == 'a' || cArr[x+1][y+1] == 'b' ) { //if the path is blocked by spawnA or spawnB 
+void Spawn::movementE(int x, int y, int Arr[][Rows], int Arr2[][Rows], char cArr[][Rows], char cArr2[][Rows]) {  //e = move right & down
+    if (cArr[x+1][y+1] == 'a' || cArr[x+1][y] == 'b' ) { //if the path is blocked by spawnA or spawnB 
         cArr2[x+2][y+2] = 'e'; Arr2[x+2][y+2] = Arr[x][y]; //jumps over it
         cArr2[x][y] = '\0'; Arr2[x][y] = 0;
         //printf("jump over at [%d][%d] \n",x+1,y+1);
-    } else if (x == 0 || x == 83 || cArr[x+1][y+1] == 'l' || cArr[x+1][y+1] == 'r') { //if it hits the wall or 'l' or 'r'.
+    } else if (x == 0 || x == 83 || cArr[x+1][y+1] == 'l' || cArr[x+1][y+1] == 'r' || cArr[x+1][y+1] == 'm') { //if it hits the wall or 'l' or 'r' or 'm'.
         cArr2[x-1][y+1] = 'd'; Arr2[x-1][y+1] = Arr[x][y]; //start moving left & down
         cArr2[x][y] = '\0'; Arr2[x][y] = 0;
         //printf("spawn d at x = %d is shifted to e \n",x);
@@ -153,28 +153,25 @@
     for ( int y = 0; y < Rows; y++) {
         for ( int x = 0; x < Cols; x++) {
             deleteChar(x, y, Arr2, cArr2); //cleaning up the array
-            if (cArr2[x][y] == 'a') {
+            if (cArr2[x][y] == 'a' || cArr2[x][y] == 'd' || cArr2[x][y] == 'e') {
                 lcd.setPixel(x,y);
                 Arr[x][y] = Arr2[x][y]; //to update the main array
                 cArr[x][y] = cArr2[x][y];
             } else if (cArr2[x][y] == 'b') {
-                lcd.setPixel(x,y); lcd.setPixel(x,y+1);
+                lcd.setPixel(x,y); lcd.setPixel(x,y-1);
                 Arr[x][y] = Arr2[x][y];  //to update the main array
                 cArr[x][y] = 'b';             
-            } else if (cArr2[x][y] == 'c') {// l and r (left and right) side of the spawn C for bigger hit box.
+            } else if (cArr2[x][y] == 'c') {// l and r (left and right) side of the spawn C for bigger hit box & to deflect spawnDE.
                 if (cArr2[x-1][y-1] == '\0'){ //this code to prevent b, d and e from getting replaced 
                     cArr[x-1][y-1] = 'l'; cArr2[x-1][y-1] = 'l';
                 } 
                 if (cArr2[x+1][y-1] == '\0'){ //this code to prevent b, d and e from getting replaced
                     cArr[x+1][y-1] = 'r'; cArr2[x+1][y-1] = 'r';
                 }
+                cArr[x][y-1] = 'm'; //to deflect spawnDE.
                 cArr[x][y] = cArr2[x][y]; Arr[x][y] = Arr2[x][y]; //to update the main array
                 lcd.setPixel(x,y); lcd.setPixel(x,y-1);
                 lcd.setPixel(x+1,y-1); lcd.setPixel(x-1,y-1);
-            } else if (cArr2[x][y] == 'd' || cArr2[x][y] == 'e') {
-                lcd.setPixel(x,y);
-                Arr[x][y] = Arr2[x][y]; //to update the main array
-                cArr[x][y] = cArr2[x][y];
             } else {
                 Arr[x][y] = 0;
                 cArr[x][y] = '\0';