Yang Zhenye 201199680

Dependencies:   mbed

Menu/Menu.cpp

Committer:
yangzhenye
Date:
2020-05-08
Revision:
3:30c81344beff
Parent:
2:baca89f466bc
Child:
4:eb8dca1dc341

File content as of revision 3:30c81344beff:

#include "Menu.h"

int _sprite[30][80]= {
    
    
    
    
    
    
    
    
    
    
    
    
    
void Menu::init() {
     _state = 0;
     engine.init(); }
    
     
void Menu::run(N5110 &lcd, Gamepad &gamepad) {
    input(gamepad.check_event(Gamepad::START_PRESSED,gamepad.check_event(Gamepad::BACK_PRESSED),gamepad.check_event(Gamepad::X_PRESSED))
    _output = fsm[_state].output;
    output();
    _state = fsm[_state].next_state[_input]; }
    
void 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 output() {
  if (_output == 0) {
      display_page1;
      run_engine(lcd, gamepad) }
      else if(_output == 1) {
          display_page2;
          run_engine(); }
          else if(_output == 2) {
              display_page3; } }

State fsm[3] = {
    {0,{0,1,2,0}},
    {1,{1,1,1,0}},
    {2,{2,2,2,0}}
    }
    
display_page1(N5110 &lcd, Gamepad &gamepad) {
   lcd.printString("Start - playgame!",0,4);
   lcd.printSrting("X - instruction",0,5);
   lcd.drawSptire(1,60,30,80,(int*)_sprite); }
   
display_page2(N5110 &lcd, Gamepad &gamepad) {
   lcd.printString("love you Tim!",0,0)
   lcd.refresh; wait(0.5);}
   
display_page3(N5110 &lcd, Gamepad &gamepad) {
   lcd.printString("joystick - ",0,1);
   lcd.printString("control Roony - ",0,3);
   lcd.printString("Be a hero! - ",0,4);
   lcd.printString("Save England! - ",0,1); }