Mochu Yao explorer game
Dependencies: mbed
Diff: menu/Menu.cpp
- Revision:
- 31:8e92b65e0779
- Parent:
- 30:65e639ace415
- Child:
- 32:47d98959b4ef
--- a/menu/Menu.cpp Wed Apr 29 03:18:13 2020 +0000 +++ b/menu/Menu.cpp Wed Apr 29 04:49:10 2020 +0000 @@ -31,9 +31,9 @@ //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 // State fsm[3] = { - {0,0.5,{0,2,0,0}}, - {1,0.5,{2,2,0,1}}, - {2,0.5,{1,2,1,0}} + {0,{0,2,0,0}}, + {1,{2,2,0,1}}, + {2,{1,2,1,0}} }; Menu::Menu() {} @@ -46,48 +46,41 @@ _game_engine.init(); } void Menu::run_engine(N5110 &lcd, Gamepad &gamepad) { - get_input(gamepad.check_event(Gamepad::START_PRESSED), - gamepad.check_event(Gamepad::BACK_PRESSED), - gamepad.check_event(Gamepad::B_PRESSED)); - _output = fsm[_state].output; - wait(fsm[_state].time); - // implement required delay - // set the next state depending on direction - _state = fsm[_state].next_state[_input_value]; -} - -void Menu::get_output(N5110 &lcd, Gamepad &gamepad) { + get_input(gamepad.check_event(Gamepad::START_PRESSED), gamepad.check_event(Gamepad::BACK_PRESSED),gamepad.check_event(Gamepad::B_PRESSED)); + _output = fsm[_state].output; if (_output == 0) { run_game(lcd, gamepad); // Runs the main game loop. } else if (_output == 1) { display_page1(lcd, gamepad); // Displays the main menu. } else { display_page2(lcd, gamepad); // Displayes the control page. - } - } + } + // implement required delay + // set the next state depending on direction + _state = fsm[_state].next_state[_input_value]; +} void Menu::get_input(bool start, bool back, bool b) { if(!start && !back && !b) { _input_value = 0;} + else if (!start && back) { + _input_value = 1;} else if (start && !back) { _input_value = 2;} - else if (!start && back) { - _input_value = 1;} else if (b) { _input_value = 3;} } void Menu::display_page1(N5110 &lcd, Gamepad &gamepad) { - lcd.printString("START- Play!",0,0); - lcd.printString("B- Controls",0,2); - lcd.drawSprite(1,21,25,80,(int*)page1_sprite);} + lcd.printString("START - Play!",0,0); + lcd.printString("B - Controls",0,2); + lcd.drawSprite(1,25,25,80,(int*)page1_sprite);} void Menu::display_page2(N5110 &lcd, Gamepad &gamepad) { lcd.printString("METHOD:",0,0); lcd.printString("-Go Left/Right",0,1); lcd.printString("Collect item!",0,4); - lcd.printString("x:",0,2); - lcd.printString("-Jump",0,3);} + lcd.printString("x -Jump:",0,2); } void Menu::run_game(N5110 &lcd, Gamepad &gamepad){ _game_engine.run_engine(lcd, gamepad);}