Mochu Yao explorer game

Dependencies:   mbed

Committer:
el17my
Date:
Tue Apr 28 14:26:47 2020 +0000
Revision:
21:349c70c8a7de
Parent:
menu/menu.cpp@20:20e6ba54e15c
Child:
22:f8ba0ab7465c
4.28

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17my 13:30330d61f09c 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,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0,1,0,0,0,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 20:20e6ba54e15c 34 {0,{0,2,0,0}},
el17my 20:20e6ba54e15c 35 {1,{2,2,0,1}},
el17my 20:20e6ba54e15c 36 {2,{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 13:30330d61f09c 52 _output = fsm[_state].output;
el17my 13:30330d61f09c 53 // implement required delay
el17my 19:14c5427b30d1 54 if (_output == 0) {
el17my 13:30330d61f09c 55 run_game(lcd, gamepad); // Runs the main game loop.
el17my 13:30330d61f09c 56 } else if (_output == 1) {
el17my 13:30330d61f09c 57 display_page1(lcd, gamepad); // Displays the main menu.
el17my 13:30330d61f09c 58 } else {
el17my 13:30330d61f09c 59 display_page2(lcd, gamepad); // Displayes the control page.
el17my 13:30330d61f09c 60 }
el17my 19:14c5427b30d1 61 // set the next state depending on direction
el17my 19:14c5427b30d1 62 _state = fsm[_state].next_state[_input_value];
el17my 13:30330d61f09c 63 }
el17my 13:30330d61f09c 64
el17my 21:349c70c8a7de 65 void Menu::get_input(bool start, bool back, bool b) {
el17my 20:20e6ba54e15c 66 if(!start && !back && !b) {
el17my 20:20e6ba54e15c 67 _input_value = 0;}
el17my 20:20e6ba54e15c 68 else if (start && !back) {
el17my 20:20e6ba54e15c 69 _input_value = 2;}
el17my 20:20e6ba54e15c 70 else if (!start && back) {
el17my 20:20e6ba54e15c 71 _input_value = 1;}
el17my 20:20e6ba54e15c 72 else if (b) {
el17my 19:14c5427b30d1 73 _input_value = 3;}
el17my 13:30330d61f09c 74 }
el17my 13:30330d61f09c 75
el17my 21:349c70c8a7de 76 void Menu::display_page1(N5110 &lcd, Gamepad &gamepad) {
el17my 13:30330d61f09c 77 lcd.printString("START- Play!",0,0);
el17my 13:30330d61f09c 78 lcd.printString("B- Controls",0,2);
el17my 20:20e6ba54e15c 79 lcd.drawSprite(1,21,25,80,(int*)page1_sprite);}
el17my 13:30330d61f09c 80
el17my 21:349c70c8a7de 81 void Menu::display_page2(N5110 &lcd, Gamepad &gamepad) {
el17my 13:30330d61f09c 82 lcd.printString("METHOD:",0,0);
el17my 13:30330d61f09c 83 lcd.printString("-Go Left/Right",0,1);
el17my 13:30330d61f09c 84 lcd.printString("Collect item!",0,4);
el17my 13:30330d61f09c 85 lcd.printString("x:",0,2);
el17my 13:30330d61f09c 86 lcd.printString("-Jump",0,3);}
el17my 13:30330d61f09c 87
el17my 21:349c70c8a7de 88 void Menu::run_game(N5110 &lcd, Gamepad &gamepad){
el17my 13:30330d61f09c 89 _game_engine.run_engine(lcd, gamepad);}
el17my 13:30330d61f09c 90
el17my 13:30330d61f09c 91