Meteor defense project

Dependencies:   N5110 mbed

Committer:
jasper0712
Date:
Tue Mar 21 22:29:33 2017 +0000
Revision:
2:2c60c92bf65b
Parent:
1:f5cda0674f24
Child:
3:6b50fe9d3848
done with the basic of spawn.

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 1:f5cda0674f24 13 void Spawn::randomizeSpawn() {
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 1:f5cda0674f24 19 bool TrueFalse = (rand() % 100) < 30;
jasper0712 1:f5cda0674f24 20 if (TrueFalse) {
jasper0712 1:f5cda0674f24 21 //spawning from the top of the screen
jasper0712 2:2c60c92bf65b 22 spawnArray1[x][0] = 1;
jasper0712 2:2c60c92bf65b 23 spawnArray2[x][0] = 1;
jasper0712 1:f5cda0674f24 24 printf("spawn set at x = is %d \n",x);
jasper0712 1:f5cda0674f24 25 }
jasper0712 1:f5cda0674f24 26 }
jasper0712 2:2c60c92bf65b 27 printf("at x=2, y=0. value = %d \n",spawnArray1[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 2:2c60c92bf65b 33 void Spawn::moveSpawn() {
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 2:2c60c92bf65b 37 spawnArray2[x][0] = 0;
jasper0712 1:f5cda0674f24 38 for ( int y = 0; y < Rows; y++) {
jasper0712 2:2c60c92bf65b 39 if (spawnArray1[x][y] == 1) {
jasper0712 1:f5cda0674f24 40 //move it down a row
jasper0712 2:2c60c92bf65b 41 spawnArray2[x][y+1] = 1;
jasper0712 2:2c60c92bf65b 42 } else {
jasper0712 2:2c60c92bf65b 43 spawnArray2[x][y+1] = 0;
jasper0712 1:f5cda0674f24 44 }
jasper0712 1:f5cda0674f24 45 }
jasper0712 1:f5cda0674f24 46 }
jasper0712 2:2c60c92bf65b 47 printf("at x=2, y=47. number is =%d \n",spawnArray2[2][47]);
jasper0712 1:f5cda0674f24 48 }
jasper0712 1:f5cda0674f24 49
jasper0712 2:2c60c92bf65b 50 void Spawn::updateSpawn(N5110 &lcd) {
jasper0712 2:2c60c92bf65b 51 for ( int x = 0; x < Cols; x++) {
jasper0712 2:2c60c92bf65b 52 for ( int y = 0; y < Rows; y++) {
jasper0712 2:2c60c92bf65b 53 if (spawnArray2[x][y] == 1) {
jasper0712 1:f5cda0674f24 54 lcd.setPixel(x,y);
jasper0712 2:2c60c92bf65b 55 //to update array1
jasper0712 2:2c60c92bf65b 56 spawnArray1[x][y] = 1;
jasper0712 2:2c60c92bf65b 57 } else {
jasper0712 2:2c60c92bf65b 58 spawnArray1[x][y] = 0;
jasper0712 1:f5cda0674f24 59 }
jasper0712 1:f5cda0674f24 60 }
jasper0712 1:f5cda0674f24 61 }
jasper0712 1:f5cda0674f24 62 }
jasper0712 1:f5cda0674f24 63
jasper0712 1:f5cda0674f24 64
jasper0712 1:f5cda0674f24 65
jasper0712 0:5fbc0fbc9d30 66