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.
Pause/Pause.cpp@38:a85bc227b907, 2019-05-09 (annotated)
- Committer:
- JamesCummins
- Date:
- Thu May 09 01:09:18 2019 +0000
- Revision:
- 38:a85bc227b907
- Parent:
- 36:9f7463a65fe0
Doxygen documentation written out and in line commenting completed. Game working and finished. Tests.h still to write out
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JamesCummins | 20:4a39a1a2be51 | 1 | #include "Pause.h" |
JamesCummins | 20:4a39a1a2be51 | 2 | |
JamesCummins | 38:a85bc227b907 | 3 | //constructor |
JamesCummins | 22:4e305ff8a050 | 4 | Pause::Pause(){ |
JamesCummins | 22:4e305ff8a050 | 5 | } |
JamesCummins | 22:4e305ff8a050 | 6 | |
JamesCummins | 38:a85bc227b907 | 7 | //destructor |
JamesCummins | 22:4e305ff8a050 | 8 | Pause::~Pause(){ |
JamesCummins | 22:4e305ff8a050 | 9 | } |
JamesCummins | 22:4e305ff8a050 | 10 | |
JamesCummins | 38:a85bc227b907 | 11 | ////initialiser |
JamesCummins | 20:4a39a1a2be51 | 12 | void Pause::init(){ |
JamesCummins | 38:a85bc227b907 | 13 | _state = RESUME; //set arrows to point to first item in the menu |
JamesCummins | 20:4a39a1a2be51 | 14 | } |
JamesCummins | 20:4a39a1a2be51 | 15 | |
JamesCummins | 29:42651f87522b | 16 | PauseOption Pause::pause_menu(Gamepad &gamepad, N5110 &lcd, int fps){ |
JamesCummins | 38:a85bc227b907 | 17 | PauseOption choice = RESUME; //choice stores the state to be selected and pointed to with arrows |
JamesCummins | 38:a85bc227b907 | 18 | while(!(gamepad.check_event(gamepad.A_PRESSED))){ //check for user selection |
JamesCummins | 20:4a39a1a2be51 | 19 | lcd.clear(); |
JamesCummins | 38:a85bc227b907 | 20 | display_pause_options(lcd); //render the menu on the screen |
JamesCummins | 38:a85bc227b907 | 21 | choice = pause_selection(gamepad, lcd); //update currently selected choice and point to it with arrows |
JamesCummins | 20:4a39a1a2be51 | 22 | lcd.refresh(); |
JamesCummins | 38:a85bc227b907 | 23 | wait(0.2); //avoid button bounce as much as poss |
JamesCummins | 20:4a39a1a2be51 | 24 | } |
JamesCummins | 29:42651f87522b | 25 | return choice; |
JamesCummins | 29:42651f87522b | 26 | } |
JamesCummins | 29:42651f87522b | 27 | |
JamesCummins | 29:42651f87522b | 28 | |
JamesCummins | 29:42651f87522b | 29 | |
JamesCummins | 29:42651f87522b | 30 | int Pause::brickbreaker_action(PauseOption choice, Gamepad &gamepad, N5110 &lcd, int frame, int fps){ |
JamesCummins | 20:4a39a1a2be51 | 31 | int jump_to_frame = frame; |
JamesCummins | 38:a85bc227b907 | 32 | if(choice == RESUME){ jump_to_frame = frame; } //Just keep code iterating |
JamesCummins | 38:a85bc227b907 | 33 | if(choice == RESTART){ jump_to_frame = 0; } //return to frame 1 if restarted |
JamesCummins | 38:a85bc227b907 | 34 | if(choice == QUIT){ jump_to_frame = 45*fps; } //jump to final frame |
JamesCummins | 38:a85bc227b907 | 35 | if(choice == HELP){ brickbreaker_help(gamepad, lcd); } //display relevant help screen |
JamesCummins | 38:a85bc227b907 | 36 | return jump_to_frame; |
JamesCummins | 20:4a39a1a2be51 | 37 | } |
JamesCummins | 20:4a39a1a2be51 | 38 | |
JamesCummins | 29:42651f87522b | 39 | |
JamesCummins | 20:4a39a1a2be51 | 40 | void Pause::display_pause_options(N5110 &lcd){ |
JamesCummins | 38:a85bc227b907 | 41 | lcd.printString("GAME PAUSED:", 6, 0); //text for each line of the display |
JamesCummins | 20:4a39a1a2be51 | 42 | lcd.printString("Resume", 24, 1); |
JamesCummins | 20:4a39a1a2be51 | 43 | lcd.printString("Restart", 21, 2); |
JamesCummins | 20:4a39a1a2be51 | 44 | lcd.printString("Quit", 30, 3); |
JamesCummins | 20:4a39a1a2be51 | 45 | lcd.printString("Help", 30, 4); |
JamesCummins | 20:4a39a1a2be51 | 46 | lcd.printString("(Select = A)", 6, 5); |
JamesCummins | 20:4a39a1a2be51 | 47 | } |
JamesCummins | 20:4a39a1a2be51 | 48 | |
JamesCummins | 20:4a39a1a2be51 | 49 | PauseOption Pause::pause_selection(Gamepad &gamepad, N5110 &lcd){ |
JamesCummins | 38:a85bc227b907 | 50 | PauseSelection fsm[4] = { //state machine to power the pause menu |
JamesCummins | 38:a85bc227b907 | 51 | {1,{HELP,RESTART,RESUME}}, //output (1,2,3 or 4) is the line to print the arrows on |
JamesCummins | 38:a85bc227b907 | 52 | {2,{RESUME,QUIT,RESTART}}, //next_state[0] is the option above the current item |
JamesCummins | 38:a85bc227b907 | 53 | {3,{RESTART,HELP,QUIT}}, //next_state[1] is the option below the current item |
JamesCummins | 38:a85bc227b907 | 54 | {4,{QUIT,RESUME,HELP}} //next_state[2] is the current item/state |
JamesCummins | 20:4a39a1a2be51 | 55 | }; |
JamesCummins | 38:a85bc227b907 | 56 | if(gamepad.get_direction() == N){ _next_state = 0;} //move up |
JamesCummins | 38:a85bc227b907 | 57 | else if(gamepad.get_direction() == S){ _next_state = 1;} //move down |
JamesCummins | 38:a85bc227b907 | 58 | else{ _next_state = 2;} //arrows in same position (default) |
JamesCummins | 38:a85bc227b907 | 59 | _state = fsm[_state].next_state[_next_state]; //update state |
JamesCummins | 38:a85bc227b907 | 60 | lcd.printString(">", 6, fsm[_state].output); //print arrows to LCD display |
JamesCummins | 20:4a39a1a2be51 | 61 | lcd.printString("<", 72, fsm[_state].output); |
JamesCummins | 20:4a39a1a2be51 | 62 | return _state; |
JamesCummins | 20:4a39a1a2be51 | 63 | } |
JamesCummins | 20:4a39a1a2be51 | 64 | |
JamesCummins | 29:42651f87522b | 65 | void Pause::classic_help(Gamepad &gamepad, N5110 &lcd){ |
JamesCummins | 38:a85bc227b907 | 66 | while(!(gamepad.check_event(gamepad.A_PRESSED))){ //check for user advancing |
JamesCummins | 29:42651f87522b | 67 | lcd.clear(); |
JamesCummins | 38:a85bc227b907 | 68 | lcd.printString("Help", 30, 0); //display each line of help |
JamesCummins | 38:a85bc227b907 | 69 | lcd.printString("Don't leave", 0, 1); //on LCD display |
JamesCummins | 29:42651f87522b | 70 | lcd.printString("the path! Tilt", 0, 2); |
JamesCummins | 29:42651f87522b | 71 | lcd.printString("pad to roll", 0, 3); |
JamesCummins | 29:42651f87522b | 72 | lcd.printString("the ball", 0, 4); |
JamesCummins | 36:9f7463a65fe0 | 73 | lcd.printString("(Press A)", 0, 5); |
JamesCummins | 29:42651f87522b | 74 | lcd.refresh(); |
JamesCummins | 29:42651f87522b | 75 | wait(0.5); |
JamesCummins | 29:42651f87522b | 76 | } |
JamesCummins | 29:42651f87522b | 77 | } |
JamesCummins | 29:42651f87522b | 78 | |
JamesCummins | 20:4a39a1a2be51 | 79 | void Pause::brickbreaker_help(Gamepad &gamepad, N5110 &lcd){ |
JamesCummins | 38:a85bc227b907 | 80 | while(!(gamepad.check_event(gamepad.A_PRESSED))){ //check for user advancing |
JamesCummins | 20:4a39a1a2be51 | 81 | lcd.clear(); |
JamesCummins | 38:a85bc227b907 | 82 | lcd.printString("Help", 30, 0); //display each line of help |
JamesCummins | 38:a85bc227b907 | 83 | lcd.printString("Tilt gamepad", 0, 1); //on LCD display |
JamesCummins | 20:4a39a1a2be51 | 84 | lcd.printString("to move ball", 0, 2); |
JamesCummins | 20:4a39a1a2be51 | 85 | lcd.printString("Game length=", 0, 3); |
JamesCummins | 20:4a39a1a2be51 | 86 | lcd.printString("45 secs", 0, 4); |
JamesCummins | 36:9f7463a65fe0 | 87 | lcd.printString("(Press A)", 0, 5); |
JamesCummins | 20:4a39a1a2be51 | 88 | lcd.refresh(); |
JamesCummins | 20:4a39a1a2be51 | 89 | wait(0.5); |
JamesCummins | 20:4a39a1a2be51 | 90 | } |
JamesCummins | 20:4a39a1a2be51 | 91 | } |