Meteor defense project

Dependencies:   N5110 mbed

Committer:
jasper0712
Date:
Thu Mar 23 19:36:33 2017 +0000
Revision:
6:a554424e4517
Parent:
5:c74bbdda06f4
Child:
7:3be4369131c6
problem solved : sharing array between classes

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 6:a554424e4517 24 Arr2[x][0] = 1;
jasper0712 1:f5cda0674f24 25 printf("spawn set at x = is %d \n",x);
jasper0712 1:f5cda0674f24 26 }
jasper0712 1:f5cda0674f24 27 }
jasper0712 6:a554424e4517 28 printf("at x=2, y=0. value = %d \n",Arr1[2][0]);
jasper0712 1:f5cda0674f24 29 } else {
jasper0712 1:f5cda0674f24 30 stopSpawn = 0;
jasper0712 1:f5cda0674f24 31 }
jasper0712 1:f5cda0674f24 32
jasper0712 1:f5cda0674f24 33 }
jasper0712 6:a554424e4517 34 void Spawn::moveSpawn(int Arr1[][Rows], int Arr2[][Rows]) {
jasper0712 2:2c60c92bf65b 35 //printf("x=2,y =0. value = %d \n",array[2][0]);
jasper0712 1:f5cda0674f24 36 //scan through the whole array
jasper0712 1:f5cda0674f24 37 for ( int x = 0; x < Cols; x++) {
jasper0712 6:a554424e4517 38 Arr2[x][0] = 0;
jasper0712 1:f5cda0674f24 39 for ( int y = 0; y < Rows; y++) {
jasper0712 6:a554424e4517 40 if (Arr1[x][y] > 0) {
jasper0712 1:f5cda0674f24 41 //move it down a row
jasper0712 6:a554424e4517 42 Arr2[x][y+1] = Arr1[x][y];
jasper0712 2:2c60c92bf65b 43 } else {
jasper0712 6:a554424e4517 44 Arr2[x][y+1] = 0;
jasper0712 1:f5cda0674f24 45 }
jasper0712 1:f5cda0674f24 46 }
jasper0712 1:f5cda0674f24 47 }
jasper0712 6:a554424e4517 48 printf("at x=2, y=47. number is =%d \n",Arr2[2][47]);
jasper0712 1:f5cda0674f24 49 }
jasper0712 1:f5cda0674f24 50
jasper0712 6:a554424e4517 51 void Spawn::updateSpawn(int Arr1[][Rows], int Arr2[][Rows],N5110 &lcd) {
jasper0712 2:2c60c92bf65b 52 for ( int x = 0; x < Cols; x++) {
jasper0712 2:2c60c92bf65b 53 for ( int y = 0; y < Rows; y++) {
jasper0712 6:a554424e4517 54 if (Arr2[x][y] > 0) {
jasper0712 1:f5cda0674f24 55 lcd.setPixel(x,y);
jasper0712 2:2c60c92bf65b 56 //to update array1
jasper0712 6:a554424e4517 57 Arr1[x][y] = Arr2[x][y];
jasper0712 2:2c60c92bf65b 58 } else {
jasper0712 6:a554424e4517 59 Arr1[x][y] = 0;
jasper0712 1:f5cda0674f24 60 }
jasper0712 1:f5cda0674f24 61 }
jasper0712 1:f5cda0674f24 62 }
jasper0712 1:f5cda0674f24 63 }
jasper0712 1:f5cda0674f24 64
jasper0712 3:6b50fe9d3848 65