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