JianWei Lee
/
project_game
Meteor defense project
main.cpp
- Committer:
- jasper0712
- Date:
- 2017-04-25
- Revision:
- 39:f92b93efbc72
- Parent:
- 38:c66a69c1a6de
- Child:
- 40:3a0c66a0e10e
File content as of revision 39:f92b93efbc72:
#include "mbed.h" #include "N5110.h" #include "Gamepad.h" #include "GameEngine.h" #define PI 3.14159265 //Y rows and X columns #define Rows 48 #define Cols 84 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); Gamepad pad; GameEngine game; int gamefps = 15; Ticker waveCompleteTicker; int setTicker; int waveComplete_flag; int waveNumber; int menu; char wave[10]; void init(); void render(); void waveComplete_isr(); void gameMenu(); void startGame(); void gameUpgrades(); int main() { init(); gameMenu(); setTicker = 1; //set the ticker. while (true) { if (setTicker == 1) { startGame(); } //this is the game game.update(pad, lcd); while(waveComplete_flag == 1) { //after every wave, go to upgrades gameUpgrades(); } render(); } } void init() { // need to initialise LCD and Gamepad lcd.init(); pad.init(); game.init(waveNumber); // initialise the game } void render() { // clear screen, re-draw and refresh lcd.refresh(); 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,60); //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; } void gameMenu() { while ( pad.check_event(Gamepad::START_PRESSED) == false) { game.startingMenu(pad, lcd); lcd.refresh(); wait(0.2); } lcd.clear(); }