Su 200943147
Dependencies: Gamepad N5110 mbed
main.cpp@9:6ee4c806f3e9, 2017-05-04 (annotated)
- Committer:
- GS00
- Date:
- Thu May 04 14:20:35 2017 +0000
- Revision:
- 9:6ee4c806f3e9
- Parent:
- 8:3899d883d329
Final and Upload version
Who changed what in which revision?
User | Revision | Line number | New 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 | 9:6ee4c806f3e9 | 6 | /** |
GS00 | 9:6ee4c806f3e9 | 7 | *Tetris |
GS00 | 9:6ee4c806f3e9 | 8 | *Author Guanxiong Su |
GS00 | 9:6ee4c806f3e9 | 9 | *Date May 2017 |
GS00 | 9:6ee4c806f3e9 | 10 | */ |
GS00 | 9:6ee4c806f3e9 | 11 | |
GS00 | 3:9dd35424cdfe | 12 | struct UserInput { |
GS00 | 3:9dd35424cdfe | 13 | Direction d; |
GS00 | 3:9dd35424cdfe | 14 | }; |
GS00 | 3:9dd35424cdfe | 15 | |
GS00 | 8:3899d883d329 | 16 | //////////////////Object//////////////////// |
GS00 | 0:444b4d0a113d | 17 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
GS00 | 3:9dd35424cdfe | 18 | Gamepad pad; |
GS00 | 3:9dd35424cdfe | 19 | Engine Engine; |
GS00 | 8:3899d883d329 | 20 | ///////////////Function//////////////////// |
GS00 | 3:9dd35424cdfe | 21 | void Init(); |
GS00 | 8:3899d883d329 | 22 | void WelcometoStart(); |
GS00 | 0:444b4d0a113d | 23 | |
GS00 | 8:3899d883d329 | 24 | ///////////////MainLoop///////////////////// |
GS00 | 3:9dd35424cdfe | 25 | int main() |
GS00 | 3:9dd35424cdfe | 26 | { |
GS00 | 3:9dd35424cdfe | 27 | Init(); |
GS00 | 8:3899d883d329 | 28 | WelcometoStart(); |
GS00 | 8:3899d883d329 | 29 | |
GS00 | 8:3899d883d329 | 30 | int fps = 4; //4 frames per second |
GS00 | 8:3899d883d329 | 31 | wait(1.0f/fps); |
GS00 | 8:3899d883d329 | 32 | |
GS00 | 8:3899d883d329 | 33 | // game loop - read input, update the game state and screen display |
GS00 | 3:9dd35424cdfe | 34 | while (1) { |
GS00 | 3:9dd35424cdfe | 35 | Engine.ReadInput(pad); |
GS00 | 8:3899d883d329 | 36 | Engine.Update(lcd,pad); |
GS00 | 3:9dd35424cdfe | 37 | Engine.Pixel(lcd); |
GS00 | 8:3899d883d329 | 38 | wait(1.0f/fps); |
GS00 | 3:9dd35424cdfe | 39 | } |
GS00 | 3:9dd35424cdfe | 40 | } |
GS00 | 3:9dd35424cdfe | 41 | |
GS00 | 3:9dd35424cdfe | 42 | void Init() |
GS00 | 3:9dd35424cdfe | 43 | { |
GS00 | 8:3899d883d329 | 44 | // initialise the LCD and Gamepad |
GS00 | 3:9dd35424cdfe | 45 | lcd.init(); |
GS00 | 3:9dd35424cdfe | 46 | pad.init(); |
GS00 | 8:3899d883d329 | 47 | lcd.normalMode(); // normal colour mode |
GS00 | 8:3899d883d329 | 48 | lcd.setBrightness(0.5); // put LED backlight on 50% |
GS00 | 3:9dd35424cdfe | 49 | |
GS00 | 3:9dd35424cdfe | 50 | // initialise the game |
GS00 | 5:afa6592a4ba5 | 51 | Engine.Init(lcd); |
GS00 | 3:9dd35424cdfe | 52 | } |
GS00 | 6:e919a1fd1eed | 53 | |
GS00 | 8:3899d883d329 | 54 | void WelcometoStart() |
GS00 | 8:3899d883d329 | 55 | { |
GS00 | 8:3899d883d329 | 56 | lcd.printString(" Welcome ",0,2); |
GS00 | 8:3899d883d329 | 57 | lcd.printString(" Tetris ",0,3); |
GS00 | 9:6ee4c806f3e9 | 58 | lcd.printString(" Press Start ",0,4); |
GS00 | 6:e919a1fd1eed | 59 | lcd.refresh(); |
GS00 | 8:3899d883d329 | 60 | |
GS00 | 8:3899d883d329 | 61 | // flashing LEDs until start button is pressed |
GS00 | 6:e919a1fd1eed | 62 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
GS00 | 8:3899d883d329 | 63 | for(int a=0; a<7; a++) { |
GS00 | 8:3899d883d329 | 64 | pad.led(a,1); //led on from left to right |
GS00 | 8:3899d883d329 | 65 | wait(0.1); //time delay |
GS00 | 8:3899d883d329 | 66 | } |
GS00 | 8:3899d883d329 | 67 | for(int a=6; a>0; a--) { |
GS00 | 8:3899d883d329 | 68 | pad.led(a,0); //led off from right to left |
GS00 | 8:3899d883d329 | 69 | wait(0.1); //time delay |
GS00 | 8:3899d883d329 | 70 | } |
GS00 | 6:e919a1fd1eed | 71 | } |
GS00 | 6:e919a1fd1eed | 72 | } |