Peng Jingran
/
Snake_copy
ccc
main.cpp@14:f898d37428b1, 2020-05-11 (annotated)
- Committer:
- pjr
- Date:
- Mon May 11 10:32:00 2020 +0000
- Revision:
- 14:f898d37428b1
- Parent:
- 1:b34f1b9b2b62
Classes
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
VivianDu | 0:bc1d36f5f772 | 1 | #include <math.h> |
VivianDu | 0:bc1d36f5f772 | 2 | #include <stdlib.h> |
VivianDu | 0:bc1d36f5f772 | 3 | #include "Gamepad.h" |
VivianDu | 0:bc1d36f5f772 | 4 | #include "mbed.h" |
VivianDu | 0:bc1d36f5f772 | 5 | #include "N5110.h" |
VivianDu | 0:bc1d36f5f772 | 6 | #include "Snake.h" |
VivianDu | 0:bc1d36f5f772 | 7 | //libraries including |
VivianDu | 0:bc1d36f5f772 | 8 | |
VivianDu | 0:bc1d36f5f772 | 9 | struct UserInput { |
VivianDu | 0:bc1d36f5f772 | 10 | Direction d; |
VivianDu | 0:bc1d36f5f772 | 11 | |
VivianDu | 0:bc1d36f5f772 | 12 | }; |
VivianDu | 0:bc1d36f5f772 | 13 | |
VivianDu | 0:bc1d36f5f772 | 14 | Gamepad pad; |
VivianDu | 0:bc1d36f5f772 | 15 | Snake snake; |
VivianDu | 0:bc1d36f5f772 | 16 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);//hardware used lcd and pad |
VivianDu | 0:bc1d36f5f772 | 17 | |
VivianDu | 0:bc1d36f5f772 | 18 | void init_screen(); |
VivianDu | 0:bc1d36f5f772 | 19 | |
VivianDu | 0:bc1d36f5f772 | 20 | int main() |
VivianDu | 0:bc1d36f5f772 | 21 | { |
VivianDu | 0:bc1d36f5f772 | 22 | lcd.init(); |
VivianDu | 0:bc1d36f5f772 | 23 | pad.init(); |
VivianDu | 0:bc1d36f5f772 | 24 | |
pjr | 14:f898d37428b1 | 25 | snake.init(25,25,20,10); |
VivianDu | 0:bc1d36f5f772 | 26 | init_screen(); |
VivianDu | 0:bc1d36f5f772 | 27 | |
VivianDu | 0:bc1d36f5f772 | 28 | while (true) { |
VivianDu | 0:bc1d36f5f772 | 29 | |
VivianDu | 0:bc1d36f5f772 | 30 | snake.draw(lcd); |
VivianDu | 0:bc1d36f5f772 | 31 | snake.update(pad); |
VivianDu | 0:bc1d36f5f772 | 32 | |
VivianDu | 0:bc1d36f5f772 | 33 | } |
VivianDu | 0:bc1d36f5f772 | 34 | }//initialization |
VivianDu | 0:bc1d36f5f772 | 35 | |
VivianDu | 0:bc1d36f5f772 | 36 | |
VivianDu | 0:bc1d36f5f772 | 37 | void init_screen(){ |
VivianDu | 0:bc1d36f5f772 | 38 | |
pjr | 14:f898d37428b1 | 39 | lcd.printString("Peng Jingran",10,0); |
pjr | 14:f898d37428b1 | 40 | lcd.printString("201199511",20,2); |
pjr | 14:f898d37428b1 | 41 | lcd.printString("Press Start!!!",1,4); |
VivianDu | 0:bc1d36f5f772 | 42 | lcd.refresh();//print the information |
VivianDu | 0:bc1d36f5f772 | 43 | |
VivianDu | 0:bc1d36f5f772 | 44 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
VivianDu | 0:bc1d36f5f772 | 45 | pad.leds_on(); |
pjr | 14:f898d37428b1 | 46 | wait(0.4); |
VivianDu | 0:bc1d36f5f772 | 47 | pad.leds_off(); |
VivianDu | 0:bc1d36f5f772 | 48 | wait(0.1); |
VivianDu | 0:bc1d36f5f772 | 49 | printf("Error"); |
VivianDu | 0:bc1d36f5f772 | 50 | } |
VivianDu | 1:b34f1b9b2b62 | 51 | printf("start!!!");//condition of the unsuccesful login |
VivianDu | 0:bc1d36f5f772 | 52 | } |
VivianDu | 0:bc1d36f5f772 | 53 |