Meteor defense project

Dependencies:   N5110 mbed

main.cpp

Committer:
jasper0712
Date:
2017-04-18
Revision:
29:6632dd9c48d8
Parent:
28:450ab72fabdc
Child:
30:2e2d48cbfec3

File content as of revision 29:6632dd9c48d8:

#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;
void waveComplete_isr();
char wave[10]; 
int waveNumber;


void init();
void render();


int main()
{
    setTicker = 1; //set the ticker.
    init();
    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();
            waveCompleteTicker.attach(&waveComplete_isr,60);
            setTicker = 0; //clear set ticker flag
        }
        
        game.update(pad, lcd); //this is the game
        
        while(waveComplete_flag == 1) {
            waveCompleteTicker.detach();
            lcd.printString("60 seconds",10,3);
            lcd.printString("Start to Upgrade",1,5);
            render();
            game.weapUpgrade(pad, lcd);
            if (game.done == 1) {
                waveComplete_flag = 0; //get out of while loop
                setTicker = 1; //continue the game
                game.done = 0;
                printf("i got out");
            }
        }
        render();
    }
}

void init() {
    // need to initialise LCD and Gamepad 
    lcd.init();
    pad.init();
    game.init();
    // 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;
}