
George Sykes ELEC2645 project
Dependencies: mbed
GHOST HUNTER
In a world of ghostly horrors there is much money to be made in underground ghost fighting rings. You've managed to get hold of a Ghostbuster, a special piece of equipment that allows you to catch, train and fight ghosts.
Instructions
Below you will find the instructions for the game. Please note that due to COVID-19 a large part of the game (fighting ghosts) could not be added as it would have required access to a second gamepad which i could not acquire.
Welcome screen
When first started you will be presented with a welcome screen
- Pot 1 to adjust the contrast on the screen
- Press A to continue.
Main menu
You have three options, catch ghosts (add ghosts to your inventory), inventory (sell ghosts) or settings(adjust the games settings).
- Press X and B to move the selection up and down respectively
- Press A to enter the selected submenu
Catch Ghost
Will now be presented with two challenges. In the first you need to find a ghost, in the second you catch it. Theses stages will start automatically.
Find ghost
Rotate the gamepad on its roll and pitch axis until all the LED's turn on. The ones on the left indicate roll and the right pitch.
- Rotate the gamepad on it roll and pitch to light up the LED's
Catch ghost
Return the gamepad to a comfortable position and use the joystick to move the crosshairs onto the ghost sprite. When ready press the A button to catch the ghost. You will be told what kind of ghost you have captured and it will be added to your inventory.
- Press A to catch the ghost
- Move the joystick to move the crosshairs
Inventory
The inventory allows you to view your ghosts and sell them.
- Use Pot 1 to scroll through the ghosts
- Pot 2 to scroll up and down the details of the individual ghosts
- Press X to prepare to sell a ghost and press again to confirm, if you don't press again the sale screen will disappear after 5 seconds
- Press Start to return to the main menu
Settings
This menu allows you to adjust some of the settings of the game.
- Press X to go up one option
- Press B to go down one option
- Press A to enter the selected submenu
- Press Start to return to the main menu
Contrast
Set the contrast of the LCD screen, the contrast will adjust on this screen so you can see the effect (contrast is bounded between 0.4 and 0.6).
- Pot 1 to increase or decrease the contrast
- Press A to set the contrast
Button Delay
Set the minimum time between button presses; if this is too low the game will detect two button presses when there was only one, too high and the buttons will seem unresponsive. So as to ensure these issues do not occur while changing the setting button X temporarily operates on the new delay but none of the others will until A is pressed.
- Pot 1 to increase or decrease the delay
- Press X to test the new delay, this will toggle the small circle to be filled in or unfilled
- Press A to save the setting
gameEngine/gameEngine.h@17:3ebcf7bba112, 2020-05-26 (annotated)
- Committer:
- el18gs
- Date:
- Tue May 26 13:37:32 2020 +0000
- Revision:
- 17:3ebcf7bba112
- Parent:
- 15:598baed15751
Final Submission. I have read and agreed with Statement of Academic Integrity.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el18gs | 13:3b2a4e14937b | 1 | /** Inventory Class |
el18gs | 13:3b2a4e14937b | 2 | * @brief Library for maintaining an inventory |
el18gs | 13:3b2a4e14937b | 3 | * @author George Sykes [el18gs] |
el18gs | 13:3b2a4e14937b | 4 | * @date 11 May 2020 |
el18gs | 13:3b2a4e14937b | 5 | * @version 1.1 |
el18gs | 13:3b2a4e14937b | 6 | */ |
el18gs | 13:3b2a4e14937b | 7 | |
el18gs | 13:3b2a4e14937b | 8 | #ifndef GAMEENGINE_H |
el18gs | 13:3b2a4e14937b | 9 | #define GAMEENGINE_H |
el18gs | 13:3b2a4e14937b | 10 | |
el18gs | 14:e2b3e645809f | 11 | /** Game enginer library that provides all the functios necessary to run the game |
el18gs | 14:e2b3e645809f | 12 | * @author George Sykes [el18gs] |
el18gs | 14:e2b3e645809f | 13 | * @date 13 May 2020 |
el18gs | 14:e2b3e645809f | 14 | * @version 1.0 |
el18gs | 14:e2b3e645809f | 15 | */ |
el18gs | 14:e2b3e645809f | 16 | |
el18gs | 13:3b2a4e14937b | 17 | #include "mbed.h" |
el18gs | 13:3b2a4e14937b | 18 | #include "Gamepad.h" |
el18gs | 13:3b2a4e14937b | 19 | #include "N5110.h" |
el18gs | 13:3b2a4e14937b | 20 | #include "SDFileSystem.h" |
el18gs | 13:3b2a4e14937b | 21 | #include "FX0S8700CQ.h" |
el18gs | 13:3b2a4e14937b | 22 | #include "Ghost.h" |
el18gs | 13:3b2a4e14937b | 23 | #include "Inventory.h" |
el18gs | 13:3b2a4e14937b | 24 | #include "tooling.h" |
el18gs | 13:3b2a4e14937b | 25 | #include <vector> |
el18gs | 13:3b2a4e14937b | 26 | #include <string> |
el18gs | 13:3b2a4e14937b | 27 | |
el18gs | 14:e2b3e645809f | 28 | /** struct for FSM used to represent menus throughout the game */ |
el18gs | 13:3b2a4e14937b | 29 | struct State { |
el18gs | 14:e2b3e645809f | 30 | int output; //**< Output value of the FSM */ |
el18gs | 14:e2b3e645809f | 31 | int nextState[2]; //**< The next state to transition too {up, down} */ |
el18gs | 13:3b2a4e14937b | 32 | }; |
el18gs | 13:3b2a4e14937b | 33 | |
el18gs | 13:3b2a4e14937b | 34 | // Constant FSM's |
el18gs | 13:3b2a4e14937b | 35 | // main Menu FSM |
el18gs | 13:3b2a4e14937b | 36 | const State mainMenuFsm[4] = { |
el18gs | 13:3b2a4e14937b | 37 | // line next{up, down} |
el18gs | 13:3b2a4e14937b | 38 | {0,{2,1}}, // State: 0 |
el18gs | 13:3b2a4e14937b | 39 | {2,{0,2}}, // State: 1 |
el18gs | 13:3b2a4e14937b | 40 | {4,{1,0}}, // State: 2 |
el18gs | 13:3b2a4e14937b | 41 | }; |
el18gs | 13:3b2a4e14937b | 42 | |
el18gs | 13:3b2a4e14937b | 43 | // Settings menu |
el18gs | 13:3b2a4e14937b | 44 | const State settingsFsm[2] = { |
el18gs | 13:3b2a4e14937b | 45 | // line next{up, down} |
el18gs | 13:3b2a4e14937b | 46 | {2,{1,1}}, // State: 0 |
el18gs | 13:3b2a4e14937b | 47 | {4,{0,0}}, // State: 1 |
el18gs | 13:3b2a4e14937b | 48 | }; |
el18gs | 13:3b2a4e14937b | 49 | |
el18gs | 14:e2b3e645809f | 50 | /** gameEngine class provides an interface for running the game |
el18gs | 14:e2b3e645809f | 51 | * @author George Sykes [el18gs] |
el18gs | 14:e2b3e645809f | 52 | * @date 13 May 2020 |
el18gs | 14:e2b3e645809f | 53 | * @veersion 1.0 |
el18gs | 14:e2b3e645809f | 54 | */ |
el18gs | 13:3b2a4e14937b | 55 | class gameEngine |
el18gs | 13:3b2a4e14937b | 56 | { |
el18gs | 13:3b2a4e14937b | 57 | public: |
el18gs | 14:e2b3e645809f | 58 | // Cnstructor |
el18gs | 14:e2b3e645809f | 59 | /** Create a game engine object and initilise the periphials |
el18gs | 14:e2b3e645809f | 60 | * @param sd pointer to the sd card object |
el18gs | 14:e2b3e645809f | 61 | * @param pad pointer to the gamepad object |
el18gs | 14:e2b3e645809f | 62 | * @param lcd pointer to the LCD object |
el18gs | 14:e2b3e645809f | 63 | */ |
el18gs | 14:e2b3e645809f | 64 | gameEngine(SDFileSystem &sd, |
el18gs | 14:e2b3e645809f | 65 | Gamepad &pad, |
el18gs | 14:e2b3e645809f | 66 | N5110 &lcd); |
el18gs | 14:e2b3e645809f | 67 | |
el18gs | 14:e2b3e645809f | 68 | /** Display the welcome screen allowing the user to adjust the contrast, continue |
el18gs | 14:e2b3e645809f | 69 | * by pressing A |
el18gs | 14:e2b3e645809f | 70 | * @param sd pointer to the sd card object |
el18gs | 14:e2b3e645809f | 71 | * @param lcd pointer to the LCD object |
el18gs | 14:e2b3e645809f | 72 | * @param pad pointer to the gamepad object |
el18gs | 14:e2b3e645809f | 73 | * @param g_buttonA_flag pointer to the global variable that will be set to 1 if the A button has been pressed |
el18gs | 14:e2b3e645809f | 74 | */ |
el18gs | 14:e2b3e645809f | 75 | void welcome(SDFileSystem &sd, |
el18gs | 14:e2b3e645809f | 76 | N5110 &lcd, |
el18gs | 14:e2b3e645809f | 77 | Gamepad &pad, |
el18gs | 14:e2b3e645809f | 78 | volatile int &g_buttonA_flag); |
el18gs | 14:e2b3e645809f | 79 | |
el18gs | 14:e2b3e645809f | 80 | /** Display the game menu, there are three options; catch ghosts, inventory, settings |
el18gs | 14:e2b3e645809f | 81 | * @param lcd pointer to the LCD object |
el18gs | 14:e2b3e645809f | 82 | * @param g_buttonA_flag pointer to the global variable that will be set to 1 if the A button has been pressed |
el18gs | 14:e2b3e645809f | 83 | * @param g_buttonB_flag pointer to the global variable that will be set to 1 if the B button has been pressed |
el18gs | 14:e2b3e645809f | 84 | * @param g_buttonX_flag pointer to the global variable that will be set to 1 if the X button has been pressed |
el18gs | 14:e2b3e645809f | 85 | * @return integer relating to which option was selected 'catch ghosts' = 0, 'inventory' = 1, 'settings' = 2 |
el18gs | 14:e2b3e645809f | 86 | * @note use X and B to move the selection up and down, press A to select |
el18gs | 14:e2b3e645809f | 87 | */ |
el18gs | 14:e2b3e645809f | 88 | int game_menu(N5110 &lcd, |
el18gs | 14:e2b3e645809f | 89 | volatile int &g_buttonA_flag, |
el18gs | 14:e2b3e645809f | 90 | volatile int &g_buttonB_flag, |
el18gs | 14:e2b3e645809f | 91 | volatile int &g_buttonX_flag); |
el18gs | 14:e2b3e645809f | 92 | |
el18gs | 14:e2b3e645809f | 93 | /** Provide the user with two challenges if they complete both they will get an extra ghost. |
el18gs | 14:e2b3e645809f | 94 | * The first challenge is rotating the gamepad to the right direction. The seccond is moving a crosshair onto a randomly moving ghost. |
el18gs | 14:e2b3e645809f | 95 | * @note in the seccond the ghost is intentionally jittering and moving quickly as it looks more ghost like |
el18gs | 14:e2b3e645809f | 96 | * @param inventory pointer to the users inventory |
el18gs | 14:e2b3e645809f | 97 | * @param accel pointer to the accelerometer object |
el18gs | 14:e2b3e645809f | 98 | * @param sd pointer to the sd card object |
el18gs | 14:e2b3e645809f | 99 | * @param lcd pointer to the LCD object |
el18gs | 14:e2b3e645809f | 100 | * @param pad pointer to the gamepad object |
el18gs | 14:e2b3e645809f | 101 | * @param g_buttonA_flag pointer to the global variable that will be set to 1 |
el18gs | 14:e2b3e645809f | 102 | * if the A button has been pressed |
el18gs | 14:e2b3e645809f | 103 | * @param left_LED pointer to the bus out object representing the left LED's |
el18gs | 14:e2b3e645809f | 104 | * @param right_LED pointer to the bus out object representing the right LED's |
el18gs | 14:e2b3e645809f | 105 | */ |
el18gs | 14:e2b3e645809f | 106 | void catch_ghosts(Inventory &inventory, |
el18gs | 14:e2b3e645809f | 107 | FX0S8700CQ &accel, |
el18gs | 14:e2b3e645809f | 108 | SDFileSystem &sd, |
el18gs | 14:e2b3e645809f | 109 | N5110 &lcd, |
el18gs | 14:e2b3e645809f | 110 | Gamepad &pad, |
el18gs | 14:e2b3e645809f | 111 | volatile int &g_buttonA_flag, |
el18gs | 14:e2b3e645809f | 112 | BusOut &left_LED, |
el18gs | 14:e2b3e645809f | 113 | BusOut &right_LED); |
el18gs | 14:e2b3e645809f | 114 | |
el18gs | 14:e2b3e645809f | 115 | /** Settings menu alows the user to change the contrast and button delay time |
el18gs | 14:e2b3e645809f | 116 | * (how long the game waits after a button press) |
el18gs | 14:e2b3e645809f | 117 | * @note contrast is limited to 0.4 to 0..6 |
el18gs | 14:e2b3e645809f | 118 | * @note use X and B to move up and down respectivly and A to select the option |
el18gs | 14:e2b3e645809f | 119 | * @todo change button sensitivity to background timer that won't allow the |
el18gs | 14:e2b3e645809f | 120 | * button to be set again until a period of time has passed (note other functions |
el18gs | 14:e2b3e645809f | 121 | * may happen in the meantime) |
el18gs | 14:e2b3e645809f | 122 | * @todo add a method of saving the settings for future use |
el18gs | 14:e2b3e645809f | 123 | * @param lcd pointer to the LCD object |
el18gs | 14:e2b3e645809f | 124 | * @param pad pointer to the gamepad object |
el18gs | 14:e2b3e645809f | 125 | * @param g_buttonA_flag pointer to the global variable that will be set to 1 if the A button has been pressed |
el18gs | 14:e2b3e645809f | 126 | * @param g_buttonX_flag pointer to the global variable that will be set to 1 if the X button has been pressed |
el18gs | 14:e2b3e645809f | 127 | * @param g_buttonB_flag pointer to the global variable that will be set to 1 if the B button has been pressed |
el18gs | 15:598baed15751 | 128 | * @param g_buttonStart_flag pointer to the global variable that will be set to 1 if the Start button has been pressed |
el18gs | 14:e2b3e645809f | 129 | * @param g_buttonTesting to the global variable that tells button X to use g_buttonSensitivityTest as its wait |
el18gs | 14:e2b3e645809f | 130 | * time not g_buttonSensitivity |
el18gs | 14:e2b3e645809f | 131 | * @param g_buttonSensitivityTest to the global variable that acts as a tempory waiting time the X button during testing |
el18gs | 14:e2b3e645809f | 132 | * this is to allow the user to test the setting before saving it |
el18gs | 14:e2b3e645809f | 133 | * @param g_buttonSensitivity pointer to the global variable that tells the buttons how long to wait after being pressed |
el18gs | 14:e2b3e645809f | 134 | */ |
el18gs | 14:e2b3e645809f | 135 | void settings(N5110 &lcd, |
el18gs | 14:e2b3e645809f | 136 | Gamepad &pad, |
el18gs | 14:e2b3e645809f | 137 | volatile int &g_buttonA_flag, |
el18gs | 14:e2b3e645809f | 138 | volatile int &g_buttonX_flag, |
el18gs | 14:e2b3e645809f | 139 | volatile int &g_buttonB_flag, |
el18gs | 15:598baed15751 | 140 | volatile int &g_buttonStart_flag, |
el18gs | 14:e2b3e645809f | 141 | volatile bool &g_buttonTesting, |
el18gs | 14:e2b3e645809f | 142 | volatile int &g_buttonSensitivityTest, |
el18gs | 14:e2b3e645809f | 143 | volatile int &g_buttonSensitivity); |
el18gs | 13:3b2a4e14937b | 144 | |
el18gs | 13:3b2a4e14937b | 145 | private: |
el18gs | 14:e2b3e645809f | 146 | void adjustContrast(N5110 &lcd, |
el18gs | 14:e2b3e645809f | 147 | Gamepad &pad, |
el18gs | 14:e2b3e645809f | 148 | volatile int &g_buttonA_flag); |
el18gs | 14:e2b3e645809f | 149 | |
el18gs | 13:3b2a4e14937b | 150 | void buttonDelay(N5110 &lcd, |
el18gs | 13:3b2a4e14937b | 151 | Gamepad &pad, |
el18gs | 13:3b2a4e14937b | 152 | volatile int &g_buttonA_flag, |
el18gs | 13:3b2a4e14937b | 153 | volatile int &g_buttonX_flag, |
el18gs | 13:3b2a4e14937b | 154 | volatile bool &g_buttonTesting, |
el18gs | 13:3b2a4e14937b | 155 | volatile int &g_buttonSensitivityTest, |
el18gs | 13:3b2a4e14937b | 156 | volatile int &g_buttonSensitivity); |
el18gs | 14:e2b3e645809f | 157 | |
el18gs | 14:e2b3e645809f | 158 | void ghostCatchTrial(FX0S8700CQ &accel, |
el18gs | 14:e2b3e645809f | 159 | N5110 &lcd, |
el18gs | 14:e2b3e645809f | 160 | SDFileSystem &sd, |
el18gs | 14:e2b3e645809f | 161 | Gamepad &pad, |
el18gs | 14:e2b3e645809f | 162 | BusOut &left_LED, |
el18gs | 14:e2b3e645809f | 163 | BusOut &right_LED, |
el18gs | 14:e2b3e645809f | 164 | volatile int &g_buttonA_flag); |
el18gs | 14:e2b3e645809f | 165 | |
el18gs | 14:e2b3e645809f | 166 | void angleDetectionTechnicalSub(FX0S8700CQ &accel, |
el18gs | 14:e2b3e645809f | 167 | BusOut &left_LED, |
el18gs | 14:e2b3e645809f | 168 | BusOut &right_LED); |
el18gs | 14:e2b3e645809f | 169 | |
el18gs | 14:e2b3e645809f | 170 | bool drawCrosshairs(Vector2D ideal, |
el18gs | 14:e2b3e645809f | 171 | int** ghost, |
el18gs | 14:e2b3e645809f | 172 | N5110 &lcd, |
el18gs | 14:e2b3e645809f | 173 | Gamepad &pad, |
el18gs | 14:e2b3e645809f | 174 | volatile int g_buttonA_flag); |
el18gs | 14:e2b3e645809f | 175 | |
el18gs | 13:3b2a4e14937b | 176 | void randomMove(Vector2D &ideal); |
el18gs | 14:e2b3e645809f | 177 | |
el18gs | 14:e2b3e645809f | 178 | bool ghostHit( int xGhost, |
el18gs | 14:e2b3e645809f | 179 | int yGhost, |
el18gs | 14:e2b3e645809f | 180 | int xJoy, |
el18gs | 14:e2b3e645809f | 181 | int yJoy); |
el18gs | 13:3b2a4e14937b | 182 | }; |
el18gs | 13:3b2a4e14937b | 183 | |
el18gs | 13:3b2a4e14937b | 184 | #endif |