James Cummins / Mbed 2 deprecated el17jnc

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

OptionsEngine Class Reference

OptionsEngine Class Reference

Options Engine Class. More...

#include <OptionsEngine.h>

Public Member Functions

 OptionsEngine ()
 Create an engine object for the Options menu.
 ~OptionsEngine ()
 Delete an Options Engine object to free up memory.
void init ()
 Initialise Options menu settings.
void display_options (N5110 &lcd)
 Render the options menu on the LCD screen.
Option option_selection (Gamepad &gamepad, N5110 &lcd)
 Read the user input, highlight and store the current option on the screen.
void change_brightness (Gamepad &gamepad, N5110 &lcd)
 Set the brightness of the LCD screen.
void change_ball_speed (Gamepad &gamepad, N5110 &lcd, Ball &ball)
 Set the ball speed multiplier.
void view_high_scores (Gamepad &gamepad, N5110 &lcd)
 Display the high scores for the selected game mode on the LCD screen.

Detailed Description

Options Engine Class.

Library to power the options menu Features methods

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

//Create an engine object for the Options Menu
OptionsEngine opt;
Gamepad gamepad;
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Ball ball;

int main(){
    //Enum for the user's option choice initialised to first menu item (brightness)
    Option choice = BRIGHTNESS;
    while(!(gamepad.check_event(gamepad.A_PRESSED))){
    //display options renders the options menu
    //option selection renders the arrows which point to the current selection
        lcd.clear();
        opt.display_options(lcd);
        choice = opt.option_selection(gamepad, lcd);
        lcd.refresh();
    //longer wait time than normal game fps to compensate for button bounce
        wait(0.2);
    }
    //each menu option called by its respective enum
    if(choice == BRIGHTNESS){ opt.change_brightness(gamepad, lcd); }
    if(choice == BALL_SPEED){ opt.change_ball_speed(gamepad, lcd, ball); }
    if(choice == HIGH_SCORES){ opt.view_high_scores(gamepad, lcd); }
}

Definition at line 64 of file OptionsEngine.h.


Constructor & Destructor Documentation

Create an engine object for the Options menu.

Definition at line 4 of file OptionsEngine.cpp.

~OptionsEngine (  )

Delete an Options Engine object to free up memory.

Definition at line 8 of file OptionsEngine.cpp.


Member Function Documentation

void change_ball_speed ( Gamepad gamepad,
N5110 lcd,
Ball ball 
)

Set the ball speed multiplier.

Parameters:
gamepad- Gamepad object to detect button press
lcd- N5110 object to display graphic interface

ball speed is a continual multiplier to the values sensed by the accelerometer, altering the sensitivity of the sensed input (i.e the same change in tilt causes a greater change in the ball's position

Definition at line 65 of file OptionsEngine.cpp.

void change_brightness ( Gamepad gamepad,
N5110 lcd 
)

Set the brightness of the LCD screen.

Parameters:
gamepad- Gamepad object to detect button press
lcd- N5110 object to alter brightness and display graphic interface

Definition at line 40 of file OptionsEngine.cpp.

void display_options ( N5110 lcd )

Render the options menu on the LCD screen.

Parameters:
lcd- N5110 object to interact with LCD screen

Definition at line 18 of file OptionsEngine.cpp.

void init (  )

Initialise Options menu settings.

Set brightness to 50%, set initial option to the top one in the list, and set ball speed sensitivity to 5/10

Definition at line 12 of file OptionsEngine.cpp.

Option option_selection ( Gamepad gamepad,
N5110 lcd 
)

Read the user input, highlight and store the current option on the screen.

Parameters:
gamepad- Gamepad object to read the user input
lcd- N5110 object to display arrows on LCD screen
Returns:
an Enum of the option selected - BRIGHTNESS, BALL_SPEED or HIGH_SCORES

Definition at line 25 of file OptionsEngine.cpp.

void view_high_scores ( Gamepad gamepad,
N5110 lcd 
)

Display the high scores for the selected game mode on the LCD screen.

Parameters:
gamepad- Gamepad object to sense user's selection
lcd- N5110 object to display chosen leaderboard on LCD Screen

Definition at line 90 of file OptionsEngine.cpp.