JianWei Lee
/
project_game
Meteor defense project
Diff: main.cpp
- Revision:
- 37:45da88e36d1d
- Parent:
- 33:61c69c46a941
- Child:
- 38:c66a69c1a6de
--- a/main.cpp Sun Apr 23 22:52:48 2017 +0000 +++ b/main.cpp Mon Apr 24 11:11:39 2017 +0000 @@ -29,6 +29,8 @@ void render(); void waveComplete_isr(); void gameMenu(); +void startGame(); +void gameUpgrades(); int main() { @@ -36,30 +38,15 @@ gameMenu(); setTicker = 1; //set the ticker. while (true) { - if (setTicker == 1) { - sprintf(wave, "wave %d", waveNumber + 1); //+1 because initially waveNumber = 0 - lcd.printString(wave,10,3); - render(); - wait(2.0); - game.init(waveNumber); - waveCompleteTicker.attach(&waveComplete_isr,60); //60 seconds for a wave. - setTicker = 0; //clear set ticker flag + if (setTicker == 1) { + startGame(); } - game.update(pad, lcd); //this is the game + //this is the game + game.update(pad, lcd); while(waveComplete_flag == 1) { //after every wave, go to upgrades - waveCompleteTicker.detach(); - lcd.printString("Wave complete",1,3); - lcd.printString("Start to Upgrade",1,5); - render(); - game.weapUpgrade(pad, lcd); - if (game.doneUpgrade == 1) { - waveComplete_flag = 0; //get out of while loop - setTicker = 1; //continue the game - game.doneUpgrade = 0; - printf("i got out"); - } + gameUpgrades(); } render(); } @@ -78,6 +65,29 @@ wait(1.0/gamefps); lcd.clear(); } +void startGame() { + sprintf(wave, "wave %d", waveNumber + 1); //+1 because initially waveNumber = 0 + lcd.printString(wave,10,3); + render(); + wait(2.0); + game.init(waveNumber); + waveCompleteTicker.attach(&waveComplete_isr,1); //60 seconds for a wave. + setTicker = 0; //clear set ticker flag +} +void gameUpgrades() { + waveCompleteTicker.detach(); + lcd.printString("Wave complete",1,3); + lcd.printString("Start to Upgrade",1,5); + render(); + game.weapUpgrade(pad, lcd); + + if (game.doneUpgrade_flag == 1) { + waveComplete_flag = 0; //get out of while loop + setTicker = 1; //continue the game + game.doneUpgrade_flag = 0; + printf("i got out"); + } +} void waveComplete_isr() { waveComplete_flag = 1; waveNumber += 1;