Meteor defense project

Dependencies:   N5110 mbed

Committer:
jasper0712
Date:
Mon Mar 27 22:55:10 2017 +0000
Revision:
7:3be4369131c6
Parent:
6:a554424e4517
Child:
9:4c4d787c7a8b
fail to detect spawn. no idea why

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 6:a554424e4517 13 void Spawn::randomizeSpawn(int Arr1[][Rows], int Arr2[][Rows]) {
jasper0712 1:f5cda0674f24 14
jasper0712 1:f5cda0674f24 15 if (stopSpawn ==0) {
jasper0712 1:f5cda0674f24 16 stopSpawn = 1;
jasper0712 1:f5cda0674f24 17 for ( int x = 0; x < Cols; x++) {
jasper0712 1:f5cda0674f24 18 //30% chance of spawning
jasper0712 5:c74bbdda06f4 19 //can depends on level
jasper0712 5:c74bbdda06f4 20 bool TrueFalse = (rand() % 100) < 20;
jasper0712 1:f5cda0674f24 21 if (TrueFalse) {
jasper0712 1:f5cda0674f24 22 //spawning from the top of the screen
jasper0712 6:a554424e4517 23 Arr1[x][0] = 1;
jasper0712 7:3be4369131c6 24 //printf("spawn set at x = is %d \n",x);
jasper0712 1:f5cda0674f24 25 }
jasper0712 1:f5cda0674f24 26 }
jasper0712 7:3be4369131c6 27 //printf("at x=2, y=0. value = %d \n",Arr1[2][0]);
jasper0712 1:f5cda0674f24 28 } else {
jasper0712 1:f5cda0674f24 29 stopSpawn = 0;
jasper0712 1:f5cda0674f24 30 }
jasper0712 1:f5cda0674f24 31
jasper0712 1:f5cda0674f24 32 }
jasper0712 6:a554424e4517 33 void Spawn::moveSpawn(int Arr1[][Rows], int Arr2[][Rows]) {
jasper0712 2:2c60c92bf65b 34 //printf("x=2,y =0. value = %d \n",array[2][0]);
jasper0712 1:f5cda0674f24 35 //scan through the whole array
jasper0712 1:f5cda0674f24 36 for ( int x = 0; x < Cols; x++) {
jasper0712 1:f5cda0674f24 37 for ( int y = 0; y < Rows; y++) {
jasper0712 6:a554424e4517 38 if (Arr1[x][y] > 0) {
jasper0712 1:f5cda0674f24 39 //move it down a row
jasper0712 6:a554424e4517 40 Arr2[x][y+1] = Arr1[x][y];
jasper0712 2:2c60c92bf65b 41 } else {
jasper0712 6:a554424e4517 42 Arr2[x][y+1] = 0;
jasper0712 1:f5cda0674f24 43 }
jasper0712 1:f5cda0674f24 44 }
jasper0712 1:f5cda0674f24 45 }
jasper0712 6:a554424e4517 46 printf("at x=2, y=47. number is =%d \n",Arr2[2][47]);
jasper0712 1:f5cda0674f24 47 }
jasper0712 1:f5cda0674f24 48
jasper0712 6:a554424e4517 49 void Spawn::updateSpawn(int Arr1[][Rows], int Arr2[][Rows],N5110 &lcd) {
jasper0712 2:2c60c92bf65b 50 for ( int x = 0; x < Cols; x++) {
jasper0712 2:2c60c92bf65b 51 for ( int y = 0; y < Rows; y++) {
jasper0712 6:a554424e4517 52 if (Arr2[x][y] > 0) {
jasper0712 1:f5cda0674f24 53 lcd.setPixel(x,y);
jasper0712 2:2c60c92bf65b 54 //to update array1
jasper0712 6:a554424e4517 55 Arr1[x][y] = Arr2[x][y];
jasper0712 2:2c60c92bf65b 56 } else {
jasper0712 6:a554424e4517 57 Arr1[x][y] = 0;
jasper0712 1:f5cda0674f24 58 }
jasper0712 1:f5cda0674f24 59 }
jasper0712 1:f5cda0674f24 60 }
jasper0712 1:f5cda0674f24 61 }
jasper0712 1:f5cda0674f24 62
jasper0712 7:3be4369131c6 63
jasper0712 3:6b50fe9d3848 64