![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Cube Dodger A 3D 'endless runner' game
Game/Game.h@30:91038c2afec7, 2019-04-05 (annotated)
- Committer:
- el17cd
- Date:
- Fri Apr 05 13:54:34 2019 +0000
- Revision:
- 30:91038c2afec7
- Parent:
- 29:4a02f0bae202
- Child:
- 31:e681177037ef
Added highscore saving to sd card
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17cd | 15:8fbbdefbe720 | 1 | #include <vector> |
el17cd | 15:8fbbdefbe720 | 2 | #ifndef FACE_H |
el17cd | 15:8fbbdefbe720 | 3 | #define FACE_H |
el17cd | 15:8fbbdefbe720 | 4 | #include "Face.h" |
el17cd | 15:8fbbdefbe720 | 5 | #endif |
el17cd | 15:8fbbdefbe720 | 6 | #include "Rasturizer.h" |
el17cd | 16:64cd7bc094f9 | 7 | #ifndef CUBE_H |
el17cd | 16:64cd7bc094f9 | 8 | #define CUBE_H |
el17cd | 15:8fbbdefbe720 | 9 | #include "Cube.h" |
el17cd | 16:64cd7bc094f9 | 10 | #endif |
el17cd | 15:8fbbdefbe720 | 11 | #include "Gamepad.h" |
el17cd | 15:8fbbdefbe720 | 12 | #include "mbed.h" |
el17cd | 30:91038c2afec7 | 13 | |
el17cd | 25:3995271e411c | 14 | /** Game class |
el17cd | 25:3995271e411c | 15 | *@brief A class used to instantiate a cube object, this is the obstacle in 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 | 26:8a85aede976d | 20 | struct Input{ |
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 | 15:8fbbdefbe720 | 30 | class Game { |
el17cd | 15:8fbbdefbe720 | 31 | private: |
el17cd | 26:8a85aede976d | 32 | Input input; |
el17cd | 20:3ca430241df0 | 33 | int noOfCubes; |
el17cd | 28:f8ff7c8c1627 | 34 | |
el17cd | 28:f8ff7c8c1627 | 35 | bool playing; |
el17cd | 28:f8ff7c8c1627 | 36 | int score; |
el17cd | 28:f8ff7c8c1627 | 37 | int highScore; |
el17cd | 28:f8ff7c8c1627 | 38 | |
el17cd | 28:f8ff7c8c1627 | 39 | bool inHomeMenu; |
el17cd | 28:f8ff7c8c1627 | 40 | int help; |
el17cd | 18:8256546a3cbf | 41 | int homeSelection; |
el17cd | 25:3995271e411c | 42 | bool deathMenuSelection; |
el17cd | 28:f8ff7c8c1627 | 43 | FILE *filePointer; |
el17cd | 28:f8ff7c8c1627 | 44 | |
el17cd | 22:236319885874 | 45 | Vector2D coord; |
el17cd | 25:3995271e411c | 46 | Cube cubeArray[25]; |
el17cd | 25:3995271e411c | 47 | Face faceArray[150]; |
el17cd | 21:6b5d2d75e083 | 48 | |
el17cd | 26:8a85aede976d | 49 | Ticker disableA; |
el17cd | 26:8a85aede976d | 50 | Ticker disableB; |
el17cd | 26:8a85aede976d | 51 | Ticker disableY; |
el17cd | 15:8fbbdefbe720 | 52 | Gamepad gamepad; |
el17cd | 15:8fbbdefbe720 | 53 | Rasturizer renderer; |
el17cd | 21:6b5d2d75e083 | 54 | |
el17cd | 28:f8ff7c8c1627 | 55 | int readHighScore(); |
el17cd | 28:f8ff7c8c1627 | 56 | /** @brief Reads the highscore stored in the SD card |
el17cd | 28:f8ff7c8c1627 | 57 | *@returns the highscore as an integer |
el17cd | 28:f8ff7c8c1627 | 58 | */ |
el17cd | 28:f8ff7c8c1627 | 59 | void writeHighScore(int score); |
el17cd | 28:f8ff7c8c1627 | 60 | /** @brief Writes the new highscore to the SD card |
el17cd | 28:f8ff7c8c1627 | 61 | *@param the highscore as an integer |
el17cd | 28:f8ff7c8c1627 | 62 | */ |
el17cd | 26:8a85aede976d | 63 | void resetScene(); |
el17cd | 26:8a85aede976d | 64 | /** @brief generates initial positions for all cubes |
el17cd | 26:8a85aede976d | 65 | */ |
el17cd | 21:6b5d2d75e083 | 66 | void addScore(); |
el17cd | 25:3995271e411c | 67 | /** @brief Increments the score by 1 |
el17cd | 25:3995271e411c | 68 | */ |
el17cd | 21:6b5d2d75e083 | 69 | void resetScore(); |
el17cd | 25:3995271e411c | 70 | /** @brief Resets the score to 0 |
el17cd | 25:3995271e411c | 71 | */ |
el17cd | 25:3995271e411c | 72 | void checkDespawn(Cube *cube); |
el17cd | 25:3995271e411c | 73 | /** @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 | 74 | *@param A pointer to a cube object |
el17cd | 25:3995271e411c | 75 | */ |
el17cd | 25:3995271e411c | 76 | void checkDeath(Cube *cube); |
el17cd | 25:3995271e411c | 77 | /** @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 | 78 | *@param A pointer to a cube object |
el17cd | 25:3995271e411c | 79 | */ |
el17cd | 25:3995271e411c | 80 | void cubeToBeRendered(Cube *cube, int cubeIndex); |
el17cd | 25:3995271e411c | 81 | /** @brief Adds the cubes faces to the array of faces to be passed to the renderer |
el17cd | 25:3995271e411c | 82 | *@param A pointer to a cube object |
el17cd | 25:3995271e411c | 83 | *@param The integer index of the cubes position in the cube array |
el17cd | 25:3995271e411c | 84 | */ |
el17cd | 25:3995271e411c | 85 | void moveCubes(Cube *cube); |
el17cd | 25:3995271e411c | 86 | /** @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 | 87 | *@param A pointer to a cube object |
el17cd | 25:3995271e411c | 88 | */ |
el17cd | 25:3995271e411c | 89 | void displayDeathMenu(); |
el17cd | 25:3995271e411c | 90 | /** @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 | 91 | */ |
el17cd | 25:3995271e411c | 92 | void deathButtonSelections(); |
el17cd | 25:3995271e411c | 93 | /** @brief Determines the action to be taken depending on the button input once the game has ended |
el17cd | 25:3995271e411c | 94 | */ |
el17cd | 18:8256546a3cbf | 95 | void homeButtonSelections(); |
el17cd | 25:3995271e411c | 96 | /** @brief Determines the action to be taken depending on the button input at the home screen |
el17cd | 25:3995271e411c | 97 | */ |
el17cd | 26:8a85aede976d | 98 | void disableAButton(bool a); |
el17cd | 28:f8ff7c8c1627 | 99 | /** @brief Disables the A button for 300 milliseconds after being pressed to prevent erroneous input from switch bouncing |
el17cd | 28:f8ff7c8c1627 | 100 | *@param a boolean indicating whether the button has been pressed |
el17cd | 28:f8ff7c8c1627 | 101 | */ |
el17cd | 26:8a85aede976d | 102 | void disableYButton(bool y); |
el17cd | 28:f8ff7c8c1627 | 103 | /** @brief Disables the Y 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 disableBButton(bool b); |
el17cd | 28:f8ff7c8c1627 | 107 | /** @brief Disables the B 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 enableA(); |
el17cd | 28:f8ff7c8c1627 | 111 | /** @brief Is called using a ticker 300 milliseconds after the A button is pressed to re-enable it |
el17cd | 28:f8ff7c8c1627 | 112 | */ |
el17cd | 26:8a85aede976d | 113 | void enableY(); |
el17cd | 28:f8ff7c8c1627 | 114 | /** @brief Is called using a ticker 300 milliseconds after the Y button is pressed to re-enable it |
el17cd | 28:f8ff7c8c1627 | 115 | */ |
el17cd | 26:8a85aede976d | 116 | void enableB(); |
el17cd | 28:f8ff7c8c1627 | 117 | /** @brief Is called using a ticker 300 milliseconds after the B button is pressed to re-enable it |
el17cd | 28:f8ff7c8c1627 | 118 | */ |
el17cd | 26:8a85aede976d | 119 | void processInput(); |
el17cd | 28:f8ff7c8c1627 | 120 | /** @brief Process the joystick and Y, B and A button inputs and store their values in a structure |
el17cd | 28:f8ff7c8c1627 | 121 | */ |
el17cd | 26:8a85aede976d | 122 | void play(); |
el17cd | 28:f8ff7c8c1627 | 123 | /** @brief Begin the execution of the game |
el17cd | 28:f8ff7c8c1627 | 124 | */ |
el17cd | 30:91038c2afec7 | 125 | void homeScreen(); |
el17cd | 30:91038c2afec7 | 126 | /** @brief Displays the home screen |
el17cd | 30:91038c2afec7 | 127 | */ |
el17cd | 27:e46af658c67a | 128 | void helpScreen(); |
el17cd | 28:f8ff7c8c1627 | 129 | /** @brief Display the help screens |
el17cd | 28:f8ff7c8c1627 | 130 | */ |
el17cd | 27:e46af658c67a | 131 | void checkNextHelpScreen(); |
el17cd | 28:f8ff7c8c1627 | 132 | /** @brief Check whether the user has advanced to the next help screen by pressing the A button |
el17cd | 28:f8ff7c8c1627 | 133 | */ |
el17cd | 15:8fbbdefbe720 | 134 | public: |
el17cd | 15:8fbbdefbe720 | 135 | Game(); |
el17cd | 28:f8ff7c8c1627 | 136 | /**brief The constructor of the Face class which instantiates the game object. |
el17cd | 28:f8ff7c8c1627 | 137 | */ |
el17cd | 15:8fbbdefbe720 | 138 | void run(); |
el17cd | 29:4a02f0bae202 | 139 | /** @brief Executes the main loop |
el17cd | 25:3995271e411c | 140 | */ |
el17cd | 30:91038c2afec7 | 141 | |
el17cd | 15:8fbbdefbe720 | 142 | }; |