Meteor defense project

Dependencies:   N5110 mbed

Committer:
jasper0712
Date:
Thu Mar 30 11:13:20 2017 +0000
Revision:
13:38cbce17d7d7
Parent:
9:4c4d787c7a8b
Child:
14:064b8d7f348d
done with spawn abc. starting energy shield next

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jasper0712 1:f5cda0674f24 1 #include "Spawn.h"
jasper0712 0:5fbc0fbc9d30 2
jasper0712 1:f5cda0674f24 3 Spawn::Spawn()
jasper0712 1:f5cda0674f24 4 {
jasper0712 1:f5cda0674f24 5
jasper0712 1:f5cda0674f24 6 }
jasper0712 1:f5cda0674f24 7
jasper0712 1:f5cda0674f24 8 Spawn::~Spawn()
jasper0712 1:f5cda0674f24 9 {
jasper0712 1:f5cda0674f24 10
jasper0712 1:f5cda0674f24 11 }
jasper0712 1:f5cda0674f24 12
jasper0712 13:38cbce17d7d7 13 void Spawn::randomizeSpawn(int Arr2[][Rows], char Arr3[][Rows]) {
jasper0712 13:38cbce17d7d7 14 //there is 3 kind of different spawn - a, b and c.
jasper0712 13:38cbce17d7d7 15 if (stopSpawnA == 0) {
jasper0712 13:38cbce17d7d7 16 for ( int x = 0; x < Cols; x++) {
jasper0712 13:38cbce17d7d7 17 //16/200 chance of spawning for A.
jasper0712 13:38cbce17d7d7 18 //can depends on level
jasper0712 13:38cbce17d7d7 19 bool TrueFalseA = (rand() % 200) < 16;
jasper0712 13:38cbce17d7d7 20 if (TrueFalseA) {
jasper0712 13:38cbce17d7d7 21 //spawning from the top of the screen
jasper0712 13:38cbce17d7d7 22 Arr2[x][0] = 1;
jasper0712 13:38cbce17d7d7 23 Arr3[x][0] = 'a';
jasper0712 13:38cbce17d7d7 24 //printf("spawn set at x = is %d \n",x);
jasper0712 13:38cbce17d7d7 25 }
jasper0712 13:38cbce17d7d7 26 }
jasper0712 13:38cbce17d7d7 27 stopSpawnA= 1;
jasper0712 13:38cbce17d7d7 28 } else {
jasper0712 13:38cbce17d7d7 29 stopSpawnA = 0;
jasper0712 13:38cbce17d7d7 30 }
jasper0712 1:f5cda0674f24 31 for ( int x = 0; x < Cols; x++) {
jasper0712 13:38cbce17d7d7 32 bool TrueFalseB = (rand() % 200) < 1;
jasper0712 13:38cbce17d7d7 33 if (TrueFalseB) {
jasper0712 13:38cbce17d7d7 34 Arr2[x][0] = 10000;
jasper0712 13:38cbce17d7d7 35 Arr3[x][0] = 'b';
jasper0712 13:38cbce17d7d7 36 }
jasper0712 13:38cbce17d7d7 37 bool TrueFalseC = (rand() % 200) < 1;
jasper0712 13:38cbce17d7d7 38 if (TrueFalseC) {
jasper0712 13:38cbce17d7d7 39 Arr2[x][0] = 10;
jasper0712 13:38cbce17d7d7 40 Arr3[x][0] = 'c';
jasper0712 1:f5cda0674f24 41 }
jasper0712 1:f5cda0674f24 42 }
jasper0712 7:3be4369131c6 43 //printf("at x=2, y=0. value = %d \n",Arr1[2][0]);
jasper0712 1:f5cda0674f24 44 }
jasper0712 13:38cbce17d7d7 45 void Spawn::moveSpawnABC(int Arr1[][Rows], int Arr2[][Rows], char Arr3[][Rows]) {
jasper0712 2:2c60c92bf65b 46 //printf("x=2,y =0. value = %d \n",array[2][0]);
jasper0712 1:f5cda0674f24 47 //scan through the whole array
jasper0712 13:38cbce17d7d7 48 for (int x = 0; x < Cols; x++) {
jasper0712 13:38cbce17d7d7 49 for (int y = 0; y < Rows; y++) {
jasper0712 9:4c4d787c7a8b 50 if (Arr2[x][y] > 0) {
jasper0712 1:f5cda0674f24 51 //move it down a row
jasper0712 9:4c4d787c7a8b 52 Arr1[x][y+1] = Arr2[x][y];
jasper0712 13:38cbce17d7d7 53 Arr3[x][y+1] = Arr3[x][y];
jasper0712 13:38cbce17d7d7 54 Arr3[x][y] = '\0';
jasper0712 2:2c60c92bf65b 55 } else {
jasper0712 9:4c4d787c7a8b 56 Arr1[x][y+1] = 0;
jasper0712 1:f5cda0674f24 57 }
jasper0712 1:f5cda0674f24 58 }
jasper0712 1:f5cda0674f24 59 }
jasper0712 6:a554424e4517 60 printf("at x=2, y=47. number is =%d \n",Arr2[2][47]);
jasper0712 1:f5cda0674f24 61 }
jasper0712 13:38cbce17d7d7 62 void Spawn::moveSpawnB(int Arr1[][Rows], int Arr2[][Rows], char Arr3[][Rows]){
jasper0712 13:38cbce17d7d7 63 //printf("moving spawn B \n");
jasper0712 13:38cbce17d7d7 64 for (int x = 0; x < Cols; x++) {
jasper0712 13:38cbce17d7d7 65 for (int y = 0; y < Rows; y++) {
jasper0712 13:38cbce17d7d7 66 if (Arr2[x][y] > 8000) {
jasper0712 13:38cbce17d7d7 67 Arr1[x][y+1] = Arr2[x][y];
jasper0712 13:38cbce17d7d7 68 Arr1[x][y] = 0;
jasper0712 13:38cbce17d7d7 69 Arr3[x][y+1] = 'b';
jasper0712 13:38cbce17d7d7 70 Arr3[x][y] = '\0';
jasper0712 13:38cbce17d7d7 71 }
jasper0712 13:38cbce17d7d7 72 }
jasper0712 13:38cbce17d7d7 73 }
jasper0712 13:38cbce17d7d7 74 }
jasper0712 1:f5cda0674f24 75
jasper0712 13:38cbce17d7d7 76 void Spawn::updateSpawn(int Arr1[][Rows], int Arr2[][Rows], char Arr3[][Rows],N5110 &lcd) {
jasper0712 2:2c60c92bf65b 77 for ( int x = 0; x < Cols; x++) {
jasper0712 2:2c60c92bf65b 78 for ( int y = 0; y < Rows; y++) {
jasper0712 13:38cbce17d7d7 79 if (Arr3[x][y] == 'a') {
jasper0712 1:f5cda0674f24 80 lcd.setPixel(x,y);
jasper0712 2:2c60c92bf65b 81 //to update array1
jasper0712 9:4c4d787c7a8b 82 Arr2[x][y] = Arr1[x][y];
jasper0712 13:38cbce17d7d7 83 } else if (Arr3[x][y] == 'b') {
jasper0712 13:38cbce17d7d7 84 lcd.setPixel(x,y);
jasper0712 13:38cbce17d7d7 85 lcd.setPixel(x,y+1);
jasper0712 13:38cbce17d7d7 86 Arr2[x][y] = Arr1[x][y];
jasper0712 13:38cbce17d7d7 87 } else if (Arr3[x][y] == 'c') {
jasper0712 13:38cbce17d7d7 88 lcd.setPixel(x,y);
jasper0712 13:38cbce17d7d7 89 lcd.setPixel(x,y+1);
jasper0712 13:38cbce17d7d7 90 lcd.setPixel(x+1,y);
jasper0712 13:38cbce17d7d7 91 lcd.setPixel(x-1,y);
jasper0712 13:38cbce17d7d7 92 Arr2[x][y] = Arr1[x][y];
jasper0712 13:38cbce17d7d7 93 }else {
jasper0712 9:4c4d787c7a8b 94 Arr2[x][y] = 0;
jasper0712 1:f5cda0674f24 95 }
jasper0712 13:38cbce17d7d7 96 deleteChar(x, y, Arr1, Arr3);
jasper0712 1:f5cda0674f24 97 }
jasper0712 1:f5cda0674f24 98 }
jasper0712 1:f5cda0674f24 99 }
jasper0712 13:38cbce17d7d7 100 void Spawn::deleteChar(int x, int y, int Arr1[][Rows], char Arr3[][Rows]) {
jasper0712 13:38cbce17d7d7 101 if (Arr1[x][y] == 0) {
jasper0712 13:38cbce17d7d7 102 Arr3[x][y] = '\0';
jasper0712 13:38cbce17d7d7 103 }
jasper0712 13:38cbce17d7d7 104 }
jasper0712 7:3be4369131c6 105
jasper0712 3:6b50fe9d3848 106