Meteor defense project

Dependencies:   N5110 mbed

Committer:
jasper0712
Date:
Tue Apr 18 21:50:14 2017 +0000
Revision:
30:2e2d48cbfec3
Parent:
29:6632dd9c48d8
Child:
31:1c0e47931e84
disastrous bug

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jasper0712 0:5fbc0fbc9d30 1 #include "mbed.h"
jasper0712 0:5fbc0fbc9d30 2 #include "N5110.h"
jasper0712 0:5fbc0fbc9d30 3 #include "Gamepad.h"
jasper0712 4:4145abd09075 4 #include "GameEngine.h"
jasper0712 0:5fbc0fbc9d30 5
jasper0712 0:5fbc0fbc9d30 6 #define PI 3.14159265
jasper0712 0:5fbc0fbc9d30 7 //Y rows and X columns
jasper0712 1:f5cda0674f24 8 #define Rows 48
jasper0712 1:f5cda0674f24 9 #define Cols 84
jasper0712 0:5fbc0fbc9d30 10
jasper0712 0:5fbc0fbc9d30 11 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
jasper0712 0:5fbc0fbc9d30 12 Gamepad pad;
jasper0712 4:4145abd09075 13 GameEngine game;
jasper0712 5:c74bbdda06f4 14
jasper0712 4:4145abd09075 15
jasper0712 0:5fbc0fbc9d30 16
jasper0712 28:450ab72fabdc 17
jasper0712 29:6632dd9c48d8 18 int gamefps = 15;
jasper0712 28:450ab72fabdc 19
jasper0712 28:450ab72fabdc 20 Ticker waveCompleteTicker;
jasper0712 28:450ab72fabdc 21 int setTicker;
jasper0712 28:450ab72fabdc 22 int waveComplete_flag;
jasper0712 28:450ab72fabdc 23 void waveComplete_isr();
jasper0712 28:450ab72fabdc 24 char wave[10];
jasper0712 28:450ab72fabdc 25 int waveNumber;
jasper0712 28:450ab72fabdc 26
jasper0712 28:450ab72fabdc 27
jasper0712 0:5fbc0fbc9d30 28 void init();
jasper0712 0:5fbc0fbc9d30 29 void render();
jasper0712 0:5fbc0fbc9d30 30
jasper0712 28:450ab72fabdc 31
jasper0712 0:5fbc0fbc9d30 32 int main()
jasper0712 0:5fbc0fbc9d30 33 {
jasper0712 28:450ab72fabdc 34 setTicker = 1; //set the ticker.
jasper0712 0:5fbc0fbc9d30 35 init();
jasper0712 0:5fbc0fbc9d30 36 while (true) {
jasper0712 28:450ab72fabdc 37 if (setTicker == 1) {
jasper0712 30:2e2d48cbfec3 38 game.init(waveNumber);
jasper0712 28:450ab72fabdc 39 sprintf(wave, "wave %d", waveNumber + 1); //+1 because initially waveNumber = 0
jasper0712 28:450ab72fabdc 40 lcd.printString(wave,10,3);
jasper0712 28:450ab72fabdc 41 render();
jasper0712 28:450ab72fabdc 42 wait(2.0);
jasper0712 30:2e2d48cbfec3 43 waveCompleteTicker.attach(&waveComplete_isr,200);
jasper0712 28:450ab72fabdc 44 setTicker = 0; //clear set ticker flag
jasper0712 28:450ab72fabdc 45 }
jasper0712 29:6632dd9c48d8 46
jasper0712 29:6632dd9c48d8 47 game.update(pad, lcd); //this is the game
jasper0712 29:6632dd9c48d8 48
jasper0712 28:450ab72fabdc 49 while(waveComplete_flag == 1) {
jasper0712 28:450ab72fabdc 50 waveCompleteTicker.detach();
jasper0712 28:450ab72fabdc 51 lcd.printString("60 seconds",10,3);
jasper0712 28:450ab72fabdc 52 lcd.printString("Start to Upgrade",1,5);
jasper0712 28:450ab72fabdc 53 render();
jasper0712 28:450ab72fabdc 54 game.weapUpgrade(pad, lcd);
jasper0712 28:450ab72fabdc 55 if (game.done == 1) {
jasper0712 28:450ab72fabdc 56 waveComplete_flag = 0; //get out of while loop
jasper0712 28:450ab72fabdc 57 setTicker = 1; //continue the game
jasper0712 28:450ab72fabdc 58 game.done = 0;
jasper0712 30:2e2d48cbfec3 59 //printf("i got out");
jasper0712 28:450ab72fabdc 60 }
jasper0712 28:450ab72fabdc 61 }
jasper0712 0:5fbc0fbc9d30 62 render();
jasper0712 0:5fbc0fbc9d30 63 }
jasper0712 0:5fbc0fbc9d30 64 }
jasper0712 0:5fbc0fbc9d30 65
jasper0712 28:450ab72fabdc 66 void init() {
jasper0712 0:5fbc0fbc9d30 67 // need to initialise LCD and Gamepad
jasper0712 0:5fbc0fbc9d30 68 lcd.init();
jasper0712 0:5fbc0fbc9d30 69 pad.init();
jasper0712 30:2e2d48cbfec3 70 game.init(waveNumber);
jasper0712 0:5fbc0fbc9d30 71 // initialise the game
jasper0712 0:5fbc0fbc9d30 72 }
jasper0712 28:450ab72fabdc 73 void render() {
jasper0712 0:5fbc0fbc9d30 74 // clear screen, re-draw and refresh
jasper0712 0:5fbc0fbc9d30 75 lcd.refresh();
jasper0712 0:5fbc0fbc9d30 76 wait(1.0/gamefps);
jasper0712 0:5fbc0fbc9d30 77 lcd.clear();
jasper0712 28:450ab72fabdc 78 }
jasper0712 28:450ab72fabdc 79 void waveComplete_isr() {
jasper0712 28:450ab72fabdc 80 waveComplete_flag = 1;
jasper0712 28:450ab72fabdc 81 waveNumber += 1;
jasper0712 0:5fbc0fbc9d30 82 }