Su 200943147

Dependencies:   Gamepad N5110 mbed

Committer:
GS00
Date:
Wed May 03 08:42:22 2017 +0000
Revision:
6:e919a1fd1eed
Parent:
5:afa6592a4ba5
Child:
7:31dd8865cc44
Current Version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
GS00 0:444b4d0a113d 1 #include "mbed.h"
GS00 0:444b4d0a113d 2 #include "N5110.h"
GS00 3:9dd35424cdfe 3 #include "Engine.h"
GS00 3:9dd35424cdfe 4 #include "Gamepad.h"
GS00 0:444b4d0a113d 5
GS00 3:9dd35424cdfe 6 struct UserInput {
GS00 3:9dd35424cdfe 7 Direction d;
GS00 3:9dd35424cdfe 8 };
GS00 3:9dd35424cdfe 9
GS00 3:9dd35424cdfe 10 //N5110 lcd(p7,p8,p9,p10,p11,p13,p21);
GS00 0:444b4d0a113d 11 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
GS00 3:9dd35424cdfe 12 Gamepad pad;
GS00 3:9dd35424cdfe 13 Engine Engine;
GS00 3:9dd35424cdfe 14 void Init();
GS00 6:e919a1fd1eed 15 void Welcome();
GS00 0:444b4d0a113d 16
GS00 3:9dd35424cdfe 17 int main()
GS00 3:9dd35424cdfe 18 {
GS00 3:9dd35424cdfe 19 Init();
GS00 6:e919a1fd1eed 20 //Welcome();
GS00 3:9dd35424cdfe 21 // game loop - read input, update the game state and render the display
GS00 3:9dd35424cdfe 22 while (1) {
GS00 3:9dd35424cdfe 23 Engine.ReadInput(pad);
GS00 3:9dd35424cdfe 24 Engine.Update(pad);
GS00 3:9dd35424cdfe 25 Engine.Pixel(lcd);
GS00 3:9dd35424cdfe 26 lcd.refresh();
GS00 6:e919a1fd1eed 27 lcd.clear();
GS00 6:e919a1fd1eed 28 wait(0.3);
GS00 3:9dd35424cdfe 29 }
GS00 3:9dd35424cdfe 30 }
GS00 3:9dd35424cdfe 31
GS00 3:9dd35424cdfe 32 void Init()
GS00 3:9dd35424cdfe 33 {
GS00 3:9dd35424cdfe 34 // need to initialise LCD and Gamepad
GS00 3:9dd35424cdfe 35 lcd.init();
GS00 3:9dd35424cdfe 36 pad.init();
GS00 3:9dd35424cdfe 37
GS00 3:9dd35424cdfe 38 // initialise the game
GS00 5:afa6592a4ba5 39 Engine.Init(lcd);
GS00 3:9dd35424cdfe 40 lcd.normalMode(); // normal colour mode
GS00 3:9dd35424cdfe 41 lcd.setBrightness(0.5); // put LED backlight on 50%
GS00 3:9dd35424cdfe 42 }
GS00 6:e919a1fd1eed 43
GS00 6:e919a1fd1eed 44 void Welcome() {
GS00 6:e919a1fd1eed 45
GS00 6:e919a1fd1eed 46 lcd.printString(" Tetris! ",0,1);
GS00 6:e919a1fd1eed 47 lcd.printString(" Press Start ",0,4);
GS00 6:e919a1fd1eed 48 lcd.refresh();
GS00 6:e919a1fd1eed 49
GS00 6:e919a1fd1eed 50 // flashing LEDs until start button is pressed
GS00 6:e919a1fd1eed 51 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
GS00 6:e919a1fd1eed 52 pad.leds_on();
GS00 6:e919a1fd1eed 53 wait(0.1);
GS00 6:e919a1fd1eed 54 pad.leds_off();
GS00 6:e919a1fd1eed 55 wait(0.1);
GS00 6:e919a1fd1eed 56 }
GS00 6:e919a1fd1eed 57 }