James Cummins / Mbed 2 deprecated el17jnc

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Pause.h Source File

Pause.h

00001 #ifndef PAUSE_H
00002 #define PAUSE_H
00003 
00004 #include "mbed.h"
00005 #include "Gamepad.h"
00006 #include "ClassicEngine.h"
00007 #include "N5110.h"
00008 
00009 /** Enum for game mode*/
00010 enum Mode{
00011     CLASSIC_MODE, 
00012     BRICKBREAKER_MODE
00013     };
00014 
00015 /** Enum for Pause Options*/
00016 enum PauseOption{
00017     RESUME,
00018     RESTART,
00019     QUIT,
00020     HELP
00021     };
00022 
00023 /**Pause selection struct*/
00024 struct PauseSelection{
00025     int output;                 /**<Integer output for line to print arrows*/
00026     PauseOption next_state[3];  /**<Array of enums for possible next option*/
00027     };
00028 
00029 /** Pause Class
00030 @brief Library to power the pause menu
00031 @brief Can pass frame values to control the flow of the game modes they're
00032 @brief utilised in, enabling features like restarting and quitting
00033 
00034 @author James Cummins
00035 
00036 @code
00037 
00038 #include "mbed.h"
00039 #include "Pause.h"
00040 
00041 Pause pause;        //create a pause object for the pause menu
00042 Gamepad gamepad;
00043 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
00044 
00045 int main(){
00046     //first initialise the pause menu so it points to top item first
00047     pause.init();
00048     int game_length = 90;   //desired game mode length in seconds
00049     int fps = 30;           //frames per sec of the game mode
00050     
00051     //use either one or the other of these (for the correct game mode)
00052     //to display instructions before the game commences
00053     pause.brickbreaker_help(gamepad, lcd);
00054     pause.classic_help(gamepad, lcd);
00055     
00056     for(int i = 0; i < game_length*fps; i++){
00057         //
00058         //
00059         //code to operate a time based game mode
00060         //
00061         //
00062         
00063         if(gamepad.check_event(gamepad.BACK_PRESSED)){
00064         //retrieve the user's choice from the pause menu
00065             PauseOption choice = pause.pause_menu(gamepad, lcd, fps);
00066         //jump to the appropriate point in the game mode
00067             i = pause.brickbreaker_action(choice, gamepad, lcd, i, fps);
00068         }
00069     }
00070 }
00071 
00072 @endcode
00073 */
00074 
00075 class Pause {
00076 
00077 public:
00078     /** 
00079     * @brief Create a Pause object
00080     */
00081     Pause();
00082     /** 
00083     * @brief Delete Pause object to free memory
00084     */
00085     ~Pause();
00086     /** 
00087     * @brief Initialise the pause menu with the first menu option highlighted
00088     */
00089     void init();
00090     /** 
00091     * @brief Read the user input and update the displayed menu until an option is selected
00092     * @param gamepad - Gamepad object to sense user interaction
00093     * @param lcd - N5110 object to render menu on LCD screen
00094     * @param fps - integer value of frames per second game is ran at
00095     * @returns an Enum of the pause option selected by user (RESUME, RESTART, QUIT or HELP)
00096     */
00097     PauseOption pause_menu(Gamepad &gamepad, N5110 &lcd, int fps);
00098     /** 
00099     * @brief Jump to a specified frame in the game based on user's menu choice
00100     * @param choice - option selected in the Pause menu
00101     * @param gamepad - Gamepad object to check for button press
00102     * @param lcd - N5110 object to interact with LCD screen
00103     * @param frame - integer of current no. of frames iterated through in gameplay
00104     * @param fps - integer of gameplay's frames per second
00105     * @returns i - integer of frame to jump to
00106     */
00107     int brickbreaker_action(PauseOption choice, Gamepad &gamepad, N5110 &lcd, int frame, int fps);
00108     /** 
00109     * @brief Display the help menu for classic game mode
00110     * @param gamepad - Gamepad object to check for button press
00111     * @param lcd - N5110 object to render help menu on LCD
00112     */
00113     void classic_help(Gamepad &gamepad, N5110 &lcd);
00114     /** 
00115     * @brief Display the help menu for brickbreaker game mode
00116     * @param gamepad - Gamepad object to check for button press
00117     * @param lcd - N5110 object to render help menu on LCD
00118     */
00119     void brickbreaker_help(Gamepad &gamepad, N5110 &lcd);
00120 
00121 private:
00122 
00123     void display_pause_options(N5110 &lcd);
00124     PauseOption pause_selection(Gamepad &gamepad, N5110 &lcd);
00125     PauseOption _state;
00126     int _next_state;
00127 };
00128 #endif