Yang Zhenye 201199680

Dependencies:   mbed

Committer:
yangzhenye
Date:
Fri May 08 09:09:49 2020 +0000
Revision:
3:30c81344beff
Parent:
2:baca89f466bc
Child:
4:eb8dca1dc341
improve project

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yangzhenye 2:baca89f466bc 1 #include "Menu.h"
yangzhenye 2:baca89f466bc 2
yangzhenye 2:baca89f466bc 3 int _sprite[30][80]= {
yangzhenye 2:baca89f466bc 4
yangzhenye 2:baca89f466bc 5
yangzhenye 2:baca89f466bc 6
yangzhenye 2:baca89f466bc 7
yangzhenye 2:baca89f466bc 8
yangzhenye 2:baca89f466bc 9
yangzhenye 2:baca89f466bc 10
yangzhenye 2:baca89f466bc 11
yangzhenye 2:baca89f466bc 12
yangzhenye 2:baca89f466bc 13
yangzhenye 2:baca89f466bc 14
yangzhenye 2:baca89f466bc 15
yangzhenye 2:baca89f466bc 16
yangzhenye 2:baca89f466bc 17 void Menu::init() {
yangzhenye 2:baca89f466bc 18 _state = 0;
yangzhenye 2:baca89f466bc 19 engine.init(); }
yangzhenye 2:baca89f466bc 20
yangzhenye 2:baca89f466bc 21
yangzhenye 2:baca89f466bc 22 void Menu::run(N5110 &lcd, Gamepad &gamepad) {
yangzhenye 2:baca89f466bc 23 input(gamepad.check_event(Gamepad::START_PRESSED,gamepad.check_event(Gamepad::BACK_PRESSED),gamepad.check_event(Gamepad::X_PRESSED))
yangzhenye 2:baca89f466bc 24 _output = fsm[_state].output;
yangzhenye 2:baca89f466bc 25 output();
yangzhenye 2:baca89f466bc 26 _state = fsm[_state].next_state[_input]; }
yangzhenye 2:baca89f466bc 27
yangzhenye 2:baca89f466bc 28 void input(bool start, bool back, bool x) {
yangzhenye 2:baca89f466bc 29 if (!start && !back && !x) {
yangzhenye 2:baca89f466bc 30 _input = 0;}
yangzhenye 2:baca89f466bc 31 else if (start && !back && !x) {
yangzhenye 2:baca89f466bc 32 _input = 1;}
yangzhenye 2:baca89f466bc 33 else if (x && !start && !back) {
yangzhenye 2:baca89f466bc 34 _input = 2;}
yangzhenye 2:baca89f466bc 35 else if (!start && back) {
yangzhenye 2:baca89f466bc 36 _input = 3;} }
yangzhenye 2:baca89f466bc 37 void output() {
yangzhenye 2:baca89f466bc 38 if (_output == 0) {
yangzhenye 3:30c81344beff 39 display_page1;
yangzhenye 3:30c81344beff 40 run_engine(lcd, gamepad) }
yangzhenye 2:baca89f466bc 41 else if(_output == 1) {
yangzhenye 2:baca89f466bc 42 display_page2;
yangzhenye 2:baca89f466bc 43 run_engine(); }
yangzhenye 2:baca89f466bc 44 else if(_output == 2) {
yangzhenye 2:baca89f466bc 45 display_page3; } }
yangzhenye 2:baca89f466bc 46
yangzhenye 2:baca89f466bc 47 State fsm[3] = {
yangzhenye 2:baca89f466bc 48 {0,{0,1,2,0}},
yangzhenye 2:baca89f466bc 49 {1,{1,1,1,0}},
yangzhenye 2:baca89f466bc 50 {2,{2,2,2,0}}
yangzhenye 2:baca89f466bc 51 }
yangzhenye 2:baca89f466bc 52
yangzhenye 2:baca89f466bc 53 display_page1(N5110 &lcd, Gamepad &gamepad) {
yangzhenye 2:baca89f466bc 54 lcd.printString("Start - playgame!",0,4);
yangzhenye 2:baca89f466bc 55 lcd.printSrting("X - instruction",0,5);
yangzhenye 2:baca89f466bc 56 lcd.drawSptire(1,60,30,80,(int*)_sprite); }
yangzhenye 2:baca89f466bc 57
yangzhenye 2:baca89f466bc 58 display_page2(N5110 &lcd, Gamepad &gamepad) {
yangzhenye 2:baca89f466bc 59 lcd.printString("love you Tim!",0,0)
yangzhenye 2:baca89f466bc 60 lcd.refresh; wait(0.5);}
yangzhenye 2:baca89f466bc 61
yangzhenye 2:baca89f466bc 62 display_page3(N5110 &lcd, Gamepad &gamepad) {
yangzhenye 2:baca89f466bc 63 lcd.printString("joystick - ",0,1);
yangzhenye 2:baca89f466bc 64 lcd.printString("control Roony - ",0,3);
yangzhenye 2:baca89f466bc 65 lcd.printString("Be a hero! - ",0,4);
yangzhenye 2:baca89f466bc 66 lcd.printString("Save England! - ",0,1); }
yangzhenye 2:baca89f466bc 67
yangzhenye 2:baca89f466bc 68
yangzhenye 2:baca89f466bc 69