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.
Diff: Pause/Pause.cpp
- Revision:
- 20:4a39a1a2be51
- Child:
- 21:9d1447765ee1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Pause/Pause.cpp Wed Apr 17 14:34:08 2019 +0000 @@ -0,0 +1,75 @@ +#include "Pause.h" + +void Pause::init(){ + _state = RESUME; +} + +int Pause::pause_menu(Gamepad &gamepad, N5110 &lcd, int fps, int frame){ + PauseOption choice = RESUME; + while(!(gamepad.check_event(gamepad.A_PRESSED))){ + lcd.clear(); + display_pause_options(lcd); + choice = pause_selection(gamepad, lcd); + lcd.refresh(); + wait(0.2); + } + int jump_to_frame = frame; + if(choice == RESUME){ jump_to_frame = frame; } //Just keep code iterating + if(choice == RESTART){ jump_to_frame = 0; } //return to frame 1 if restarted + if(choice == QUIT){ jump_to_frame = 45*fps; } //jump to final frame + if(choice == HELP){ brickbreaker_help(gamepad, lcd); } //help screen + return jump_to_frame; +} + +void Pause::display_pause_options(N5110 &lcd){ + lcd.printString("GAME PAUSED:", 6, 0); + lcd.printString("Resume", 24, 1); + lcd.printString("Restart", 21, 2); + lcd.printString("Quit", 30, 3); + lcd.printString("Help", 30, 4); + lcd.printString("(Select = A)", 6, 5); +} + +PauseOption Pause::pause_selection(Gamepad &gamepad, N5110 &lcd){ + PauseSelection fsm[4] = { + {1,{HELP,RESTART,RESUME}}, + {2,{RESUME,QUIT,RESTART}}, + {3,{RESTART,HELP,QUIT}}, + {4,{QUIT,RESUME,HELP}} + }; + if(gamepad.get_direction() == N){ _next_state = 0;} + else if(gamepad.get_direction() == S){ _next_state = 1;} + else{ _next_state = 2;} + _state = fsm[_state].next_state[_next_state]; + lcd.printString(">", 6, fsm[_state].output); + lcd.printString("<", 72, fsm[_state].output); + return _state; +} + +void Pause::brickbreaker_help(Gamepad &gamepad, N5110 &lcd){ + while(!(gamepad.check_event(gamepad.A_PRESSED))){ + lcd.clear(); + lcd.printString("Help", 30, 0); + lcd.printString("Tilt gamepad", 0, 1); + lcd.printString("to move ball", 0, 2); + lcd.printString("Game length=", 0, 3); + lcd.printString("45 secs", 0, 4); + lcd.printString("A = go back", 0, 5); + lcd.refresh(); + wait(0.5); + } +} + +void Pause::classic_help(Gamepad &gamepad, N5110 &lcd){ + while(!(gamepad.check_event(gamepad.A_PRESSED))){ + lcd.clear(); + lcd.printString("Help", 30, 0); + lcd.printString("Don't leave", 0, 1); + lcd.printString("the path! Tilt", 0, 2); + lcd.printString("pad to roll", 0, 3); + lcd.printString("the ball", 0, 4); + lcd.printString("A = go back", 0, 5); + lcd.refresh(); + wait(0.5); + } +} \ No newline at end of file