JianWei Lee
/
project_game
Meteor defense project
main.cpp
- Committer:
- jasper0712
- Date:
- 2017-04-21
- Revision:
- 33:61c69c46a941
- Parent:
- 32:580d74825810
- Child:
- 37:45da88e36d1d
File content as of revision 33:61c69c46a941:
#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(); int main() { init(); 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 } game.update(pad, lcd); //this is the game 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"); } } 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 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(); }