Meteor defense project

Dependencies:   N5110 mbed

Committer:
jasper0712
Date:
Mon Apr 17 18:22:16 2017 +0000
Revision:
28:450ab72fabdc
Parent:
17:53aedd20155a
Child:
29:6632dd9c48d8
now trying to connect wu and weapon

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 28:450ab72fabdc 18 int gamefps = 3;
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 28:450ab72fabdc 38 sprintf(wave, "wave %d", waveNumber + 1); //+1 because initially waveNumber = 0
jasper0712 28:450ab72fabdc 39 lcd.printString(wave,10,3);
jasper0712 28:450ab72fabdc 40 render();
jasper0712 28:450ab72fabdc 41 wait(2.0);
jasper0712 28:450ab72fabdc 42 waveCompleteTicker.attach(&waveComplete_isr,2);
jasper0712 28:450ab72fabdc 43 setTicker = 0; //clear set ticker flag
jasper0712 28:450ab72fabdc 44 }
jasper0712 28:450ab72fabdc 45 //game.update(pad, lcd); //this is the game
jasper0712 28:450ab72fabdc 46 while(waveComplete_flag == 1) {
jasper0712 28:450ab72fabdc 47 waveCompleteTicker.detach();
jasper0712 28:450ab72fabdc 48 lcd.printString("60 seconds",10,3);
jasper0712 28:450ab72fabdc 49 lcd.printString("Start to Upgrade",1,5);
jasper0712 28:450ab72fabdc 50 render();
jasper0712 28:450ab72fabdc 51 game.weapUpgrade(pad, lcd);
jasper0712 28:450ab72fabdc 52 if (game.done == 1) {
jasper0712 28:450ab72fabdc 53 waveComplete_flag = 0; //get out of while loop
jasper0712 28:450ab72fabdc 54 setTicker = 1; //continue the game
jasper0712 28:450ab72fabdc 55 game.done = 0;
jasper0712 28:450ab72fabdc 56 printf("i got out");
jasper0712 28:450ab72fabdc 57 }
jasper0712 28:450ab72fabdc 58 }
jasper0712 0:5fbc0fbc9d30 59 render();
jasper0712 0:5fbc0fbc9d30 60 }
jasper0712 0:5fbc0fbc9d30 61 }
jasper0712 0:5fbc0fbc9d30 62
jasper0712 28:450ab72fabdc 63 void init() {
jasper0712 0:5fbc0fbc9d30 64 // need to initialise LCD and Gamepad
jasper0712 0:5fbc0fbc9d30 65 lcd.init();
jasper0712 0:5fbc0fbc9d30 66 pad.init();
jasper0712 17:53aedd20155a 67 game.init();
jasper0712 0:5fbc0fbc9d30 68 // initialise the game
jasper0712 0:5fbc0fbc9d30 69 }
jasper0712 28:450ab72fabdc 70 void render() {
jasper0712 0:5fbc0fbc9d30 71 // clear screen, re-draw and refresh
jasper0712 0:5fbc0fbc9d30 72 lcd.refresh();
jasper0712 0:5fbc0fbc9d30 73 wait(1.0/gamefps);
jasper0712 0:5fbc0fbc9d30 74 lcd.clear();
jasper0712 28:450ab72fabdc 75 }
jasper0712 28:450ab72fabdc 76 void waveComplete_isr() {
jasper0712 28:450ab72fabdc 77 waveComplete_flag = 1;
jasper0712 28:450ab72fabdc 78 waveNumber += 1;
jasper0712 0:5fbc0fbc9d30 79 }