ELEC2645 (2018/19) / Mbed 2 deprecated el17cd

Dependencies:   mbed

Committer:
el17cd
Date:
Tue May 07 16:57:26 2019 +0000
Revision:
39:41dcf1604fdf
Parent:
38:cc5461dd0369
Child:
40:065f0e4d6652
Added doxygen code example for structs

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17cd 15:8fbbdefbe720 1 #ifndef FACE_H
el17cd 15:8fbbdefbe720 2 #define FACE_H
el17cd 15:8fbbdefbe720 3 #include "Face.h"
el17cd 15:8fbbdefbe720 4 #endif
el17cd 31:e681177037ef 5 #include "Renderer.h"
el17cd 16:64cd7bc094f9 6 #ifndef CUBE_H
el17cd 16:64cd7bc094f9 7 #define CUBE_H
el17cd 15:8fbbdefbe720 8 #include "Cube.h"
el17cd 16:64cd7bc094f9 9 #endif
el17cd 15:8fbbdefbe720 10 #include "Gamepad.h"
el17cd 15:8fbbdefbe720 11 #include "mbed.h"
el17cd 32:9c250eda7f3f 12 #include "SDFileSystem.h"
el17cd 30:91038c2afec7 13
el17cd 34:5cb9b4d01f5c 14 /** Input struct
el17cd 39:41dcf1604fdf 15 *Stores current details of required inputs, this being the joystick x axis, the a, b and y buttons. It also stores whether the button press can be registered yet to remove the switch bouncing issue.
el17cd 39:41dcf1604fdf 16 *@code
el17cd 39:41dcf1604fdf 17 *void Game::processInput(){ //Obtain user inputs and store in input struct
el17cd 39:41dcf1604fdf 18 * input.x = gamepad.get_coord().x; //Get value of joystick x axis
el17cd 39:41dcf1604fdf 19 * bool y = gamepad.check_event(Gamepad::Y_PRESSED);
el17cd 39:41dcf1604fdf 20 * bool a = gamepad.check_event(Gamepad::A_PRESSED);
el17cd 39:41dcf1604fdf 21 * bool b = gamepad.check_event(Gamepad::B_PRESSED);
el17cd 39:41dcf1604fdf 22 *
el17cd 39:41dcf1604fdf 23 * disableYButton(y);
el17cd 39:41dcf1604fdf 24 * disableAButton(a);
el17cd 39:41dcf1604fdf 25 * disableBButton(b);
el17cd 39:41dcf1604fdf 26 *}
el17cd 39:41dcf1604fdf 27 *
el17cd 39:41dcf1604fdf 28 *void Game::disableYButton(bool y){ //Set y button to disabled, call function to reenable in 0.2 seconds
el17cd 39:41dcf1604fdf 29 * if(!input.yCooldown && y){
el17cd 39:41dcf1604fdf 30 * input.yCooldown = true;
el17cd 39:41dcf1604fdf 31 * disableY.attach(callback(this, &Game::enableY), 0.2); //attach function to ticker to renable y button
el17cd 39:41dcf1604fdf 32 * input.yButton = true;
el17cd 39:41dcf1604fdf 33 * }
el17cd 39:41dcf1604fdf 34 * else{
el17cd 39:41dcf1604fdf 35 * input.yButton = false;
el17cd 39:41dcf1604fdf 36 * }
el17cd 39:41dcf1604fdf 37 *}
el17cd 25:3995271e411c 38 */
el17cd 34:5cb9b4d01f5c 39 struct Input{
el17cd 39:41dcf1604fdf 40 float x; /**<The x axis of the joystick*/
el17cd 39:41dcf1604fdf 41 bool yButton; /**<Whether the y button is pressed*/
el17cd 39:41dcf1604fdf 42 bool aButton; /**<Whether the a button is pressed*/
el17cd 39:41dcf1604fdf 43 bool bButton; /**<Whether the b button is pressed*/
el17cd 39:41dcf1604fdf 44 bool yCooldown; /**<Whether 0.2 seconds has elapsed since the y button was pressed*/
el17cd 39:41dcf1604fdf 45 bool aCooldown; /**<Whether 0.2 seconds has elapsed since the a button was pressed*/
el17cd 39:41dcf1604fdf 46 bool bCooldown; /**<Whether 0.2 seconds has elapsed since the b button was pressed*/
el17cd 26:8a85aede976d 47 };
el17cd 26:8a85aede976d 48
el17cd 39:41dcf1604fdf 49
el17cd 36:6fbafc8bed80 50 /** MenuSelections struct
el17cd 39:41dcf1604fdf 51 *Stores the current selections in both the home menu and death menu.
el17cd 34:5cb9b4d01f5c 52 */
el17cd 32:9c250eda7f3f 53 struct MenuSelections{ //stores the current selections in both menus
el17cd 39:41dcf1604fdf 54 int deathMenuSelection; /**< Which item in the death screen has been selected*/
el17cd 39:41dcf1604fdf 55 int homeMenuSelection; /**< Which item in the home screen has been selected*/
el17cd 31:e681177037ef 56 };
el17cd 31:e681177037ef 57
el17cd 34:5cb9b4d01f5c 58
el17cd 34:5cb9b4d01f5c 59 /** Game class
el17cd 37:524b91130885 60 *@brief A class used to instantiate a game object, this is used to run the game and consists of the main game loop.
el17cd 34:5cb9b4d01f5c 61 *@author Christopher Doel
el17cd 34:5cb9b4d01f5c 62 *@date April, 2019
el17cd 34:5cb9b4d01f5c 63 */
el17cd 34:5cb9b4d01f5c 64
el17cd 34:5cb9b4d01f5c 65
el17cd 15:8fbbdefbe720 66 class Game {
el17cd 15:8fbbdefbe720 67 private:
el17cd 26:8a85aede976d 68 Input input;
el17cd 31:e681177037ef 69 MenuSelections menuSelections;
el17cd 31:e681177037ef 70
el17cd 20:3ca430241df0 71 int noOfCubes;
el17cd 28:f8ff7c8c1627 72 bool playing;
el17cd 28:f8ff7c8c1627 73 int score;
el17cd 28:f8ff7c8c1627 74 int highScore;
el17cd 31:e681177037ef 75 bool inHomeMenu;
el17cd 31:e681177037ef 76 int helpScreenNumber;
el17cd 28:f8ff7c8c1627 77
el17cd 28:f8ff7c8c1627 78 FILE *filePointer;
el17cd 28:f8ff7c8c1627 79
el17cd 31:e681177037ef 80 Cube cubeArray[25]; //Store cubes
el17cd 31:e681177037ef 81 Face faceArray[150]; //Store all cubes faces
el17cd 21:6b5d2d75e083 82
el17cd 26:8a85aede976d 83 Ticker disableA;
el17cd 26:8a85aede976d 84 Ticker disableB;
el17cd 26:8a85aede976d 85 Ticker disableY;
el17cd 15:8fbbdefbe720 86 Gamepad gamepad;
el17cd 31:e681177037ef 87 Renderer renderer;
el17cd 35:fe3956825bd8 88 /** Reads the highscore stored in the SD card
el17cd 28:f8ff7c8c1627 89 *@returns the highscore as an integer
el17cd 28:f8ff7c8c1627 90 */
el17cd 38:cc5461dd0369 91 int readHighScore();
el17cd 35:fe3956825bd8 92 /** Writes the new highscore to the SD card
el17cd 28:f8ff7c8c1627 93 *@param the highscore as an integer
el17cd 28:f8ff7c8c1627 94 */
el17cd 38:cc5461dd0369 95 void writeHighScore(int score);
el17cd 38:cc5461dd0369 96 /** generates initial positions for all cubes
el17cd 38:cc5461dd0369 97 */
el17cd 26:8a85aede976d 98 void resetScene();
el17cd 38:cc5461dd0369 99 /** Increments the score by 1
el17cd 26:8a85aede976d 100 */
el17cd 21:6b5d2d75e083 101 void addScore();
el17cd 38:cc5461dd0369 102 /** Resets the score to 0
el17cd 25:3995271e411c 103 */
el17cd 21:6b5d2d75e083 104 void resetScore();
el17cd 35:fe3956825bd8 105 /** Checks whether a cube needs to be despawned, if it does then the cube will be translated to the far side of the map
el17cd 25:3995271e411c 106 *@param A pointer to a cube object
el17cd 25:3995271e411c 107 */
el17cd 38:cc5461dd0369 108 void checkDespawn(Cube *cube);
el17cd 35:fe3956825bd8 109 /** Checks whether a cube is too close to the user and therefore a collision has occured, the game will be stopped if true
el17cd 25:3995271e411c 110 *@param A pointer to a cube object
el17cd 25:3995271e411c 111 */
el17cd 38:cc5461dd0369 112 void checkDeath(Cube *cube);
el17cd 35:fe3956825bd8 113 /** Adds the cubes faces to the array of faces to be passed to the renderer
el17cd 25:3995271e411c 114 *@param A pointer to a cube object
el17cd 25:3995271e411c 115 *@param The integer index of the cubes position in the cube array
el17cd 25:3995271e411c 116 */
el17cd 38:cc5461dd0369 117 void cubeToBeRendered(Cube *cube, int cubeIndex);
el17cd 35:fe3956825bd8 118 /** Translates the cube in the z axis towards the user (speed dependant on score) and left and right depending on the joystick location
el17cd 25:3995271e411c 119 *@param A pointer to a cube object
el17cd 25:3995271e411c 120 */
el17cd 38:cc5461dd0369 121 void moveCubes(Cube *cube);
el17cd 38:cc5461dd0369 122 /** Displays the menu screen if the game has stopeed propting the user to either restart or go to the home menu
el17cd 38:cc5461dd0369 123 */
el17cd 25:3995271e411c 124 void displayDeathMenu();
el17cd 38:cc5461dd0369 125 /** Determines the action to be taken depending on the button input once the game has ended
el17cd 25:3995271e411c 126 */
el17cd 25:3995271e411c 127 void deathButtonSelections();
el17cd 38:cc5461dd0369 128 /** Determines the action to be taken depending on the button input at the home screen
el17cd 25:3995271e411c 129 */
el17cd 18:8256546a3cbf 130 void homeButtonSelections();
el17cd 35:fe3956825bd8 131 /** Disables the A button for 300 milliseconds after being pressed to prevent erroneous input from switch bouncing
el17cd 28:f8ff7c8c1627 132 *@param a boolean indicating whether the button has been pressed
el17cd 28:f8ff7c8c1627 133 */
el17cd 38:cc5461dd0369 134 void disableAButton(bool a);
el17cd 35:fe3956825bd8 135 /** Disables the Y button for 300 milliseconds after being pressed to prevent erroneous input from switch bouncing
el17cd 28:f8ff7c8c1627 136 *@param a boolean indicating whether the button has been pressed
el17cd 28:f8ff7c8c1627 137 */
el17cd 38:cc5461dd0369 138 void disableYButton(bool y);
el17cd 35:fe3956825bd8 139 /** Disables the B button for 300 milliseconds after being pressed to prevent erroneous input from switch bouncing
el17cd 28:f8ff7c8c1627 140 *@param a boolean indicating whether the button has been pressed
el17cd 28:f8ff7c8c1627 141 */
el17cd 38:cc5461dd0369 142 void disableBButton(bool b);
el17cd 35:fe3956825bd8 143 /** Is called using a ticker 300 milliseconds after the A button is pressed to re-enable it
el17cd 28:f8ff7c8c1627 144 */
el17cd 38:cc5461dd0369 145 void enableA();
el17cd 38:cc5461dd0369 146 /** Is called using a ticker 300 milliseconds after the Y button is pressed to re-enable it
el17cd 38:cc5461dd0369 147 */
el17cd 26:8a85aede976d 148 void enableY();
el17cd 38:cc5461dd0369 149 /** Is called using a ticker 300 milliseconds after the B button is pressed to re-enable it
el17cd 28:f8ff7c8c1627 150 */
el17cd 26:8a85aede976d 151 void enableB();
el17cd 38:cc5461dd0369 152 /** Process the joystick and Y, B and A button inputs and store their values in a structure
el17cd 28:f8ff7c8c1627 153 */
el17cd 26:8a85aede976d 154 void processInput();
el17cd 38:cc5461dd0369 155 /** Begin the execution of the game
el17cd 28:f8ff7c8c1627 156 */
el17cd 26:8a85aede976d 157 void play();
el17cd 38:cc5461dd0369 158 /** Displays the home screen
el17cd 28:f8ff7c8c1627 159 */
el17cd 30:91038c2afec7 160 void homeScreen();
el17cd 38:cc5461dd0369 161 /** Display the help screens
el17cd 30:91038c2afec7 162 */
el17cd 27:e46af658c67a 163 void helpScreen();
el17cd 35:fe3956825bd8 164 /** Check whether the user has advanced to the next help screen by pressing the A button
el17cd 28:f8ff7c8c1627 165 */
el17cd 38:cc5461dd0369 166 void checkNextHelpScreen();
el17cd 38:cc5461dd0369 167
el17cd 15:8fbbdefbe720 168 public:
el17cd 38:cc5461dd0369 169 /** The constructor of the Game class and is used to execute the game.
el17cd 38:cc5461dd0369 170 */
el17cd 15:8fbbdefbe720 171 Game();
el17cd 38:cc5461dd0369 172 /** Executes the main loop
el17cd 28:f8ff7c8c1627 173 */
el17cd 15:8fbbdefbe720 174 void run();
el17cd 38:cc5461dd0369 175
el17cd 30:91038c2afec7 176
el17cd 15:8fbbdefbe720 177 };