Mochu Yao explorer game

Dependencies:   mbed

Committer:
el17my
Date:
Wed Apr 29 03:18:13 2020 +0000
Revision:
30:65e639ace415
Parent:
22:f8ba0ab7465c
Child:
31:8e92b65e0779
4.29

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17my 22:f8ba0ab7465c 1 #include "Menu.h"
el17my 13:30330d61f09c 2
el17my 13:30330d61f09c 3 int page1_sprite[25][80] = {
el17my 13:30330d61f09c 4 { 0,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,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 },
el17my 13:30330d61f09c 5 { 0,0,0,0,0,1,1,1,0,0,0,1,1,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 },
el17my 13:30330d61f09c 6 { 0,0,0,0,1,1,0,0,1,0,0,0,0,1,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 },
el17my 13:30330d61f09c 7 { 0,0,0,1,1,0,0,1,1,0,0,0,0,0,1,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 },
el17my 13:30330d61f09c 8 { 0,0,1,1,0,0,1,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,1,0,0,0,0,1,0,1,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0 },
el17my 13:30330d61f09c 26 { 0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0 },
el17my 13:30330d61f09c 27 { 0,0,1,1,1,1,0,0,0,1,1,1,1,0,0,0,0,0,1,1,1,1,1,0,1,0,0,0,0,0,1,0,1,0,0,0,0,0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,1,0,1,1,1,1,1,1,0,1,0,0,0,0,0,1,0,0,0,0,0 },
el17my 13:30330d61f09c 28 { 0,1,0,0,0,0,1,1,1,0,0,0,0,1,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 },
el17my 13:30330d61f09c 29 };
el17my 13:30330d61f09c 30 //*using the UPDown counter example in class 201.
el17my 13:30330d61f09c 31 //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
el17my 13:30330d61f09c 32 //
el17my 13:30330d61f09c 33 State fsm[3] = {
el17my 30:65e639ace415 34 {0,0.5,{0,2,0,0}},
el17my 30:65e639ace415 35 {1,0.5,{2,2,0,1}},
el17my 30:65e639ace415 36 {2,0.5,{1,2,1,0}}
el17my 15:814084bbc111 37 };
el17my 13:30330d61f09c 38
el17my 21:349c70c8a7de 39 Menu::Menu() {}
el17my 13:30330d61f09c 40
el17my 21:349c70c8a7de 41 Menu::~Menu() {}
el17my 13:30330d61f09c 42
el17my 21:349c70c8a7de 43 void Menu::init() {
el17my 13:30330d61f09c 44 // Starting setup of menu.
el17my 17:1b4ecc01b79f 45 _state = 1; // Starting state is the menu.
el17my 13:30330d61f09c 46 _game_engine.init(); }
el17my 13:30330d61f09c 47
el17my 21:349c70c8a7de 48 void Menu::run_engine(N5110 &lcd, Gamepad &gamepad) {
el17my 20:20e6ba54e15c 49 get_input(gamepad.check_event(Gamepad::START_PRESSED),
el17my 20:20e6ba54e15c 50 gamepad.check_event(Gamepad::BACK_PRESSED),
el17my 20:20e6ba54e15c 51 gamepad.check_event(Gamepad::B_PRESSED));
el17my 30:65e639ace415 52 _output = fsm[_state].output;
el17my 30:65e639ace415 53 wait(fsm[_state].time);
el17my 13:30330d61f09c 54 // implement required delay
el17my 22:f8ba0ab7465c 55 // set the next state depending on direction
el17my 22:f8ba0ab7465c 56 _state = fsm[_state].next_state[_input_value];
el17my 22:f8ba0ab7465c 57 }
el17my 22:f8ba0ab7465c 58
el17my 22:f8ba0ab7465c 59 void Menu::get_output(N5110 &lcd, Gamepad &gamepad) {
el17my 19:14c5427b30d1 60 if (_output == 0) {
el17my 13:30330d61f09c 61 run_game(lcd, gamepad); // Runs the main game loop.
el17my 13:30330d61f09c 62 } else if (_output == 1) {
el17my 13:30330d61f09c 63 display_page1(lcd, gamepad); // Displays the main menu.
el17my 13:30330d61f09c 64 } else {
el17my 13:30330d61f09c 65 display_page2(lcd, gamepad); // Displayes the control page.
el17my 13:30330d61f09c 66 }
el17my 22:f8ba0ab7465c 67 }
el17my 22:f8ba0ab7465c 68
el17my 21:349c70c8a7de 69 void Menu::get_input(bool start, bool back, bool b) {
el17my 20:20e6ba54e15c 70 if(!start && !back && !b) {
el17my 20:20e6ba54e15c 71 _input_value = 0;}
el17my 20:20e6ba54e15c 72 else if (start && !back) {
el17my 20:20e6ba54e15c 73 _input_value = 2;}
el17my 20:20e6ba54e15c 74 else if (!start && back) {
el17my 20:20e6ba54e15c 75 _input_value = 1;}
el17my 20:20e6ba54e15c 76 else if (b) {
el17my 19:14c5427b30d1 77 _input_value = 3;}
el17my 13:30330d61f09c 78 }
el17my 13:30330d61f09c 79
el17my 21:349c70c8a7de 80 void Menu::display_page1(N5110 &lcd, Gamepad &gamepad) {
el17my 13:30330d61f09c 81 lcd.printString("START- Play!",0,0);
el17my 13:30330d61f09c 82 lcd.printString("B- Controls",0,2);
el17my 20:20e6ba54e15c 83 lcd.drawSprite(1,21,25,80,(int*)page1_sprite);}
el17my 13:30330d61f09c 84
el17my 21:349c70c8a7de 85 void Menu::display_page2(N5110 &lcd, Gamepad &gamepad) {
el17my 13:30330d61f09c 86 lcd.printString("METHOD:",0,0);
el17my 13:30330d61f09c 87 lcd.printString("-Go Left/Right",0,1);
el17my 13:30330d61f09c 88 lcd.printString("Collect item!",0,4);
el17my 13:30330d61f09c 89 lcd.printString("x:",0,2);
el17my 13:30330d61f09c 90 lcd.printString("-Jump",0,3);}
el17my 13:30330d61f09c 91
el17my 21:349c70c8a7de 92 void Menu::run_game(N5110 &lcd, Gamepad &gamepad){
el17my 13:30330d61f09c 93 _game_engine.run_engine(lcd, gamepad);}
el17my 13:30330d61f09c 94
el17my 13:30330d61f09c 95