JianWei Lee
/
project_game
Meteor defense project
Spawn/Spawn.cpp@5:c74bbdda06f4, 2017-03-22 (annotated)
- Committer:
- jasper0712
- Date:
- Wed Mar 22 17:15:38 2017 +0000
- Revision:
- 5:c74bbdda06f4
- Parent:
- 3:6b50fe9d3848
- Child:
- 6:a554424e4517
tidying things up
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 | 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 | 2:2c60c92bf65b | 23 | spawnArray1[x][0] = 1; |
jasper0712 | 2:2c60c92bf65b | 24 | spawnArray2[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 | 2:2c60c92bf65b | 28 | printf("at x=2, y=0. value = %d \n",spawnArray1[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 | 2:2c60c92bf65b | 34 | void Spawn::moveSpawn() { |
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 | 2:2c60c92bf65b | 38 | spawnArray2[x][0] = 0; |
jasper0712 | 1:f5cda0674f24 | 39 | for ( int y = 0; y < Rows; y++) { |
jasper0712 | 5:c74bbdda06f4 | 40 | if (spawnArray1[x][y] > 0) { |
jasper0712 | 1:f5cda0674f24 | 41 | //move it down a row |
jasper0712 | 5:c74bbdda06f4 | 42 | spawnArray2[x][y+1] = spawnArray1[x][y]; |
jasper0712 | 2:2c60c92bf65b | 43 | } else { |
jasper0712 | 2:2c60c92bf65b | 44 | spawnArray2[x][y+1] = 0; |
jasper0712 | 1:f5cda0674f24 | 45 | } |
jasper0712 | 1:f5cda0674f24 | 46 | } |
jasper0712 | 1:f5cda0674f24 | 47 | } |
jasper0712 | 2:2c60c92bf65b | 48 | printf("at x=2, y=47. number is =%d \n",spawnArray2[2][47]); |
jasper0712 | 1:f5cda0674f24 | 49 | } |
jasper0712 | 1:f5cda0674f24 | 50 | |
jasper0712 | 2:2c60c92bf65b | 51 | void Spawn::updateSpawn(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 | 5:c74bbdda06f4 | 54 | if (spawnArray2[x][y] > 0) { |
jasper0712 | 1:f5cda0674f24 | 55 | lcd.setPixel(x,y); |
jasper0712 | 2:2c60c92bf65b | 56 | //to update array1 |
jasper0712 | 5:c74bbdda06f4 | 57 | spawnArray1[x][y] = spawnArray2[x][y]; |
jasper0712 | 2:2c60c92bf65b | 58 | } else { |
jasper0712 | 2:2c60c92bf65b | 59 | spawnArray1[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 |