Mochu Yao explorer game
Dependencies: mbed
menu/Menu.cpp@32:47d98959b4ef, 2020-04-29 (annotated)
- Committer:
- el17my
- Date:
- Wed Apr 29 12:19:12 2020 +0000
- Revision:
- 32:47d98959b4ef
- Parent:
- 31:8e92b65e0779
- Child:
- 36:cdfba51a0a44
4.29
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17my | 22:f8ba0ab7465c | 1 | #include "Menu.h" |
el17my | 13:30330d61f09c | 2 | |
el17my | 13:30330d61f09c | 3 | int page1_sprite[25][80] = { |
el17my | 13:30330d61f09c | 4 | { 0,0,0,0,0,0,0,0,0,0,0,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 }, |
el17my | 13:30330d61f09c | 5 | { 0,0,0,0,0,1,1,1,0,0,0,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 }, |
el17my | 13:30330d61f09c | 6 | { 0,0,0,0,1,1,0,0,1,0,0,0,0,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 }, |
el17my | 13:30330d61f09c | 7 | { 0,0,0,1,1,0,0,1,1,0,0,0,0,0,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 }, |
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,1,0,0,0,0,1,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0 }, |
el17my | 13:30330d61f09c | 25 | { 0,0,1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0 }, |
el17my | 13:30330d61f09c | 26 | { 0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0 }, |
el17my | 13:30330d61f09c | 27 | { 0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,1,0,0,0,0,0 }, |
el17my | 13:30330d61f09c | 28 | { 0,1,0,0,0,0,1,1,1,0,0,0,0,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 }, |
el17my | 13:30330d61f09c | 29 | }; |
el17my | 13:30330d61f09c | 30 | //*using the UPDown counter example in class 201. |
el17my | 13:30330d61f09c | 31 | //there are three pages so we have three output and we cna press the start, back and y button to change the page.These are the input |
el17my | 13:30330d61f09c | 32 | // |
el17my | 32:47d98959b4ef | 33 | State _fsm[3] = { |
el17my | 32:47d98959b4ef | 34 | {0,{0,1,0,0}}, |
el17my | 32:47d98959b4ef | 35 | {1,{1,1,0,2}}, |
el17my | 32:47d98959b4ef | 36 | {2,{2,1,2,0}} |
el17my | 15:814084bbc111 | 37 | }; |
el17my | 13:30330d61f09c | 38 | |
el17my | 21:349c70c8a7de | 39 | Menu::Menu() {} |
el17my | 13:30330d61f09c | 40 | |
el17my | 21:349c70c8a7de | 41 | Menu::~Menu() {} |
el17my | 13:30330d61f09c | 42 | |
el17my | 21:349c70c8a7de | 43 | void Menu::init() { |
el17my | 13:30330d61f09c | 44 | // Starting setup of menu. |
el17my | 17:1b4ecc01b79f | 45 | _state = 1; // Starting state is the menu. |
el17my | 13:30330d61f09c | 46 | _game_engine.init(); } |
el17my | 13:30330d61f09c | 47 | |
el17my | 21:349c70c8a7de | 48 | void Menu::run_engine(N5110 &lcd, Gamepad &gamepad) { |
el17my | 32:47d98959b4ef | 49 | get_input(gamepad.check_event(Gamepad::START_PRESSED), gamepad.check_event(Gamepad::BACK_PRESSED),gamepad.check_event(Gamepad::A_PRESSED)); |
el17my | 32:47d98959b4ef | 50 | _output = _fsm[_state].output; |
el17my | 19:14c5427b30d1 | 51 | if (_output == 0) { |
el17my | 13:30330d61f09c | 52 | run_game(lcd, gamepad); // Runs the main game loop. |
el17my | 13:30330d61f09c | 53 | } else if (_output == 1) { |
el17my | 13:30330d61f09c | 54 | display_page1(lcd, gamepad); // Displays the main menu. |
el17my | 32:47d98959b4ef | 55 | } else if (_output == 2) { |
el17my | 13:30330d61f09c | 56 | display_page2(lcd, gamepad); // Displayes the control page. |
el17my | 31:8e92b65e0779 | 57 | } |
el17my | 31:8e92b65e0779 | 58 | // implement required delay |
el17my | 31:8e92b65e0779 | 59 | // set the next state depending on direction |
el17my | 32:47d98959b4ef | 60 | _state = _fsm[_state].next_state[_input_value]; |
el17my | 31:8e92b65e0779 | 61 | } |
el17my | 22:f8ba0ab7465c | 62 | |
el17my | 32:47d98959b4ef | 63 | void Menu::get_input(bool start, bool back, bool a) { |
el17my | 32:47d98959b4ef | 64 | if(!start && !back && !a) { |
el17my | 20:20e6ba54e15c | 65 | _input_value = 0;} |
el17my | 31:8e92b65e0779 | 66 | else if (!start && back) { |
el17my | 31:8e92b65e0779 | 67 | _input_value = 1;} |
el17my | 20:20e6ba54e15c | 68 | else if (start && !back) { |
el17my | 20:20e6ba54e15c | 69 | _input_value = 2;} |
el17my | 32:47d98959b4ef | 70 | else if (a) { |
el17my | 19:14c5427b30d1 | 71 | _input_value = 3;} |
el17my | 13:30330d61f09c | 72 | } |
el17my | 13:30330d61f09c | 73 | |
el17my | 21:349c70c8a7de | 74 | void Menu::display_page1(N5110 &lcd, Gamepad &gamepad) { |
el17my | 31:8e92b65e0779 | 75 | lcd.printString("START - Play!",0,0); |
el17my | 32:47d98959b4ef | 76 | lcd.printString("A - Controls",0,2); |
el17my | 31:8e92b65e0779 | 77 | lcd.drawSprite(1,25,25,80,(int*)page1_sprite);} |
el17my | 13:30330d61f09c | 78 | |
el17my | 21:349c70c8a7de | 79 | void Menu::display_page2(N5110 &lcd, Gamepad &gamepad) { |
el17my | 13:30330d61f09c | 80 | lcd.printString("METHOD:",0,0); |
el17my | 13:30330d61f09c | 81 | lcd.printString("-Go Left/Right",0,1); |
el17my | 13:30330d61f09c | 82 | lcd.printString("Collect item!",0,4); |
el17my | 31:8e92b65e0779 | 83 | lcd.printString("x -Jump:",0,2); } |
el17my | 13:30330d61f09c | 84 | |
el17my | 21:349c70c8a7de | 85 | void Menu::run_game(N5110 &lcd, Gamepad &gamepad){ |
el17my | 13:30330d61f09c | 86 | _game_engine.run_engine(lcd, gamepad);} |
el17my | 13:30330d61f09c | 87 | |
el17my | 13:30330d61f09c | 88 |