![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Mochu Yao explorer game
Dependencies: mbed
Diff: menu/menu.cpp
- Revision:
- 20:20e6ba54e15c
- Parent:
- 19:14c5427b30d1
--- a/menu/menu.cpp Tue Apr 28 13:37:26 2020 +0000 +++ b/menu/menu.cpp Tue Apr 28 14:13:36 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,12 +46,11 @@ _game_engine.init(); } void menu::run_engine(N5110 &lcd, Gamepad &gamepad) { - START_flag = gamepad.check_event(Gamepad::START_PRESSED); - BACK_flag = gamepad.check_event(Gamepad::BACK_PRESSED); - B_flag = gamepad.check_event(Gamepad::B_PRESSED); + get_input(gamepad.check_event(Gamepad::START_PRESSED), + gamepad.check_event(Gamepad::BACK_PRESSED), + gamepad.check_event(Gamepad::B_PRESSED)); _output = fsm[_state].output; // implement required delay - wait(fsm[_state].time); if (_output == 0) { run_game(lcd, gamepad); // Runs the main game loop. } else if (_output == 1) { @@ -63,26 +62,21 @@ _state = fsm[_state].next_state[_input_value]; } -void menu::get_input_value(Gamepad &gamepad) { - if(!START_flag && !BACK_flag && !B_flag) { - _input_value = 0; - gamepad.tone(200, 0.5);} - else if (START_flag && !BACK_flag) { - _input_value = 2; - gamepad.tone(400, 0.5);} - else if (!START_flag && BACK_flag) { - _input_value = 1 - gamepad.tone(600, 0.5);} - else if (B_flag) { +void menu::get_input(bool start, bool back, bool b) { + if(!start && !back && !b) { + _input_value = 0;} + 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.drawLine(0,0,84,0,FILL_BLACK); - lcd.drawLine(0,26,84,26,FILL_BLACK); lcd.printString("START- Play!",0,0); lcd.printString("B- Controls",0,2); - lcd.drawSprite(1,27,25,80,(int*)page1_sprite);} + lcd.drawSprite(1,21,25,80,(int*)page1_sprite);} void menu::display_page2(N5110 &lcd, Gamepad &gamepad) { lcd.printString("METHOD:",0,0);