Meteor defense project

Dependencies:   N5110 mbed

Committer:
jasper0712
Date:
Fri Apr 07 10:49:57 2017 +0000
Revision:
16:ddc4d5669a6e
Parent:
14:064b8d7f348d
Child:
18:d82059ce929b
no idea why R is not working. Starting on drone.

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 16:ddc4d5669a6e 17 //32/200 chance of spawning for A.
jasper0712 13:38cbce17d7d7 18 //can depends on level
jasper0712 14:064b8d7f348d 19 bool TrueFalseA = (rand() % 200) < 32;
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 16:ddc4d5669a6e 34 Arr2[x][0] = 100000;
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 16:ddc4d5669a6e 66 if (Arr2[x][y] > 10000) { //any number larger than this must be spawn b.
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 13:38cbce17d7d7 75 void Spawn::updateSpawn(int Arr1[][Rows], int Arr2[][Rows], char Arr3[][Rows],N5110 &lcd) {
jasper0712 2:2c60c92bf65b 76 for ( int x = 0; x < Cols; x++) {
jasper0712 2:2c60c92bf65b 77 for ( int y = 0; y < Rows; y++) {
jasper0712 16:ddc4d5669a6e 78 deleteChar(x, y, Arr1, Arr3);
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 16:ddc4d5669a6e 88 Arr3[x-1][y-1] = 'l';
jasper0712 16:ddc4d5669a6e 89 Arr3[x+1][y-1] = 'r';
jasper0712 13:38cbce17d7d7 90 lcd.setPixel(x,y);
jasper0712 13:38cbce17d7d7 91 lcd.setPixel(x,y+1);
jasper0712 13:38cbce17d7d7 92 lcd.setPixel(x+1,y);
jasper0712 13:38cbce17d7d7 93 lcd.setPixel(x-1,y);
jasper0712 13:38cbce17d7d7 94 Arr2[x][y] = Arr1[x][y];
jasper0712 13:38cbce17d7d7 95 }else {
jasper0712 9:4c4d787c7a8b 96 Arr2[x][y] = 0;
jasper0712 1:f5cda0674f24 97 }
jasper0712 1:f5cda0674f24 98 }
jasper0712 1:f5cda0674f24 99 }
jasper0712 1:f5cda0674f24 100 }
jasper0712 13:38cbce17d7d7 101 void Spawn::deleteChar(int x, int y, int Arr1[][Rows], char Arr3[][Rows]) {
jasper0712 13:38cbce17d7d7 102 if (Arr1[x][y] == 0) {
jasper0712 13:38cbce17d7d7 103 Arr3[x][y] = '\0';
jasper0712 13:38cbce17d7d7 104 }
jasper0712 13:38cbce17d7d7 105 }
jasper0712 7:3be4369131c6 106
jasper0712 3:6b50fe9d3848 107