Su 200943147

Dependencies:   Gamepad N5110 mbed

main.cpp

Committer:
GS00
Date:
2017-05-03
Revision:
7:31dd8865cc44
Parent:
6:e919a1fd1eed
Child:
8:3899d883d329

File content as of revision 7:31dd8865cc44:

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

struct UserInput {
    Direction d;
};

//N5110 lcd(p7,p8,p9,p10,p11,p13,p21);
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
Engine Engine;
void Init();
void Welcome();

int main()
{
    Init();
    //Welcome();
    // game loop - read input, update the game state and render the display
    while (1) {
        Engine.ReadInput(pad);
        Engine.Update(pad);
        Engine.Update1(lcd);
        Engine.Pixel(lcd);
        lcd.refresh();
        lcd.clear();
        wait(0.3);
    }
}

void Init()
{
    // need to initialise LCD and Gamepad
    lcd.init();
    pad.init();

    // initialise the game
    Engine.Init(lcd);
    lcd.normalMode();      // normal colour mode
    lcd.setBrightness(0.5); // put LED backlight on 50%
}

void Welcome() {
    
    lcd.printString("   Tetris!    ",0,1);  
    lcd.printString("  Press Start ",0,4);
    lcd.refresh();
     
    // flashing LEDs until start button is pressed 
    while ( pad.check_event(Gamepad::START_PRESSED) == false) {
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
}