James Cummins / Mbed 2 deprecated el17jnc

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Pause Class Reference

Pause Class Reference

Pause Class. More...

#include <Pause.h>

Public Member Functions

 Pause ()
 Create a Pause object.
 ~Pause ()
 Delete Pause object to free memory.
void init ()
 Initialise the pause menu with the first menu option highlighted.
PauseOption pause_menu (Gamepad &gamepad, N5110 &lcd, int fps)
 Read the user input and update the displayed menu until an option is selected.
int brickbreaker_action (PauseOption choice, Gamepad &gamepad, N5110 &lcd, int frame, int fps)
 Jump to a specified frame in the game based on user's menu choice.
void classic_help (Gamepad &gamepad, N5110 &lcd)
 Display the help menu for classic game mode.
void brickbreaker_help (Gamepad &gamepad, N5110 &lcd)
 Display the help menu for brickbreaker game mode.

Detailed Description

Pause Class.

Library to power the pause menu Can pass frame values to control the flow of the game modes they're utilised in, enabling features like restarting and quitting

Author:
James Cummins
#include "mbed.h"
#include "Pause.h"

Pause pause;        //create a pause object for the pause menu
Gamepad gamepad;
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);

int main(){
    //first initialise the pause menu so it points to top item first
    pause.init();
    int game_length = 90;   //desired game mode length in seconds
    int fps = 30;           //frames per sec of the game mode
    
    //use either one or the other of these (for the correct game mode)
    //to display instructions before the game commences
    pause.brickbreaker_help(gamepad, lcd);
    pause.classic_help(gamepad, lcd);
    
    for(int i = 0; i < game_length*fps; i++){
        //
        //
        //code to operate a time based game mode
        //
        //
        
        if(gamepad.check_event(gamepad.BACK_PRESSED)){
        //retrieve the user's choice from the pause menu
            PauseOption choice = pause.pause_menu(gamepad, lcd, fps);
        //jump to the appropriate point in the game mode
            i = pause.brickbreaker_action(choice, gamepad, lcd, i, fps);
        }
    }
}

Definition at line 75 of file Pause.h.


Constructor & Destructor Documentation

Pause (  )

Create a Pause object.

Definition at line 4 of file Pause.cpp.

~Pause (  )

Delete Pause object to free memory.

Definition at line 8 of file Pause.cpp.


Member Function Documentation

int brickbreaker_action ( PauseOption  choice,
Gamepad gamepad,
N5110 lcd,
int  frame,
int  fps 
)

Jump to a specified frame in the game based on user's menu choice.

Parameters:
choice- option selected in the Pause menu
gamepad- Gamepad object to check for button press
lcd- N5110 object to interact with LCD screen
frame- integer of current no. of frames iterated through in gameplay
fps- integer of gameplay's frames per second
Returns:
i - integer of frame to jump to

Definition at line 30 of file Pause.cpp.

void brickbreaker_help ( Gamepad gamepad,
N5110 lcd 
)

Display the help menu for brickbreaker game mode.

Parameters:
gamepad- Gamepad object to check for button press
lcd- N5110 object to render help menu on LCD

Definition at line 79 of file Pause.cpp.

void classic_help ( Gamepad gamepad,
N5110 lcd 
)

Display the help menu for classic game mode.

Parameters:
gamepad- Gamepad object to check for button press
lcd- N5110 object to render help menu on LCD

Definition at line 65 of file Pause.cpp.

void init (  )

Initialise the pause menu with the first menu option highlighted.

Definition at line 12 of file Pause.cpp.

PauseOption pause_menu ( Gamepad gamepad,
N5110 lcd,
int  fps 
)

Read the user input and update the displayed menu until an option is selected.

Parameters:
gamepad- Gamepad object to sense user interaction
lcd- N5110 object to render menu on LCD screen
fps- integer value of frames per second game is ran at
Returns:
an Enum of the pause option selected by user (RESUME, RESTART, QUIT or HELP)

Definition at line 16 of file Pause.cpp.