JianWei Lee
/
project_game
Meteor defense project
Spawn/Spawn.cpp
- Committer:
- jasper0712
- Date:
- 2017-03-22
- Revision:
- 3:6b50fe9d3848
- Parent:
- 2:2c60c92bf65b
- Child:
- 5:c74bbdda06f4
File content as of revision 3:6b50fe9d3848:
#include "Spawn.h" Spawn::Spawn() { } Spawn::~Spawn() { } void Spawn::randomizeSpawn() { if (stopSpawn ==0) { stopSpawn = 1; for ( int x = 0; x < Cols; x++) { //30% chance of spawning bool TrueFalse = (rand() % 100) < 30; if (TrueFalse) { //spawning from the top of the screen spawnArray1[x][0] = 1; spawnArray2[x][0] = 1; printf("spawn set at x = is %d \n",x); } } printf("at x=2, y=0. value = %d \n",spawnArray1[2][0]); } else { stopSpawn = 0; } } void Spawn::moveSpawn() { //printf("x=2,y =0. value = %d \n",array[2][0]); //scan through the whole array for ( int x = 0; x < Cols; x++) { spawnArray2[x][0] = 0; for ( int y = 0; y < Rows; y++) { if (spawnArray1[x][y] == 1) { //move it down a row spawnArray2[x][y+1] = 1; } else { spawnArray2[x][y+1] = 0; } } } printf("at x=2, y=47. number is =%d \n",spawnArray2[2][47]); } void Spawn::updateSpawn(N5110 &lcd) { for ( int x = 0; x < Cols; x++) { for ( int y = 0; y < Rows; y++) { if (spawnArray2[x][y] == 1) { lcd.setPixel(x,y); //to update array1 spawnArray1[x][y] = 1; } else { spawnArray1[x][y] = 0; } } } }