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.h@38:a85bc227b907, 2019-05-09 (annotated)
- Committer:
- JamesCummins
- Date:
- Thu May 09 01:09:18 2019 +0000
- Revision:
- 38:a85bc227b907
- Parent:
- 37:de1f584bce71
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 | #ifndef PAUSE_H |
JamesCummins | 20:4a39a1a2be51 | 2 | #define PAUSE_H |
JamesCummins | 20:4a39a1a2be51 | 3 | |
JamesCummins | 20:4a39a1a2be51 | 4 | #include "mbed.h" |
JamesCummins | 20:4a39a1a2be51 | 5 | #include "Gamepad.h" |
JamesCummins | 29:42651f87522b | 6 | #include "ClassicEngine.h" |
JamesCummins | 20:4a39a1a2be51 | 7 | #include "N5110.h" |
JamesCummins | 20:4a39a1a2be51 | 8 | |
JamesCummins | 37:de1f584bce71 | 9 | /** Enum for game mode*/ |
JamesCummins | 20:4a39a1a2be51 | 10 | enum Mode{ |
JamesCummins | 37:de1f584bce71 | 11 | CLASSIC_MODE, |
JamesCummins | 21:9d1447765ee1 | 12 | BRICKBREAKER_MODE |
JamesCummins | 20:4a39a1a2be51 | 13 | }; |
JamesCummins | 37:de1f584bce71 | 14 | |
JamesCummins | 37:de1f584bce71 | 15 | /** Enum for Pause Options*/ |
JamesCummins | 20:4a39a1a2be51 | 16 | enum PauseOption{ |
JamesCummins | 20:4a39a1a2be51 | 17 | RESUME, |
JamesCummins | 20:4a39a1a2be51 | 18 | RESTART, |
JamesCummins | 20:4a39a1a2be51 | 19 | QUIT, |
JamesCummins | 20:4a39a1a2be51 | 20 | HELP |
JamesCummins | 20:4a39a1a2be51 | 21 | }; |
JamesCummins | 20:4a39a1a2be51 | 22 | |
JamesCummins | 37:de1f584bce71 | 23 | /**Pause selection struct*/ |
JamesCummins | 20:4a39a1a2be51 | 24 | struct PauseSelection{ |
JamesCummins | 37:de1f584bce71 | 25 | int output; /**<Integer output for line to print arrows*/ |
JamesCummins | 37:de1f584bce71 | 26 | PauseOption next_state[3]; /**<Array of enums for possible next option*/ |
JamesCummins | 20:4a39a1a2be51 | 27 | }; |
JamesCummins | 20:4a39a1a2be51 | 28 | |
JamesCummins | 38:a85bc227b907 | 29 | /** Pause Class |
JamesCummins | 38:a85bc227b907 | 30 | @brief Library to power the pause menu |
JamesCummins | 38:a85bc227b907 | 31 | @brief Can pass frame values to control the flow of the game modes they're |
JamesCummins | 38:a85bc227b907 | 32 | @brief utilised in, enabling features like restarting and quitting |
JamesCummins | 38:a85bc227b907 | 33 | |
JamesCummins | 38:a85bc227b907 | 34 | @author James Cummins |
JamesCummins | 38:a85bc227b907 | 35 | |
JamesCummins | 38:a85bc227b907 | 36 | @code |
JamesCummins | 38:a85bc227b907 | 37 | |
JamesCummins | 38:a85bc227b907 | 38 | #include "mbed.h" |
JamesCummins | 38:a85bc227b907 | 39 | #include "Pause.h" |
JamesCummins | 38:a85bc227b907 | 40 | |
JamesCummins | 38:a85bc227b907 | 41 | Pause pause; //create a pause object for the pause menu |
JamesCummins | 38:a85bc227b907 | 42 | Gamepad gamepad; |
JamesCummins | 38:a85bc227b907 | 43 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
JamesCummins | 38:a85bc227b907 | 44 | |
JamesCummins | 38:a85bc227b907 | 45 | int main(){ |
JamesCummins | 38:a85bc227b907 | 46 | //first initialise the pause menu so it points to top item first |
JamesCummins | 38:a85bc227b907 | 47 | pause.init(); |
JamesCummins | 38:a85bc227b907 | 48 | int game_length = 90; //desired game mode length in seconds |
JamesCummins | 38:a85bc227b907 | 49 | int fps = 30; //frames per sec of the game mode |
JamesCummins | 38:a85bc227b907 | 50 | |
JamesCummins | 38:a85bc227b907 | 51 | //use either one or the other of these (for the correct game mode) |
JamesCummins | 38:a85bc227b907 | 52 | //to display instructions before the game commences |
JamesCummins | 38:a85bc227b907 | 53 | pause.brickbreaker_help(gamepad, lcd); |
JamesCummins | 38:a85bc227b907 | 54 | pause.classic_help(gamepad, lcd); |
JamesCummins | 38:a85bc227b907 | 55 | |
JamesCummins | 38:a85bc227b907 | 56 | for(int i = 0; i < game_length*fps; i++){ |
JamesCummins | 38:a85bc227b907 | 57 | // |
JamesCummins | 38:a85bc227b907 | 58 | // |
JamesCummins | 38:a85bc227b907 | 59 | //code to operate a time based game mode |
JamesCummins | 38:a85bc227b907 | 60 | // |
JamesCummins | 38:a85bc227b907 | 61 | // |
JamesCummins | 38:a85bc227b907 | 62 | |
JamesCummins | 38:a85bc227b907 | 63 | if(gamepad.check_event(gamepad.BACK_PRESSED)){ |
JamesCummins | 38:a85bc227b907 | 64 | //retrieve the user's choice from the pause menu |
JamesCummins | 38:a85bc227b907 | 65 | PauseOption choice = pause.pause_menu(gamepad, lcd, fps); |
JamesCummins | 38:a85bc227b907 | 66 | //jump to the appropriate point in the game mode |
JamesCummins | 38:a85bc227b907 | 67 | i = pause.brickbreaker_action(choice, gamepad, lcd, i, fps); |
JamesCummins | 38:a85bc227b907 | 68 | } |
JamesCummins | 38:a85bc227b907 | 69 | } |
JamesCummins | 38:a85bc227b907 | 70 | } |
JamesCummins | 38:a85bc227b907 | 71 | |
JamesCummins | 38:a85bc227b907 | 72 | @endcode |
JamesCummins | 38:a85bc227b907 | 73 | */ |
JamesCummins | 38:a85bc227b907 | 74 | |
JamesCummins | 20:4a39a1a2be51 | 75 | class Pause { |
JamesCummins | 20:4a39a1a2be51 | 76 | |
JamesCummins | 20:4a39a1a2be51 | 77 | public: |
JamesCummins | 37:de1f584bce71 | 78 | /** |
JamesCummins | 37:de1f584bce71 | 79 | * @brief Create a Pause object |
JamesCummins | 37:de1f584bce71 | 80 | */ |
JamesCummins | 22:4e305ff8a050 | 81 | Pause(); |
JamesCummins | 37:de1f584bce71 | 82 | /** |
JamesCummins | 37:de1f584bce71 | 83 | * @brief Delete Pause object to free memory |
JamesCummins | 37:de1f584bce71 | 84 | */ |
JamesCummins | 22:4e305ff8a050 | 85 | ~Pause(); |
JamesCummins | 37:de1f584bce71 | 86 | /** |
JamesCummins | 37:de1f584bce71 | 87 | * @brief Initialise the pause menu with the first menu option highlighted |
JamesCummins | 37:de1f584bce71 | 88 | */ |
JamesCummins | 22:4e305ff8a050 | 89 | void init(); |
JamesCummins | 37:de1f584bce71 | 90 | /** |
JamesCummins | 37:de1f584bce71 | 91 | * @brief Read the user input and update the displayed menu until an option is selected |
JamesCummins | 37:de1f584bce71 | 92 | * @param gamepad - Gamepad object to sense user interaction |
JamesCummins | 37:de1f584bce71 | 93 | * @param lcd - N5110 object to render menu on LCD screen |
JamesCummins | 37:de1f584bce71 | 94 | * @param fps - integer value of frames per second game is ran at |
JamesCummins | 37:de1f584bce71 | 95 | * @returns an Enum of the pause option selected by user (RESUME, RESTART, QUIT or HELP) |
JamesCummins | 37:de1f584bce71 | 96 | */ |
JamesCummins | 29:42651f87522b | 97 | PauseOption pause_menu(Gamepad &gamepad, N5110 &lcd, int fps); |
JamesCummins | 37:de1f584bce71 | 98 | /** |
JamesCummins | 37:de1f584bce71 | 99 | * @brief Jump to a specified frame in the game based on user's menu choice |
JamesCummins | 37:de1f584bce71 | 100 | * @param choice - option selected in the Pause menu |
JamesCummins | 37:de1f584bce71 | 101 | * @param gamepad - Gamepad object to check for button press |
JamesCummins | 37:de1f584bce71 | 102 | * @param lcd - N5110 object to interact with LCD screen |
JamesCummins | 37:de1f584bce71 | 103 | * @param frame - integer of current no. of frames iterated through in gameplay |
JamesCummins | 37:de1f584bce71 | 104 | * @param fps - integer of gameplay's frames per second |
JamesCummins | 37:de1f584bce71 | 105 | * @returns i - integer of frame to jump to |
JamesCummins | 37:de1f584bce71 | 106 | */ |
JamesCummins | 29:42651f87522b | 107 | int brickbreaker_action(PauseOption choice, Gamepad &gamepad, N5110 &lcd, int frame, int fps); |
JamesCummins | 37:de1f584bce71 | 108 | /** |
JamesCummins | 37:de1f584bce71 | 109 | * @brief Display the help menu for classic game mode |
JamesCummins | 37:de1f584bce71 | 110 | * @param gamepad - Gamepad object to check for button press |
JamesCummins | 37:de1f584bce71 | 111 | * @param lcd - N5110 object to render help menu on LCD |
JamesCummins | 37:de1f584bce71 | 112 | */ |
JamesCummins | 29:42651f87522b | 113 | void classic_help(Gamepad &gamepad, N5110 &lcd); |
JamesCummins | 37:de1f584bce71 | 114 | /** |
JamesCummins | 37:de1f584bce71 | 115 | * @brief Display the help menu for brickbreaker game mode |
JamesCummins | 37:de1f584bce71 | 116 | * @param gamepad - Gamepad object to check for button press |
JamesCummins | 37:de1f584bce71 | 117 | * @param lcd - N5110 object to render help menu on LCD |
JamesCummins | 37:de1f584bce71 | 118 | */ |
JamesCummins | 29:42651f87522b | 119 | void brickbreaker_help(Gamepad &gamepad, N5110 &lcd); |
JamesCummins | 20:4a39a1a2be51 | 120 | |
JamesCummins | 20:4a39a1a2be51 | 121 | private: |
JamesCummins | 20:4a39a1a2be51 | 122 | |
JamesCummins | 22:4e305ff8a050 | 123 | void display_pause_options(N5110 &lcd); |
JamesCummins | 22:4e305ff8a050 | 124 | PauseOption pause_selection(Gamepad &gamepad, N5110 &lcd); |
JamesCummins | 22:4e305ff8a050 | 125 | PauseOption _state; |
JamesCummins | 22:4e305ff8a050 | 126 | int _next_state; |
JamesCummins | 20:4a39a1a2be51 | 127 | }; |
JamesCummins | 20:4a39a1a2be51 | 128 | #endif |