ELEC2645 (2018/19) / Mbed 2 deprecated el17arm

Dependencies:   mbed

main.cpp

Committer:
el17arm
Date:
2019-04-10
Revision:
29:d85886364643
Parent:
27:e73dd64ef334
Child:
30:6d6b48fe3679

File content as of revision 29:d85886364643:

#include "mbed.h"
#include "N5110.h"
#include "Gamepad.h"
#include "Gameengine.h"

Key _k;
Gameengine game;
Gamepad pad;
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
AnalogIn pot0(PTB2);

void contrast();
void init();
void start_screen();
void render();
void restart();

int main()
{
    init();
    start_screen();

    while (1) {
        
        contrast();
        render();
        game.update(lcd, pad);
        restart();
        wait(0.1);
    }

}

void init()
{
    lcd.init();
    lcd.normalMode();      // normal colour mode
    lcd.setBrightness(0.5); // put LED backlight on 50%
    lcd.refresh();
    pad.init();
    pad.leds_off();
    contrast();
    game.game_init();
}

void render()
{
    game.draw(_k, lcd, pad);
}

void contrast()
{
    lcd.refresh();
    float con = pot0.read();
    lcd.setContrast(con);
    lcd.clear();
}

void start_screen()
{
    lcd.printString("*MANIC MILNER!*",0,1);
    lcd.printString(" Press start! ",0,4);
    lcd.refresh();
    while ( pad.check_event(Gamepad::START_PRESSED) == false) {
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
}

void restart()
{
    if (game.game_over() == true) {
        lcd.clear();
        lcd.printString("Game Over! ",16,1);
        lcd.printString("Press reset to try again! ",0,3);
        lcd.printString("try again! ",16,4);
        wait(1);
    }
}