Yang Zhenye 201199680
Dependencies: mbed
Menu/Menu.cpp@4:eb8dca1dc341, 2020-05-13 (annotated)
- Committer:
- yangzhenye
- Date:
- Wed May 13 14:55:07 2020 +0000
- Revision:
- 4:eb8dca1dc341
- Parent:
- 3:30c81344beff
- Child:
- 5:fcad75e9b9e1
advance
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yangzhenye | 2:baca89f466bc | 1 | #include "Menu.h" |
yangzhenye | 2:baca89f466bc | 2 | |
yangzhenye | 2:baca89f466bc | 3 | int _sprite[30][80]= { |
yangzhenye | 4:eb8dca1dc341 | 4 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 5 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 6 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 7 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 8 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 9 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 10 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 11 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 12 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 13 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 14 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 15 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 16 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 17 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 18 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 19 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 20 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 21 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 22 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 23 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 24 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 25 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 26 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 27 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 28 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 29 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 30 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 31 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 32 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 33 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 34 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 35 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 36 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 37 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 38 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 39 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 40 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 41 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 42 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 43 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 44 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 45 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 46 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 47 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 48 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 49 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 50 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 51 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 52 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 53 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 54 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 55 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 56 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 57 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 58 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 59 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 60 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 61 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 62 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 63 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 64 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 65 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 66 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 67 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 68 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 69 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 70 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 71 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 72 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 73 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 74 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 75 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 76 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 77 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 78 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 79 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 80 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 81 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 82 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 83 | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
yangzhenye | 4:eb8dca1dc341 | 84 | }; |
yangzhenye | 2:baca89f466bc | 85 | |
yangzhenye | 2:baca89f466bc | 86 | |
yangzhenye | 2:baca89f466bc | 87 | |
yangzhenye | 2:baca89f466bc | 88 | void Menu::init() { |
yangzhenye | 2:baca89f466bc | 89 | _state = 0; |
yangzhenye | 2:baca89f466bc | 90 | engine.init(); } |
yangzhenye | 2:baca89f466bc | 91 | |
yangzhenye | 2:baca89f466bc | 92 | |
yangzhenye | 2:baca89f466bc | 93 | void Menu::run(N5110 &lcd, Gamepad &gamepad) { |
yangzhenye | 2:baca89f466bc | 94 | input(gamepad.check_event(Gamepad::START_PRESSED,gamepad.check_event(Gamepad::BACK_PRESSED),gamepad.check_event(Gamepad::X_PRESSED)) |
yangzhenye | 2:baca89f466bc | 95 | _output = fsm[_state].output; |
yangzhenye | 2:baca89f466bc | 96 | output(); |
yangzhenye | 2:baca89f466bc | 97 | _state = fsm[_state].next_state[_input]; } |
yangzhenye | 2:baca89f466bc | 98 | |
yangzhenye | 2:baca89f466bc | 99 | void input(bool start, bool back, bool x) { |
yangzhenye | 2:baca89f466bc | 100 | if (!start && !back && !x) { |
yangzhenye | 2:baca89f466bc | 101 | _input = 0;} |
yangzhenye | 2:baca89f466bc | 102 | else if (start && !back && !x) { |
yangzhenye | 2:baca89f466bc | 103 | _input = 1;} |
yangzhenye | 2:baca89f466bc | 104 | else if (x && !start && !back) { |
yangzhenye | 2:baca89f466bc | 105 | _input = 2;} |
yangzhenye | 2:baca89f466bc | 106 | else if (!start && back) { |
yangzhenye | 2:baca89f466bc | 107 | _input = 3;} } |
yangzhenye | 2:baca89f466bc | 108 | void output() { |
yangzhenye | 2:baca89f466bc | 109 | if (_output == 0) { |
yangzhenye | 3:30c81344beff | 110 | display_page1; |
yangzhenye | 3:30c81344beff | 111 | run_engine(lcd, gamepad) } |
yangzhenye | 2:baca89f466bc | 112 | else if(_output == 1) { |
yangzhenye | 2:baca89f466bc | 113 | display_page2; |
yangzhenye | 2:baca89f466bc | 114 | run_engine(); } |
yangzhenye | 2:baca89f466bc | 115 | else if(_output == 2) { |
yangzhenye | 2:baca89f466bc | 116 | display_page3; } } |
yangzhenye | 2:baca89f466bc | 117 | |
yangzhenye | 2:baca89f466bc | 118 | State fsm[3] = { |
yangzhenye | 2:baca89f466bc | 119 | {0,{0,1,2,0}}, |
yangzhenye | 2:baca89f466bc | 120 | {1,{1,1,1,0}}, |
yangzhenye | 2:baca89f466bc | 121 | {2,{2,2,2,0}} |
yangzhenye | 2:baca89f466bc | 122 | } |
yangzhenye | 2:baca89f466bc | 123 | |
yangzhenye | 2:baca89f466bc | 124 | display_page1(N5110 &lcd, Gamepad &gamepad) { |
yangzhenye | 2:baca89f466bc | 125 | lcd.printString("Start - playgame!",0,4); |
yangzhenye | 2:baca89f466bc | 126 | lcd.printSrting("X - instruction",0,5); |
yangzhenye | 2:baca89f466bc | 127 | lcd.drawSptire(1,60,30,80,(int*)_sprite); } |
yangzhenye | 2:baca89f466bc | 128 | |
yangzhenye | 2:baca89f466bc | 129 | display_page2(N5110 &lcd, Gamepad &gamepad) { |
yangzhenye | 2:baca89f466bc | 130 | lcd.printString("love you Tim!",0,0) |
yangzhenye | 2:baca89f466bc | 131 | lcd.refresh; wait(0.5);} |
yangzhenye | 2:baca89f466bc | 132 | |
yangzhenye | 2:baca89f466bc | 133 | display_page3(N5110 &lcd, Gamepad &gamepad) { |
yangzhenye | 2:baca89f466bc | 134 | lcd.printString("joystick - ",0,1); |
yangzhenye | 4:eb8dca1dc341 | 135 | lcd.printString("control Rooney - ",0,3); |
yangzhenye | 2:baca89f466bc | 136 | lcd.printString("Be a hero! - ",0,4); |
yangzhenye | 2:baca89f466bc | 137 | lcd.printString("Save England! - ",0,1); } |
yangzhenye | 2:baca89f466bc | 138 | |
yangzhenye | 2:baca89f466bc | 139 | |
yangzhenye | 2:baca89f466bc | 140 |