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.
Dependencies: mbed
Game/Game.h@32:9c250eda7f3f, 2019-04-05 (annotated)
- Committer:
- el17cd
- Date:
- Fri Apr 05 15:43:27 2019 +0000
- Revision:
- 32:9c250eda7f3f
- Parent:
- 31:e681177037ef
- Child:
- 34:5cb9b4d01f5c
Removed unnecessary includes in .h files
Who changed what in which revision?
| User | Revision | Line number | New 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 | 25:3995271e411c | 14 | /** Game class |
| el17cd | 32:9c250eda7f3f | 15 | *@brief A class used to instantiate a game object, this is used to run the game |
| el17cd | 25:3995271e411c | 16 | *@author Christopher Doel |
| el17cd | 25:3995271e411c | 17 | *@date April, 2019 |
| el17cd | 25:3995271e411c | 18 | */ |
| el17cd | 25:3995271e411c | 19 | |
| el17cd | 32:9c250eda7f3f | 20 | struct Input{ //Stores current details of required inputs |
| el17cd | 26:8a85aede976d | 21 | float x; |
| el17cd | 26:8a85aede976d | 22 | bool yButton; |
| el17cd | 26:8a85aede976d | 23 | bool aButton; |
| el17cd | 26:8a85aede976d | 24 | bool bButton; |
| el17cd | 26:8a85aede976d | 25 | bool yCooldown; |
| el17cd | 26:8a85aede976d | 26 | bool aCooldown; |
| el17cd | 26:8a85aede976d | 27 | bool bCooldown; |
| el17cd | 26:8a85aede976d | 28 | }; |
| el17cd | 26:8a85aede976d | 29 | |
| el17cd | 31:e681177037ef | 30 | |
| el17cd | 32:9c250eda7f3f | 31 | struct MenuSelections{ //stores the current selections in both menus |
| el17cd | 31:e681177037ef | 32 | int deathMenuSelection; |
| el17cd | 31:e681177037ef | 33 | int homeMenuSelection; |
| el17cd | 31:e681177037ef | 34 | }; |
| el17cd | 31:e681177037ef | 35 | |
| el17cd | 15:8fbbdefbe720 | 36 | class Game { |
| el17cd | 15:8fbbdefbe720 | 37 | private: |
| el17cd | 26:8a85aede976d | 38 | Input input; |
| el17cd | 31:e681177037ef | 39 | MenuSelections menuSelections; |
| el17cd | 31:e681177037ef | 40 | |
| el17cd | 20:3ca430241df0 | 41 | int noOfCubes; |
| el17cd | 28:f8ff7c8c1627 | 42 | bool playing; |
| el17cd | 28:f8ff7c8c1627 | 43 | int score; |
| el17cd | 28:f8ff7c8c1627 | 44 | int highScore; |
| el17cd | 31:e681177037ef | 45 | bool inHomeMenu; |
| el17cd | 31:e681177037ef | 46 | int helpScreenNumber; |
| el17cd | 28:f8ff7c8c1627 | 47 | |
| el17cd | 28:f8ff7c8c1627 | 48 | FILE *filePointer; |
| el17cd | 28:f8ff7c8c1627 | 49 | |
| el17cd | 31:e681177037ef | 50 | Cube cubeArray[25]; //Store cubes |
| el17cd | 31:e681177037ef | 51 | Face faceArray[150]; //Store all cubes faces |
| el17cd | 21:6b5d2d75e083 | 52 | |
| el17cd | 26:8a85aede976d | 53 | Ticker disableA; |
| el17cd | 26:8a85aede976d | 54 | Ticker disableB; |
| el17cd | 26:8a85aede976d | 55 | Ticker disableY; |
| el17cd | 15:8fbbdefbe720 | 56 | Gamepad gamepad; |
| el17cd | 31:e681177037ef | 57 | Renderer renderer; |
| el17cd | 21:6b5d2d75e083 | 58 | |
| el17cd | 28:f8ff7c8c1627 | 59 | int readHighScore(); |
| el17cd | 28:f8ff7c8c1627 | 60 | /** @brief Reads the highscore stored in the SD card |
| el17cd | 28:f8ff7c8c1627 | 61 | *@returns the highscore as an integer |
| el17cd | 28:f8ff7c8c1627 | 62 | */ |
| el17cd | 28:f8ff7c8c1627 | 63 | void writeHighScore(int score); |
| el17cd | 28:f8ff7c8c1627 | 64 | /** @brief Writes the new highscore to the SD card |
| el17cd | 28:f8ff7c8c1627 | 65 | *@param the highscore as an integer |
| el17cd | 28:f8ff7c8c1627 | 66 | */ |
| el17cd | 26:8a85aede976d | 67 | void resetScene(); |
| el17cd | 26:8a85aede976d | 68 | /** @brief generates initial positions for all cubes |
| el17cd | 26:8a85aede976d | 69 | */ |
| el17cd | 21:6b5d2d75e083 | 70 | void addScore(); |
| el17cd | 25:3995271e411c | 71 | /** @brief Increments the score by 1 |
| el17cd | 25:3995271e411c | 72 | */ |
| el17cd | 21:6b5d2d75e083 | 73 | void resetScore(); |
| el17cd | 25:3995271e411c | 74 | /** @brief Resets the score to 0 |
| el17cd | 25:3995271e411c | 75 | */ |
| el17cd | 25:3995271e411c | 76 | void checkDespawn(Cube *cube); |
| el17cd | 25:3995271e411c | 77 | /** @brief 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 | 78 | *@param A pointer to a cube object |
| el17cd | 25:3995271e411c | 79 | */ |
| el17cd | 25:3995271e411c | 80 | void checkDeath(Cube *cube); |
| el17cd | 25:3995271e411c | 81 | /** @brief 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 | 82 | *@param A pointer to a cube object |
| el17cd | 25:3995271e411c | 83 | */ |
| el17cd | 25:3995271e411c | 84 | void cubeToBeRendered(Cube *cube, int cubeIndex); |
| el17cd | 25:3995271e411c | 85 | /** @brief Adds the cubes faces to the array of faces to be passed to the renderer |
| el17cd | 25:3995271e411c | 86 | *@param A pointer to a cube object |
| el17cd | 25:3995271e411c | 87 | *@param The integer index of the cubes position in the cube array |
| el17cd | 25:3995271e411c | 88 | */ |
| el17cd | 25:3995271e411c | 89 | void moveCubes(Cube *cube); |
| el17cd | 25:3995271e411c | 90 | /** @brief 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 | 91 | *@param A pointer to a cube object |
| el17cd | 25:3995271e411c | 92 | */ |
| el17cd | 25:3995271e411c | 93 | void displayDeathMenu(); |
| el17cd | 25:3995271e411c | 94 | /** @brief Displays the menu screen if the game has stopeed propting the user to either restart or go to the home menu |
| el17cd | 25:3995271e411c | 95 | */ |
| el17cd | 25:3995271e411c | 96 | void deathButtonSelections(); |
| el17cd | 25:3995271e411c | 97 | /** @brief Determines the action to be taken depending on the button input once the game has ended |
| el17cd | 25:3995271e411c | 98 | */ |
| el17cd | 18:8256546a3cbf | 99 | void homeButtonSelections(); |
| el17cd | 25:3995271e411c | 100 | /** @brief Determines the action to be taken depending on the button input at the home screen |
| el17cd | 25:3995271e411c | 101 | */ |
| el17cd | 26:8a85aede976d | 102 | void disableAButton(bool a); |
| el17cd | 28:f8ff7c8c1627 | 103 | /** @brief Disables the A button for 300 milliseconds after being pressed to prevent erroneous input from switch bouncing |
| el17cd | 28:f8ff7c8c1627 | 104 | *@param a boolean indicating whether the button has been pressed |
| el17cd | 28:f8ff7c8c1627 | 105 | */ |
| el17cd | 26:8a85aede976d | 106 | void disableYButton(bool y); |
| el17cd | 28:f8ff7c8c1627 | 107 | /** @brief Disables the Y button for 300 milliseconds after being pressed to prevent erroneous input from switch bouncing |
| el17cd | 28:f8ff7c8c1627 | 108 | *@param a boolean indicating whether the button has been pressed |
| el17cd | 28:f8ff7c8c1627 | 109 | */ |
| el17cd | 26:8a85aede976d | 110 | void disableBButton(bool b); |
| el17cd | 28:f8ff7c8c1627 | 111 | /** @brief Disables the B button for 300 milliseconds after being pressed to prevent erroneous input from switch bouncing |
| el17cd | 28:f8ff7c8c1627 | 112 | *@param a boolean indicating whether the button has been pressed |
| el17cd | 28:f8ff7c8c1627 | 113 | */ |
| el17cd | 26:8a85aede976d | 114 | void enableA(); |
| el17cd | 28:f8ff7c8c1627 | 115 | /** @brief Is called using a ticker 300 milliseconds after the A button is pressed to re-enable it |
| el17cd | 28:f8ff7c8c1627 | 116 | */ |
| el17cd | 26:8a85aede976d | 117 | void enableY(); |
| el17cd | 28:f8ff7c8c1627 | 118 | /** @brief Is called using a ticker 300 milliseconds after the Y button is pressed to re-enable it |
| el17cd | 28:f8ff7c8c1627 | 119 | */ |
| el17cd | 26:8a85aede976d | 120 | void enableB(); |
| el17cd | 28:f8ff7c8c1627 | 121 | /** @brief Is called using a ticker 300 milliseconds after the B button is pressed to re-enable it |
| el17cd | 28:f8ff7c8c1627 | 122 | */ |
| el17cd | 26:8a85aede976d | 123 | void processInput(); |
| el17cd | 28:f8ff7c8c1627 | 124 | /** @brief Process the joystick and Y, B and A button inputs and store their values in a structure |
| el17cd | 28:f8ff7c8c1627 | 125 | */ |
| el17cd | 26:8a85aede976d | 126 | void play(); |
| el17cd | 28:f8ff7c8c1627 | 127 | /** @brief Begin the execution of the game |
| el17cd | 28:f8ff7c8c1627 | 128 | */ |
| el17cd | 30:91038c2afec7 | 129 | void homeScreen(); |
| el17cd | 30:91038c2afec7 | 130 | /** @brief Displays the home screen |
| el17cd | 30:91038c2afec7 | 131 | */ |
| el17cd | 27:e46af658c67a | 132 | void helpScreen(); |
| el17cd | 28:f8ff7c8c1627 | 133 | /** @brief Display the help screens |
| el17cd | 28:f8ff7c8c1627 | 134 | */ |
| el17cd | 27:e46af658c67a | 135 | void checkNextHelpScreen(); |
| el17cd | 28:f8ff7c8c1627 | 136 | /** @brief Check whether the user has advanced to the next help screen by pressing the A button |
| el17cd | 28:f8ff7c8c1627 | 137 | */ |
| el17cd | 15:8fbbdefbe720 | 138 | public: |
| el17cd | 15:8fbbdefbe720 | 139 | Game(); |
| el17cd | 28:f8ff7c8c1627 | 140 | /**brief The constructor of the Face class which instantiates the game object. |
| el17cd | 28:f8ff7c8c1627 | 141 | */ |
| el17cd | 15:8fbbdefbe720 | 142 | void run(); |
| el17cd | 29:4a02f0bae202 | 143 | /** @brief Executes the main loop |
| el17cd | 25:3995271e411c | 144 | */ |
| el17cd | 30:91038c2afec7 | 145 | |
| el17cd | 15:8fbbdefbe720 | 146 | }; |