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
Menu/Menu.cpp
- Committer:
- ale_carb0ni
- Date:
- 2020-05-26
- Revision:
- 6:a2c72def99f9
- Parent:
- 4:17d5b53b8815
- Child:
- 7:8d381315f72c
File content as of revision 6:a2c72def99f9:
#include "Menu.h" #include "mbed.h" #include "Gamepad.h" #include "N5110.h" //design of snake on initial page int snake[28][26] { { 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,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0 }, { 0,0,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,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() { wait(0.1); _lcd.drawSprite(WIDTH/2-26,25,5,7,(int*)selector); _lcd.refresh(); while(_pad.A_held() == false) { //unitl A is pressed, the code arrow(); //stays on the menu, _lcd.refresh(); //executing only the code of the arrow 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); } } 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.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); }