JianWei Lee
/
project_game
Meteor defense project
Spawn/Spawn.cpp@1:f5cda0674f24, 2017-03-20 (annotated)
- Committer:
- jasper0712
- Date:
- Mon Mar 20 22:06:50 2017 +0000
- Revision:
- 1:f5cda0674f24
- Parent:
- 0:5fbc0fbc9d30
- Child:
- 2:2c60c92bf65b
Array fail. Might be the problem with movingspawn
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:f5cda0674f24 | 22 | spawnArray[x][0] = 1; |
jasper0712 | 1:f5cda0674f24 | 23 | |
jasper0712 | 1:f5cda0674f24 | 24 | printf("spawn set at x = is %d \n",x); |
jasper0712 | 1:f5cda0674f24 | 25 | } |
jasper0712 | 1:f5cda0674f24 | 26 | } |
jasper0712 | 1:f5cda0674f24 | 27 | printf("at x=2, y=0. value = %d \n",spawnArray[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 | 1:f5cda0674f24 | 33 | void Spawn::moveSpawn(int array[Cols][Rows]) { |
jasper0712 | 1:f5cda0674f24 | 34 | //scan through the whole array |
jasper0712 | 1:f5cda0674f24 | 35 | printf("x=2,y =0. value = %d \n",array[2][0]); |
jasper0712 | 1:f5cda0674f24 | 36 | for ( int x = 0; x < Cols; x++) { |
jasper0712 | 1:f5cda0674f24 | 37 | for ( int y = 0; y < Rows; y++) { |
jasper0712 | 1:f5cda0674f24 | 38 | if (array[x][y] == 1) { |
jasper0712 | 1:f5cda0674f24 | 39 | //move it down a row |
jasper0712 | 1:f5cda0674f24 | 40 | array[x][y+1] = 1; |
jasper0712 | 1:f5cda0674f24 | 41 | array[x][y] = 0; |
jasper0712 | 1:f5cda0674f24 | 42 | } |
jasper0712 | 1:f5cda0674f24 | 43 | } |
jasper0712 | 1:f5cda0674f24 | 44 | } |
jasper0712 | 1:f5cda0674f24 | 45 | printf("at x=2, y=47. number is =%d \n",array[2][47]); |
jasper0712 | 1:f5cda0674f24 | 46 | } |
jasper0712 | 1:f5cda0674f24 | 47 | |
jasper0712 | 1:f5cda0674f24 | 48 | void Spawn::updateSpawn(int array[Cols][Rows], N5110 &lcd) { |
jasper0712 | 1:f5cda0674f24 | 49 | for ( int x = 0; x < 83; x++) { |
jasper0712 | 1:f5cda0674f24 | 50 | for ( int y = 0; y < 45; y++) { |
jasper0712 | 1:f5cda0674f24 | 51 | if (array[x][y] == 1) { |
jasper0712 | 1:f5cda0674f24 | 52 | lcd.setPixel(x,y); |
jasper0712 | 1:f5cda0674f24 | 53 | } |
jasper0712 | 1:f5cda0674f24 | 54 | } |
jasper0712 | 1:f5cda0674f24 | 55 | } |
jasper0712 | 1:f5cda0674f24 | 56 | } |
jasper0712 | 1:f5cda0674f24 | 57 | |
jasper0712 | 1:f5cda0674f24 | 58 | |
jasper0712 | 1:f5cda0674f24 | 59 | |
jasper0712 | 0:5fbc0fbc9d30 | 60 |