zhenye yang
/
el17zy
Yang Zhenye 201199680
Menu/Menu.cpp@2:baca89f466bc, 2020-04-30 (annotated)
- Committer:
- yangzhenye
- Date:
- Thu Apr 30 07:08:09 2020 +0000
- Revision:
- 2:baca89f466bc
- Child:
- 3:30c81344beff
complete menu and improve roony
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 | 2:baca89f466bc | 4 | |
yangzhenye | 2:baca89f466bc | 5 | |
yangzhenye | 2:baca89f466bc | 6 | |
yangzhenye | 2:baca89f466bc | 7 | |
yangzhenye | 2:baca89f466bc | 8 | |
yangzhenye | 2:baca89f466bc | 9 | |
yangzhenye | 2:baca89f466bc | 10 | |
yangzhenye | 2:baca89f466bc | 11 | |
yangzhenye | 2:baca89f466bc | 12 | |
yangzhenye | 2:baca89f466bc | 13 | |
yangzhenye | 2:baca89f466bc | 14 | |
yangzhenye | 2:baca89f466bc | 15 | |
yangzhenye | 2:baca89f466bc | 16 | |
yangzhenye | 2:baca89f466bc | 17 | void Menu::init() { |
yangzhenye | 2:baca89f466bc | 18 | _state = 0; |
yangzhenye | 2:baca89f466bc | 19 | engine.init(); } |
yangzhenye | 2:baca89f466bc | 20 | |
yangzhenye | 2:baca89f466bc | 21 | |
yangzhenye | 2:baca89f466bc | 22 | void Menu::run(N5110 &lcd, Gamepad &gamepad) { |
yangzhenye | 2:baca89f466bc | 23 | input(gamepad.check_event(Gamepad::START_PRESSED,gamepad.check_event(Gamepad::BACK_PRESSED),gamepad.check_event(Gamepad::X_PRESSED)) |
yangzhenye | 2:baca89f466bc | 24 | _output = fsm[_state].output; |
yangzhenye | 2:baca89f466bc | 25 | output(); |
yangzhenye | 2:baca89f466bc | 26 | _state = fsm[_state].next_state[_input]; } |
yangzhenye | 2:baca89f466bc | 27 | |
yangzhenye | 2:baca89f466bc | 28 | void input(bool start, bool back, bool x) { |
yangzhenye | 2:baca89f466bc | 29 | if (!start && !back && !x) { |
yangzhenye | 2:baca89f466bc | 30 | _input = 0;} |
yangzhenye | 2:baca89f466bc | 31 | else if (start && !back && !x) { |
yangzhenye | 2:baca89f466bc | 32 | _input = 1;} |
yangzhenye | 2:baca89f466bc | 33 | else if (x && !start && !back) { |
yangzhenye | 2:baca89f466bc | 34 | _input = 2;} |
yangzhenye | 2:baca89f466bc | 35 | else if (!start && back) { |
yangzhenye | 2:baca89f466bc | 36 | _input = 3;} } |
yangzhenye | 2:baca89f466bc | 37 | void output() { |
yangzhenye | 2:baca89f466bc | 38 | if (_output == 0) { |
yangzhenye | 2:baca89f466bc | 39 | display_page1; } |
yangzhenye | 2:baca89f466bc | 40 | else if(_output == 1) { |
yangzhenye | 2:baca89f466bc | 41 | display_page2; |
yangzhenye | 2:baca89f466bc | 42 | run_engine(); } |
yangzhenye | 2:baca89f466bc | 43 | else if(_output == 2) { |
yangzhenye | 2:baca89f466bc | 44 | display_page3; } } |
yangzhenye | 2:baca89f466bc | 45 | |
yangzhenye | 2:baca89f466bc | 46 | State fsm[3] = { |
yangzhenye | 2:baca89f466bc | 47 | {0,{0,1,2,0}}, |
yangzhenye | 2:baca89f466bc | 48 | {1,{1,1,1,0}}, |
yangzhenye | 2:baca89f466bc | 49 | {2,{2,2,2,0}} |
yangzhenye | 2:baca89f466bc | 50 | } |
yangzhenye | 2:baca89f466bc | 51 | |
yangzhenye | 2:baca89f466bc | 52 | display_page1(N5110 &lcd, Gamepad &gamepad) { |
yangzhenye | 2:baca89f466bc | 53 | lcd.printString("Start - playgame!",0,4); |
yangzhenye | 2:baca89f466bc | 54 | lcd.printSrting("X - instruction",0,5); |
yangzhenye | 2:baca89f466bc | 55 | lcd.drawSptire(1,60,30,80,(int*)_sprite); } |
yangzhenye | 2:baca89f466bc | 56 | |
yangzhenye | 2:baca89f466bc | 57 | display_page2(N5110 &lcd, Gamepad &gamepad) { |
yangzhenye | 2:baca89f466bc | 58 | lcd.printString("love you Tim!",0,0) |
yangzhenye | 2:baca89f466bc | 59 | lcd.refresh; wait(0.5);} |
yangzhenye | 2:baca89f466bc | 60 | |
yangzhenye | 2:baca89f466bc | 61 | display_page3(N5110 &lcd, Gamepad &gamepad) { |
yangzhenye | 2:baca89f466bc | 62 | lcd.printString("joystick - ",0,1); |
yangzhenye | 2:baca89f466bc | 63 | lcd.printString("control Roony - ",0,3); |
yangzhenye | 2:baca89f466bc | 64 | lcd.printString("Be a hero! - ",0,4); |
yangzhenye | 2:baca89f466bc | 65 | lcd.printString("Save England! - ",0,1); } |
yangzhenye | 2:baca89f466bc | 66 | |
yangzhenye | 2:baca89f466bc | 67 | |
yangzhenye | 2:baca89f466bc | 68 |