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.
OptionsEngine.h
00001 #ifndef OPTIONSENGINE_H 00002 #define OPTIONSENGINE_H 00003 00004 #include "mbed.h" 00005 #include "Gamepad.h" 00006 #include "N5110.h" 00007 #include "Ball.h" 00008 #include "Pause.h" 00009 #include "SDFileSystem.h" 00010 00011 /** Enum for choice currently selected in Options Menu*/ 00012 enum Option{ 00013 BRIGHTNESS, /**<Top menu option*/ 00014 BALL_SPEED, /**<Middle menu option*/ 00015 HIGH_SCORES /**<Bottom menu option*/ 00016 }; 00017 00018 /** Option Selection struct*/ 00019 struct OptionSelection{ 00020 int output; /**< Integer output for line to print arrows */ 00021 Option next_state[3]; /**< Array of enums for possible next option */ 00022 }; 00023 00024 /** Options Engine Class 00025 @brief Library to power the options menu 00026 @brief Features methods 00027 00028 @author James Cummins 00029 00030 @code 00031 00032 #include "mbed.h" 00033 #include "OptionsEngine.h" 00034 00035 //Create an engine object for the Options Menu 00036 OptionsEngine opt; 00037 Gamepad gamepad; 00038 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); 00039 Ball ball; 00040 00041 int main(){ 00042 //Enum for the user's option choice initialised to first menu item (brightness) 00043 Option choice = BRIGHTNESS; 00044 while(!(gamepad.check_event(gamepad.A_PRESSED))){ 00045 //display options renders the options menu 00046 //option selection renders the arrows which point to the current selection 00047 lcd.clear(); 00048 opt.display_options(lcd); 00049 choice = opt.option_selection(gamepad, lcd); 00050 lcd.refresh(); 00051 //longer wait time than normal game fps to compensate for button bounce 00052 wait(0.2); 00053 } 00054 //each menu option called by its respective enum 00055 if(choice == BRIGHTNESS){ opt.change_brightness(gamepad, lcd); } 00056 if(choice == BALL_SPEED){ opt.change_ball_speed(gamepad, lcd, ball); } 00057 if(choice == HIGH_SCORES){ opt.view_high_scores(gamepad, lcd); } 00058 } 00059 00060 @endcode 00061 00062 */ 00063 00064 class OptionsEngine { 00065 00066 public: 00067 /** 00068 * @brief Create an engine object for the Options menu 00069 */ 00070 OptionsEngine(); 00071 /** 00072 * @brief Delete an Options Engine object to free up memory 00073 */ 00074 ~OptionsEngine(); 00075 /** 00076 * @brief Initialise Options menu settings. Set brightness to 50%, set initial 00077 * option to the top one in the list, and set ball speed sensitivity to 5/10 00078 */ 00079 void init(); 00080 /** 00081 * @brief Render the options menu on the LCD screen 00082 * @param lcd - N5110 object to interact with LCD screen 00083 */ 00084 void display_options(N5110 &lcd); 00085 /** 00086 * @brief Read the user input, highlight and store the current option on the screen 00087 * @param gamepad - Gamepad object to read the user input 00088 * @param lcd - N5110 object to display arrows on LCD screen 00089 * @returns an Enum of the option selected - BRIGHTNESS, BALL_SPEED or HIGH_SCORES 00090 */ 00091 Option option_selection(Gamepad &gamepad, N5110 &lcd); 00092 /** 00093 * @brief Set the brightness of the LCD screen 00094 * @param gamepad - Gamepad object to detect button press 00095 * @param lcd - N5110 object to alter brightness and display graphic interface 00096 */ 00097 void change_brightness(Gamepad &gamepad, N5110 &lcd); 00098 /** 00099 * @brief Set the ball speed multiplier 00100 * @param gamepad - Gamepad object to detect button press 00101 * @param lcd - N5110 object to display graphic interface 00102 * @details ball speed is a continual multiplier to the values sensed by the 00103 * accelerometer, altering the sensitivity of the sensed input 00104 * (i.e the same change in tilt causes a greater change in the 00105 * ball's position 00106 */ 00107 void change_ball_speed(Gamepad &gamepad, N5110 &lcd, Ball &ball); 00108 /** 00109 * @brief Display the high scores for the selected game mode on the LCD screen 00110 * @param gamepad - Gamepad object to sense user's selection 00111 * @param lcd - N5110 object to display chosen leaderboard on LCD Screen 00112 */ 00113 void view_high_scores(Gamepad &gamepad, N5110 &lcd); 00114 00115 private: 00116 void read_brightness_input(Gamepad &gamepad); 00117 void read_ball_speed_input(Gamepad &gamepad); 00118 void print_high_scores(N5110 &lcd); 00119 void read_classic_high_scores(); 00120 void read_bb_high_scores(); 00121 Option _state; 00122 int _next_state; 00123 float _brightness; 00124 int _ball_speed; 00125 Mode _leaderboard; 00126 int _classic_index[6]; 00127 float _classic_values[6]; 00128 int _bb_index[6]; 00129 float _bb_values[6]; 00130 00131 }; 00132 #endif
Generated on Thu Jul 14 2022 00:39:27 by
1.7.2