Mochu Yao explorer game

Dependencies:   mbed

Committer:
el17my
Date:
Tue Apr 28 12:50:40 2020 +0000
Revision:
17:1b4ecc01b79f
Parent:
15:814084bbc111
Child:
19:14c5427b30d1
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,0,0,0,0,0,0,0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,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 13:30330d61f09c 34 {0,0.5,{0,2,0,0}},
el17my 13:30330d61f09c 35 {1,0.5,{2,2,0,1}},
el17my 15:814084bbc111 36 {2,0.5,{1,2,1,0}}
el17my 15:814084bbc111 37 };
el17my 13:30330d61f09c 38
el17my 13:30330d61f09c 39 menu::menu() {}
el17my 13:30330d61f09c 40
el17my 13:30330d61f09c 41 menu::~menu() {}
el17my 13:30330d61f09c 42
el17my 13:30330d61f09c 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 13:30330d61f09c 48 void menu::run_engine(N5110 &lcd, Gamepad &gamepad) {
el17my 13:30330d61f09c 49 START_flag = gamepad.check_event(Gamepad::START_PRESSED);
el17my 15:814084bbc111 50 BACK_flag = gamepad.check_event(Gamepad::BACK_PRESSED);
el17my 13:30330d61f09c 51 B_flag = gamepad.check_event(Gamepad::B_PRESSED);
el17my 13:30330d61f09c 52 _output = fsm[_state].output;
el17my 13:30330d61f09c 53 // implement required delay
el17my 13:30330d61f09c 54 wait(fsm[_state].time);
el17my 13:30330d61f09c 55 // set the next state depending on direction
el17my 13:30330d61f09c 56 _state = fsm[_state].next_state[_input_value];
el17my 13:30330d61f09c 57 if (_output == 0) {
el17my 13:30330d61f09c 58 run_game(lcd, gamepad); // Runs the main game loop.
el17my 13:30330d61f09c 59 } else if (_output == 1) {
el17my 13:30330d61f09c 60 display_page1(lcd, gamepad); // Displays the main menu.
el17my 13:30330d61f09c 61 } else {
el17my 13:30330d61f09c 62 display_page2(lcd, gamepad); // Displayes the control page.
el17my 13:30330d61f09c 63 }
el17my 13:30330d61f09c 64 }
el17my 13:30330d61f09c 65
el17my 15:814084bbc111 66 void menu::get_input_value(Gamepad &gamepad) {
el17my 13:30330d61f09c 67 if(!START_flag && !BACK_flag && !B_flag) {
el17my 15:814084bbc111 68 _input_value = 0;
el17my 15:814084bbc111 69 gamepad.tone(200, 0.5);}
el17my 15:814084bbc111 70 else if (START_flag && !BACK_flag && !B_flag) {
el17my 15:814084bbc111 71 _input_value = 1;
el17my 15:814084bbc111 72 gamepad.tone(400, 0.5);}
el17my 15:814084bbc111 73 else if (!START_flag && BACK_flag && !B_flag) {
el17my 15:814084bbc111 74 _input_value = 2;
el17my 15:814084bbc111 75 gamepad.tone(600, 0.5);}
el17my 15:814084bbc111 76 else if (!START_flag && !BACK_flag && B_flag) {
el17my 13:30330d61f09c 77 _input_value = 3;}
el17my 13:30330d61f09c 78 }
el17my 13:30330d61f09c 79
el17my 15:814084bbc111 80 void menu::display_page1(N5110 &lcd, Gamepad &gamepad) {
el17my 13:30330d61f09c 81 lcd.drawLine(0,0,84,0,FILL_BLACK);
el17my 13:30330d61f09c 82 lcd.drawLine(0,26,84,26,FILL_BLACK);
el17my 13:30330d61f09c 83 lcd.printString("START- Play!",0,0);
el17my 13:30330d61f09c 84 lcd.printString("B- Controls",0,2);
el17my 15:814084bbc111 85 lcd.drawSprite(1,27,25,80,(int*)page1_sprite);}
el17my 13:30330d61f09c 86
el17my 13:30330d61f09c 87 void menu::display_page2(N5110 &lcd, Gamepad &gamepad) {
el17my 13:30330d61f09c 88 lcd.printString("METHOD:",0,0);
el17my 13:30330d61f09c 89 lcd.printString("-Go Left/Right",0,1);
el17my 13:30330d61f09c 90 lcd.printString("Collect item!",0,4);
el17my 13:30330d61f09c 91 lcd.printString("x:",0,2);
el17my 13:30330d61f09c 92 lcd.printString("-Jump",0,3);}
el17my 13:30330d61f09c 93
el17my 13:30330d61f09c 94 void menu::run_game(N5110 &lcd, Gamepad &gamepad){
el17my 13:30330d61f09c 95 _game_engine.run_engine(lcd, gamepad);}
el17my 13:30330d61f09c 96
el17my 13:30330d61f09c 97