Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: Menu/Menu.cpp
- Revision:
- 2:7fa08670b1fc
- Child:
- 4:17d5b53b8815
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Menu/Menu.cpp Tue May 26 16:26:12 2020 +0000 @@ -0,0 +1,201 @@ +#include "Menu.h" +#include "mbed.h" +#include "Gamepad.h" +#include "N5110.h" + +int snake[28][26] { //design of snake on initial page + { 0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, + { 0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }, + { 0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0 }, + { 0,0,1,0,1,0,0,0,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0 }, + { 0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 }, + { 0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 }, + { 0,0,0,0,1,1,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,1,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0 }, + { 0,0,0,0,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,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,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,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,1,0,0,0,0,0,1,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,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0 }, +}; + +int selector[5][7] { + { 0,0,0,0,1,0,0 }, + { 0,0,0,0,1,1,0 }, + { 1,1,1,1,1,1,1 }, + { 0,0,0,0,1,1,0 }, + { 0,0,0,0,1,0,0 }, +}; + + +Menu::Menu(N5110 &lcd,Gamepad &pad) +{ + _lcd = lcd; + _pad = pad; +}; + +void Menu::initscreen() +{ + while( _pad.start_held() == false) { + _lcd.clear(); + _lcd.drawSprite(29,1,28,26,(int*)snake); //initial page + _lcd.printString("SNAKE",WIDTH/2-15,4); + _lcd.printString("Press Start",WIDTH/2-30,5); + _lcd.setContrast( _pad.read_pot1()); + _lcd.refresh(); + wait(1/6); + } + _lcd.clear(); +} + +void Menu::menu_screen() +{ + while(_pad.A_held() == false) { //unitl A is pressed, the code + arrow(); //stays on the meun, + _lcd.refresh(); //executing only the code of the arrow + wait(1/6); + } + + /*if (_lcd.getPixel(20,27)) { //if A is pressed and the arrow + movement(); //is corresponding to PLAY, + draw(); //the code executes game, movement, draw functions + _lcd.refresh(); + wait(1/6); + }*/ + if (_lcd.getPixel(20,35)) { //if A is pressed and the arrow + help(); //is corresponding to HELP, + _lcd.refresh(); //the code executes help function + wait(1/6); + } + _lcd.refresh(); +} + +void Menu::arrow() +{ + _lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT); //main menu design + _lcd.printString("MENU",WIDTH/2-15,1); + _lcd.printString("Play",WIDTH/2-13,3); + _lcd.printString("Help",WIDTH/2-13,4); + //_lcd.drawSprite(WIDTH/2-26,25,5,7,(int*)selector); + _lcd.refresh(); + wait(1/6); + + if ( _pad.X_held() == true) { //position of arrow in the meun + _lcd.clear(); //according to what button is pressed + _lcd.drawSprite(WIDTH/2-26,25,5,7,(int*)selector); + _lcd.refresh(); + wait(1/6); + } + + if ( _pad.B_held() == true) { //position of arrow in the meun + _lcd.clear(); //according to what button is pressed + _lcd.drawSprite(WIDTH/2-26,33,5,7,(int*)selector); + _lcd.refresh(); + wait(1/6); + } +} + +void Menu::help() +{ + while(1) { + _lcd.clear(); //help instructions, page 1 + _lcd.printString("Use the",21,0); + _lcd.printString("buttons",21,1); + _lcd.printString("to move",21,2); + _lcd.printString("(press B)",15,5); + _lcd.refresh(); + wait(1/6); + if (_pad.B_held()) { + break; + } + } + wait(0.2); + + while(1) { + _lcd.clear(); //help instructions, page 2 + _lcd.printString("Eat the fruit",5,0); + _lcd.printString("to score",15,1); + _lcd.printString("(press B)",16,5); + _lcd.refresh(); + wait(1/6); + + if (_pad.B_held()) { + break; + } + } + wait(0.2); + + while(1) { + _lcd.clear(); //help instructions, page 3 + _lcd.printString("If you hit",13,0); + _lcd.printString("a wall",23,1); + _lcd.printString("or your tail",5,2); + _lcd.printString("...",WIDTH/2-7,3); + _lcd.printString("(press B)",16,5); + _lcd.refresh(); + wait(1/6); + + if (_pad.B_held()) { + break; + } + } + wait(0.2); + + while(1) { + _lcd.clear(); //help instructions, final page + _lcd.printString("YOU DIE!",20,1); + _lcd.drawSprite(30,16,23,23,(int*)skull); + _lcd.refresh(); + wait(1/6); + + if (_pad.B_held()) { + break; + } + } + wait(1/6); + _lcd.clear(); + menu_screen(); //after help instructions, returns to main menu + _lcd.refresh(); + wait(1/6); +} \ No newline at end of file