Cube Dodger A 3D 'endless runner' game

Dependencies:   mbed

Committer:
el17cd
Date:
Wed May 08 18:17:59 2019 +0000
Revision:
46:824ec81ff578
Parent:
45:6eb1a18019d0
Potentiometer now changes screen contrast for use on other devices.; Final Submission.; I have read and agreed with the Statement of Academic Integrity.

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