ELEC2645 (2018/19) / Mbed 2 deprecated el17cd

Dependencies:   mbed

Committer:
el17cd
Date:
Thu Apr 04 19:03:06 2019 +0000
Revision:
26:8a85aede976d
Parent:
25:3995271e411c
Child:
27:e46af658c67a
Fixed bouncing issue with d pad buttons, implemented input processor function

Who changed what in which revision?

UserRevisionLine numberNew 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 15:8fbbdefbe720 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 25:3995271e411c 33 bool backToMenu;
el17cd 20:3ca430241df0 34 int noOfCubes;
el17cd 18:8256546a3cbf 35 int homeSelection;
el17cd 25:3995271e411c 36 bool deathMenuSelection;
el17cd 15:8fbbdefbe720 37 bool playing;
el17cd 15:8fbbdefbe720 38 int score;
el17cd 26:8a85aede976d 39 bool selectDisable;
el17cd 22:236319885874 40 Vector2D coord;
el17cd 25:3995271e411c 41 Cube cubeArray[25];
el17cd 25:3995271e411c 42 Face faceArray[150];
el17cd 21:6b5d2d75e083 43
el17cd 26:8a85aede976d 44 Ticker disableA;
el17cd 26:8a85aede976d 45 Ticker disableB;
el17cd 26:8a85aede976d 46 Ticker disableY;
el17cd 15:8fbbdefbe720 47 Gamepad gamepad;
el17cd 15:8fbbdefbe720 48 Rasturizer renderer;
el17cd 21:6b5d2d75e083 49
el17cd 26:8a85aede976d 50 void resetScene();
el17cd 26:8a85aede976d 51 /** @brief generates initial positions for all cubes
el17cd 26:8a85aede976d 52 */
el17cd 21:6b5d2d75e083 53 void addScore();
el17cd 25:3995271e411c 54 /** @brief Increments the score by 1
el17cd 25:3995271e411c 55 */
el17cd 21:6b5d2d75e083 56 void resetScore();
el17cd 25:3995271e411c 57 /** @brief Resets the score to 0
el17cd 25:3995271e411c 58 */
el17cd 25:3995271e411c 59 void checkDespawn(Cube *cube);
el17cd 25:3995271e411c 60 /** @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 61 *@param A pointer to a cube object
el17cd 25:3995271e411c 62 */
el17cd 25:3995271e411c 63 void checkDeath(Cube *cube);
el17cd 25:3995271e411c 64 /** @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 65 *@param A pointer to a cube object
el17cd 25:3995271e411c 66 */
el17cd 25:3995271e411c 67 void cubeToBeRendered(Cube *cube, int cubeIndex);
el17cd 25:3995271e411c 68 /** @brief Adds the cubes faces to the array of faces to be passed to the renderer
el17cd 25:3995271e411c 69 *@param A pointer to a cube object
el17cd 25:3995271e411c 70 *@param The integer index of the cubes position in the cube array
el17cd 25:3995271e411c 71 */
el17cd 25:3995271e411c 72 void moveCubes(Cube *cube);
el17cd 25:3995271e411c 73 /** @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 74 *@param A pointer to a cube object
el17cd 25:3995271e411c 75 */
el17cd 25:3995271e411c 76 void displayDeathMenu();
el17cd 25:3995271e411c 77 /** @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 78 */
el17cd 25:3995271e411c 79 void deathButtonSelections();
el17cd 25:3995271e411c 80 /** @brief Determines the action to be taken depending on the button input once the game has ended
el17cd 25:3995271e411c 81 */
el17cd 18:8256546a3cbf 82 void homeButtonSelections();
el17cd 25:3995271e411c 83 /** @brief Determines the action to be taken depending on the button input at the home screen
el17cd 25:3995271e411c 84 */
el17cd 26:8a85aede976d 85 void disableAButton(bool a);
el17cd 26:8a85aede976d 86 void disableYButton(bool y);
el17cd 26:8a85aede976d 87 void disableBButton(bool b);
el17cd 26:8a85aede976d 88 void enableA();
el17cd 26:8a85aede976d 89 void enableY();
el17cd 26:8a85aede976d 90 void enableB();
el17cd 26:8a85aede976d 91 void processInput();
el17cd 26:8a85aede976d 92
el17cd 26:8a85aede976d 93 void play();
el17cd 15:8fbbdefbe720 94 public:
el17cd 15:8fbbdefbe720 95 Game();
el17cd 15:8fbbdefbe720 96 void run();
el17cd 25:3995271e411c 97 /** @brief Executes the game loop
el17cd 25:3995271e411c 98 */
el17cd 18:8256546a3cbf 99 void homeScreen();
el17cd 25:3995271e411c 100 /** @brief Executed the home screen loop
el17cd 25:3995271e411c 101 */
el17cd 15:8fbbdefbe720 102 };