zhenye yang
/
el17zy
Yang Zhenye 201199680
Menu/Menu.cpp
- Committer:
- yangzhenye
- Date:
- 2020-05-15
- Revision:
- 9:a5a82b3d1102
- Parent:
- 8:c02c278320c0
File content as of revision 9:a5a82b3d1102:
/* ELEC2645 Embedded Systems Project School of Electronic & Electrical Engineering University of Leeds 2019/20 Name:Yang Zhenye Username:el17zy Student ID Number:201199680 Date:2020/5/12 */ #include "Menu.h" int _sprite[30][80]= { {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, {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,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,0,0,0,1,0,1,1,1,1,1,1,0,1,0,0,0,0,1}, {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,0,0,0,0,1,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,1,1,0,0,0,1,0,1,0,0,0,0,0,0,1,0,0,0,0,1}, {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,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0,0,0,0,1,0,0,1,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,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,1,0,1,0,0,1,0,1,0,0,0,0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{1,1,1,0}}, {2,{2,2,2,0}} }; Menu::Menu() {} Menu::~Menu() {} void Menu::init() { _state = 0; _engine.init(); } // starting the menu 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::X_PRESSED)); _output = fsm[_state].output; _state = fsm[_state].next_state[_input]; } void Menu::get_input(bool start, bool back, bool x) { if (!start && !back && !x) { _input = 0;} else if (start && !back && !x) { _input = 1;} else if (x && !start && !back) { _input = 2;} else if (!start && back) { _input = 3;} } void Menu::get_output(N5110 &lcd, Gamepad &gamepad) { if (_output == 0) { run_engine(lcd, gamepad); } else if(_output == 1) { display_page1(lcd, gamepad); // display_page2(lcd, gamepad); // run_engine(lcd, gamepad); } else if(_output == 2) { display_page3(lcd, gamepad); } } //display the three pages void Menu::display_page1(N5110 &lcd, Gamepad &gamepad) { lcd.printString("Start - playgame!",0,4); lcd.printString("X - instruction",0,5); lcd.drawSprite(1,60,30,80,(int*)_sprite); } //void Menu::display_page2(N5110 &lcd, Gamepad &gamepad) { // lcd.printString("It is Rooney turn!",0,0); //} void Menu::display_page3(N5110 &lcd, Gamepad &gamepad) { lcd.printString("joystick - ",0,1); lcd.printString("control Rooney - ",0,3); lcd.printString("Be a hero! - ",0,4); lcd.printString("Save England! - ",0,1); } void Menu::run_game(N5110 &lcd, Gamepad &gamepad){ _engine.run_engine(lcd, gamepad);}