Yang Zhenye 201199680

Dependencies:   mbed

Committer:
yangzhenye
Date:
Thu May 14 15:55:41 2020 +0000
Revision:
6:4abef55fee88
Parent:
5:fcad75e9b9e1
Child:
8:c02c278320c0
el17zy

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yangzhenye 5:fcad75e9b9e1 1 /*
yangzhenye 5:fcad75e9b9e1 2 ELEC2645 Embedded Systems Project
yangzhenye 5:fcad75e9b9e1 3 School of Electronic & Electrical Engineering
yangzhenye 5:fcad75e9b9e1 4 University of Leeds
yangzhenye 5:fcad75e9b9e1 5 2019/20
yangzhenye 5:fcad75e9b9e1 6
yangzhenye 5:fcad75e9b9e1 7 Name:Yang Zhenye
yangzhenye 5:fcad75e9b9e1 8 Username:el17zy
yangzhenye 5:fcad75e9b9e1 9 Student ID Number:201199680
yangzhenye 5:fcad75e9b9e1 10 Date:2020/5/12
yangzhenye 5:fcad75e9b9e1 11 */
yangzhenye 5:fcad75e9b9e1 12
yangzhenye 2:baca89f466bc 13 #include "Menu.h"
yangzhenye 2:baca89f466bc 14
yangzhenye 2:baca89f466bc 15 int _sprite[30][80]= {
yangzhenye 5:fcad75e9b9e1 16 {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},
yangzhenye 5:fcad75e9b9e1 17 {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},
yangzhenye 5:fcad75e9b9e1 18 {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,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enye 5:fcad75e9b9e1 48 State fsm[3] = {
yangzhenye 5:fcad75e9b9e1 49 {0,{0,1,2,0}},
yangzhenye 5:fcad75e9b9e1 50 {1,{1,1,1,0}},
yangzhenye 5:fcad75e9b9e1 51 {2,{2,2,2,0}}
yangzhenye 5:fcad75e9b9e1 52 };
yangzhenye 5:fcad75e9b9e1 53
yangzhenye 5:fcad75e9b9e1 54 Menu::Menu() {}
yangzhenye 5:fcad75e9b9e1 55
yangzhenye 5:fcad75e9b9e1 56 Menu::~Menu() {}
yangzhenye 5:fcad75e9b9e1 57
yangzhenye 2:baca89f466bc 58
yangzhenye 2:baca89f466bc 59 void Menu::init() {
yangzhenye 2:baca89f466bc 60 _state = 0;
yangzhenye 5:fcad75e9b9e1 61 _engine.init(); }
yangzhenye 6:4abef55fee88 62 // starting the menu
yangzhenye 2:baca89f466bc 63
yangzhenye 5:fcad75e9b9e1 64 void Menu::run_engine(N5110 &lcd, Gamepad &gamepad) {
yangzhenye 5:fcad75e9b9e1 65 get_input(gamepad.check_event(Gamepad::START_PRESSED),gamepad.check_event(Gamepad::BACK_PRESSED),gamepad.check_event(Gamepad::X_PRESSED));
yangzhenye 2:baca89f466bc 66 _output = fsm[_state].output;
yangzhenye 2:baca89f466bc 67 _state = fsm[_state].next_state[_input]; }
yangzhenye 2:baca89f466bc 68
yangzhenye 5:fcad75e9b9e1 69 void Menu::get_input(bool start, bool back, bool x) {
yangzhenye 2:baca89f466bc 70 if (!start && !back && !x) {
yangzhenye 2:baca89f466bc 71 _input = 0;}
yangzhenye 2:baca89f466bc 72 else if (start && !back && !x) {
yangzhenye 2:baca89f466bc 73 _input = 1;}
yangzhenye 2:baca89f466bc 74 else if (x && !start && !back) {
yangzhenye 2:baca89f466bc 75 _input = 2;}
yangzhenye 2:baca89f466bc 76 else if (!start && back) {
yangzhenye 2:baca89f466bc 77 _input = 3;} }
yangzhenye 5:fcad75e9b9e1 78
yangzhenye 5:fcad75e9b9e1 79 void Menu::get_output(N5110 &lcd, Gamepad &gamepad) {
yangzhenye 2:baca89f466bc 80 if (_output == 0) {
yangzhenye 5:fcad75e9b9e1 81 display_page1(lcd, gamepad);
yangzhenye 5:fcad75e9b9e1 82 run_engine(lcd, gamepad); }
yangzhenye 5:fcad75e9b9e1 83 else if(_output == 1) {
yangzhenye 5:fcad75e9b9e1 84 display_page2(lcd, gamepad);
yangzhenye 5:fcad75e9b9e1 85 run_engine(lcd, gamepad); }
yangzhenye 5:fcad75e9b9e1 86 else if(_output == 2) {
yangzhenye 5:fcad75e9b9e1 87 display_page3(lcd, gamepad); } }
yangzhenye 6:4abef55fee88 88 //display the three pages
yangzhenye 2:baca89f466bc 89
yangzhenye 2:baca89f466bc 90
yangzhenye 5:fcad75e9b9e1 91 void Menu::display_page1(N5110 &lcd, Gamepad &gamepad) {
yangzhenye 2:baca89f466bc 92 lcd.printString("Start - playgame!",0,4);
yangzhenye 5:fcad75e9b9e1 93 lcd.printString("X - instruction",0,5);
yangzhenye 5:fcad75e9b9e1 94 lcd.drawSprite(1,60,30,80,(int*)_sprite); }
yangzhenye 2:baca89f466bc 95
yangzhenye 5:fcad75e9b9e1 96 void Menu::display_page2(N5110 &lcd, Gamepad &gamepad) {
yangzhenye 5:fcad75e9b9e1 97 lcd.printString("love you Tim!",0,0);
yangzhenye 5:fcad75e9b9e1 98 }
yangzhenye 2:baca89f466bc 99
yangzhenye 5:fcad75e9b9e1 100 void Menu::display_page3(N5110 &lcd, Gamepad &gamepad) {
yangzhenye 2:baca89f466bc 101 lcd.printString("joystick - ",0,1);
yangzhenye 4:eb8dca1dc341 102 lcd.printString("control Rooney - ",0,3);
yangzhenye 2:baca89f466bc 103 lcd.printString("Be a hero! - ",0,4);
yangzhenye 2:baca89f466bc 104 lcd.printString("Save England! - ",0,1); }
yangzhenye 2:baca89f466bc 105
yangzhenye 5:fcad75e9b9e1 106 void Menu::run_game(N5110 &lcd, Gamepad &gamepad){
yangzhenye 5:fcad75e9b9e1 107 _engine.run_engine(lcd, gamepad);}
yangzhenye 5:fcad75e9b9e1 108
yangzhenye 2:baca89f466bc 109
yangzhenye 2:baca89f466bc 110