Su 200943147

Dependencies:   Gamepad N5110 mbed

Committer:
GS00
Date:
Wed May 03 21:52:52 2017 +0000
Revision:
7:31dd8865cc44
Parent:
6:e919a1fd1eed
Child:
8:3899d883d329
Version8

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 7:31dd8865cc44 25 Engine.Update1(lcd);
GS00 3:9dd35424cdfe 26 Engine.Pixel(lcd);
GS00 3:9dd35424cdfe 27 lcd.refresh();
GS00 6:e919a1fd1eed 28 lcd.clear();
GS00 6:e919a1fd1eed 29 wait(0.3);
GS00 3:9dd35424cdfe 30 }
GS00 3:9dd35424cdfe 31 }
GS00 3:9dd35424cdfe 32
GS00 3:9dd35424cdfe 33 void Init()
GS00 3:9dd35424cdfe 34 {
GS00 3:9dd35424cdfe 35 // need to initialise LCD and Gamepad
GS00 3:9dd35424cdfe 36 lcd.init();
GS00 3:9dd35424cdfe 37 pad.init();
GS00 3:9dd35424cdfe 38
GS00 3:9dd35424cdfe 39 // initialise the game
GS00 5:afa6592a4ba5 40 Engine.Init(lcd);
GS00 3:9dd35424cdfe 41 lcd.normalMode(); // normal colour mode
GS00 3:9dd35424cdfe 42 lcd.setBrightness(0.5); // put LED backlight on 50%
GS00 3:9dd35424cdfe 43 }
GS00 6:e919a1fd1eed 44
GS00 6:e919a1fd1eed 45 void Welcome() {
GS00 6:e919a1fd1eed 46
GS00 6:e919a1fd1eed 47 lcd.printString(" Tetris! ",0,1);
GS00 6:e919a1fd1eed 48 lcd.printString(" Press Start ",0,4);
GS00 6:e919a1fd1eed 49 lcd.refresh();
GS00 6:e919a1fd1eed 50
GS00 6:e919a1fd1eed 51 // flashing LEDs until start button is pressed
GS00 6:e919a1fd1eed 52 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
GS00 6:e919a1fd1eed 53 pad.leds_on();
GS00 6:e919a1fd1eed 54 wait(0.1);
GS00 6:e919a1fd1eed 55 pad.leds_off();
GS00 6:e919a1fd1eed 56 wait(0.1);
GS00 6:e919a1fd1eed 57 }
GS00 6:e919a1fd1eed 58 }