Cube Dodger A 3D 'endless runner' game

Dependencies:   mbed

Committer:
el17cd
Date:
Mon Apr 29 14:48:27 2019 +0000
Revision:
34:5cb9b4d01f5c
Parent:
32:9c250eda7f3f
Child:
35:fe3956825bd8
Removed @ before brief causing descriptions to be in the wrong order

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 34:5cb9b4d01f5c 15 brief 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 34:5cb9b4d01f5c 28 brief 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 34:5cb9b4d01f5c 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 34:5cb9b4d01f5c 67 /** brief 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 34:5cb9b4d01f5c 71 /** brief 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 34:5cb9b4d01f5c 75 /** brief generates initial positions for all cubes
el17cd 26:8a85aede976d 76 */
el17cd 21:6b5d2d75e083 77 void addScore();
el17cd 34:5cb9b4d01f5c 78 /** brief Increments the score by 1
el17cd 25:3995271e411c 79 */
el17cd 21:6b5d2d75e083 80 void resetScore();
el17cd 34:5cb9b4d01f5c 81 /** brief Resets the score to 0
el17cd 25:3995271e411c 82 */
el17cd 25:3995271e411c 83 void checkDespawn(Cube *cube);
el17cd 34:5cb9b4d01f5c 84 /** 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 85 *@param A pointer to a cube object
el17cd 25:3995271e411c 86 */
el17cd 25:3995271e411c 87 void checkDeath(Cube *cube);
el17cd 34:5cb9b4d01f5c 88 /** 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 89 *@param A pointer to a cube object
el17cd 25:3995271e411c 90 */
el17cd 25:3995271e411c 91 void cubeToBeRendered(Cube *cube, int cubeIndex);
el17cd 34:5cb9b4d01f5c 92 /** brief 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 34:5cb9b4d01f5c 97 /** 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 98 *@param A pointer to a cube object
el17cd 25:3995271e411c 99 */
el17cd 25:3995271e411c 100 void displayDeathMenu();
el17cd 34:5cb9b4d01f5c 101 /** 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 102 */
el17cd 25:3995271e411c 103 void deathButtonSelections();
el17cd 34:5cb9b4d01f5c 104 /** brief 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 34:5cb9b4d01f5c 107 /** brief 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 34:5cb9b4d01f5c 110 /** brief 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 34:5cb9b4d01f5c 114 /** brief 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 34:5cb9b4d01f5c 118 /** brief 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 34:5cb9b4d01f5c 122 /** brief 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 34:5cb9b4d01f5c 125 /** brief 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 34:5cb9b4d01f5c 128 /** brief 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 34:5cb9b4d01f5c 131 /** brief 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 34:5cb9b4d01f5c 134 /** brief Begin the execution of the game
el17cd 28:f8ff7c8c1627 135 */
el17cd 30:91038c2afec7 136 void homeScreen();
el17cd 34:5cb9b4d01f5c 137 /** brief Displays the home screen
el17cd 30:91038c2afec7 138 */
el17cd 27:e46af658c67a 139 void helpScreen();
el17cd 34:5cb9b4d01f5c 140 /** brief Display the help screens
el17cd 28:f8ff7c8c1627 141 */
el17cd 27:e46af658c67a 142 void checkNextHelpScreen();
el17cd 34:5cb9b4d01f5c 143 /** brief 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 28:f8ff7c8c1627 147 /**brief The constructor of the Face class which instantiates the game object.
el17cd 28:f8ff7c8c1627 148 */
el17cd 15:8fbbdefbe720 149 void run();
el17cd 34:5cb9b4d01f5c 150 /** brief Executes the main loop
el17cd 25:3995271e411c 151 */
el17cd 30:91038c2afec7 152
el17cd 15:8fbbdefbe720 153 };