zhenye yang
/
el17zy
Yang Zhenye 201199680
Menu/Menu.cpp@5:fcad75e9b9e1, 2020-05-14 (annotated)
- Committer:
- yangzhenye
- Date:
- Thu May 14 14:13:03 2020 +0000
- Revision:
- 5:fcad75e9b9e1
- Parent:
- 4:eb8dca1dc341
- Child:
- 6:4abef55fee88
first
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yangzhenye | 5:fcad75e9b9e1 | 1 | /* |
yangzhenye | 5:fcad75e9b9e1 | 2 | ELEC2645 Embedded Systems Project |
yangzhenye | 5:fcad75e9b9e1 | 3 | School of Electronic & Electrical Engineering |
yangzhenye | 5:fcad75e9b9e1 | 4 | University of Leeds |
yangzhenye | 5:fcad75e9b9e1 | 5 | 2019/20 |
yangzhenye | 5:fcad75e9b9e1 | 6 | |
yangzhenye | 5:fcad75e9b9e1 | 7 | Name:Yang Zhenye |
yangzhenye | 5:fcad75e9b9e1 | 8 | Username:el17zy |
yangzhenye | 5:fcad75e9b9e1 | 9 | Student ID Number:201199680 |
yangzhenye | 5:fcad75e9b9e1 | 10 | Date:2020/5/12 |
yangzhenye | 5:fcad75e9b9e1 | 11 | */ |
yangzhenye | 5:fcad75e9b9e1 | 12 | |
yangzhenye | 2:baca89f466bc | 13 | #include "Menu.h" |
yangzhenye | 2:baca89f466bc | 14 | |
yangzhenye | 2:baca89f466bc | 15 | int _sprite[30][80]= { |
yangzhenye | 5:fcad75e9b9e1 | 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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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 | 5:fcad75e9b9e1 | 17 | {0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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 | 5:fcad75e9b9e1 | 45 | {0,0,0,0,0,1,1,1,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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 | }; |
yangzhenye | 5:fcad75e9b9e1 | 47 | |
yangzhenye | 5:fcad75e9b9e1 | 48 | State fsm[3] = { |
yangzhenye | 5:fcad75e9b9e1 | 49 | {0,{0,1,2,0}}, |
yangzhenye | 5:fcad75e9b9e1 | 50 | {1,{1,1,1,0}}, |
yangzhenye | 5:fcad75e9b9e1 | 51 | {2,{2,2,2,0}} |
yangzhenye | 5:fcad75e9b9e1 | 52 | }; |
yangzhenye | 5:fcad75e9b9e1 | 53 | |
yangzhenye | 5:fcad75e9b9e1 | 54 | Menu::Menu() {} |
yangzhenye | 5:fcad75e9b9e1 | 55 | |
yangzhenye | 5:fcad75e9b9e1 | 56 | Menu::~Menu() {} |
yangzhenye | 5:fcad75e9b9e1 | 57 | |
yangzhenye | 2:baca89f466bc | 58 | |
yangzhenye | 2:baca89f466bc | 59 | void Menu::init() { |
yangzhenye | 2:baca89f466bc | 60 | _state = 0; |
yangzhenye | 5:fcad75e9b9e1 | 61 | _engine.init(); } |
yangzhenye | 2:baca89f466bc | 62 | |
yangzhenye | 2:baca89f466bc | 63 | |
yangzhenye | 5:fcad75e9b9e1 | 64 | void Menu::run_engine(N5110 &lcd, Gamepad &gamepad) { |
yangzhenye | 5:fcad75e9b9e1 | 65 | get_input(gamepad.check_event(Gamepad::START_PRESSED),gamepad.check_event(Gamepad::BACK_PRESSED),gamepad.check_event(Gamepad::X_PRESSED)); |
yangzhenye | 2:baca89f466bc | 66 | _output = fsm[_state].output; |
yangzhenye | 2:baca89f466bc | 67 | _state = fsm[_state].next_state[_input]; } |
yangzhenye | 2:baca89f466bc | 68 | |
yangzhenye | 5:fcad75e9b9e1 | 69 | void Menu::get_input(bool start, bool back, bool x) { |
yangzhenye | 2:baca89f466bc | 70 | if (!start && !back && !x) { |
yangzhenye | 2:baca89f466bc | 71 | _input = 0;} |
yangzhenye | 2:baca89f466bc | 72 | else if (start && !back && !x) { |
yangzhenye | 2:baca89f466bc | 73 | _input = 1;} |
yangzhenye | 2:baca89f466bc | 74 | else if (x && !start && !back) { |
yangzhenye | 2:baca89f466bc | 75 | _input = 2;} |
yangzhenye | 2:baca89f466bc | 76 | else if (!start && back) { |
yangzhenye | 2:baca89f466bc | 77 | _input = 3;} } |
yangzhenye | 5:fcad75e9b9e1 | 78 | |
yangzhenye | 5:fcad75e9b9e1 | 79 | void Menu::get_output(N5110 &lcd, Gamepad &gamepad) { |
yangzhenye | 2:baca89f466bc | 80 | if (_output == 0) { |
yangzhenye | 5:fcad75e9b9e1 | 81 | display_page1(lcd, gamepad); |
yangzhenye | 5:fcad75e9b9e1 | 82 | run_engine(lcd, gamepad); } |
yangzhenye | 5:fcad75e9b9e1 | 83 | else if(_output == 1) { |
yangzhenye | 5:fcad75e9b9e1 | 84 | display_page2(lcd, gamepad); |
yangzhenye | 5:fcad75e9b9e1 | 85 | run_engine(lcd, gamepad); } |
yangzhenye | 5:fcad75e9b9e1 | 86 | else if(_output == 2) { |
yangzhenye | 5:fcad75e9b9e1 | 87 | display_page3(lcd, gamepad); } } |
yangzhenye | 2:baca89f466bc | 88 | |
yangzhenye | 2:baca89f466bc | 89 | |
yangzhenye | 5:fcad75e9b9e1 | 90 | void Menu::display_page1(N5110 &lcd, Gamepad &gamepad) { |
yangzhenye | 2:baca89f466bc | 91 | lcd.printString("Start - playgame!",0,4); |
yangzhenye | 5:fcad75e9b9e1 | 92 | lcd.printString("X - instruction",0,5); |
yangzhenye | 5:fcad75e9b9e1 | 93 | lcd.drawSprite(1,60,30,80,(int*)_sprite); } |
yangzhenye | 2:baca89f466bc | 94 | |
yangzhenye | 5:fcad75e9b9e1 | 95 | void Menu::display_page2(N5110 &lcd, Gamepad &gamepad) { |
yangzhenye | 5:fcad75e9b9e1 | 96 | lcd.printString("love you Tim!",0,0); |
yangzhenye | 5:fcad75e9b9e1 | 97 | } |
yangzhenye | 2:baca89f466bc | 98 | |
yangzhenye | 5:fcad75e9b9e1 | 99 | void Menu::display_page3(N5110 &lcd, Gamepad &gamepad) { |
yangzhenye | 2:baca89f466bc | 100 | lcd.printString("joystick - ",0,1); |
yangzhenye | 4:eb8dca1dc341 | 101 | lcd.printString("control Rooney - ",0,3); |
yangzhenye | 2:baca89f466bc | 102 | lcd.printString("Be a hero! - ",0,4); |
yangzhenye | 2:baca89f466bc | 103 | lcd.printString("Save England! - ",0,1); } |
yangzhenye | 2:baca89f466bc | 104 | |
yangzhenye | 5:fcad75e9b9e1 | 105 | void Menu::run_game(N5110 &lcd, Gamepad &gamepad){ |
yangzhenye | 5:fcad75e9b9e1 | 106 | _engine.run_engine(lcd, gamepad);} |
yangzhenye | 5:fcad75e9b9e1 | 107 | |
yangzhenye | 2:baca89f466bc | 108 | |
yangzhenye | 2:baca89f466bc | 109 |