![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
contains my game for the embedded systems project 2645
Dependencies: mbed FXOS8700CQQQ
GameEngine/RocketRacer.h@31:4d4a9d78cae5, 2019-04-28 (annotated)
- Committer:
- OmarAlebiary
- Date:
- Sun Apr 28 02:43:58 2019 +0000
- Revision:
- 31:4d4a9d78cae5
- Parent:
- 30:c5060010a1e6
- Child:
- 35:4c9b39c6fd72
fixed instructions menu not showing properly
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OmarAlebiary | 6:958376d55d70 | 1 | #ifndef ROCKETRACER_H |
OmarAlebiary | 6:958376d55d70 | 2 | #define ROCKETRACER_H |
OmarAlebiary | 6:958376d55d70 | 3 | #include "mbed.h" |
OmarAlebiary | 6:958376d55d70 | 4 | #include "N5110.h" |
OmarAlebiary | 9:edb39a8334ee | 5 | #include <cstdlib> |
OmarAlebiary | 9:edb39a8334ee | 6 | #include <ctime> |
OmarAlebiary | 6:958376d55d70 | 7 | #include "Gamepad.h" |
OmarAlebiary | 27:771d186b1bc8 | 8 | #include "GameSprites.h" |
OmarAlebiary | 28:39607fb67e88 | 9 | #include "GameTones.h" |
OmarAlebiary | 30:c5060010a1e6 | 10 | #include "FXOS8700CQ.h" |
OmarAlebiary | 29:e660274d8222 | 11 | |
OmarAlebiary | 17:989ff25612ad | 12 | /** RocketRacer class |
OmarAlebiary | 6:958376d55d70 | 13 | |
OmarAlebiary | 30:c5060010a1e6 | 14 | @brief University of Leeds,C++ class containing the game methods and the interface |
OmarAlebiary | 17:989ff25612ad | 15 | |
OmarAlebiary | 17:989ff25612ad | 16 | @version 1.0 |
OmarAlebiary | 17:989ff25612ad | 17 | |
OmarAlebiary | 17:989ff25612ad | 18 | @author Omar Alebiary |
OmarAlebiary | 17:989ff25612ad | 19 | |
OmarAlebiary | 17:989ff25612ad | 20 | @date April 2019 |
OmarAlebiary | 17:989ff25612ad | 21 | |
OmarAlebiary | 17:989ff25612ad | 22 | @code |
OmarAlebiary | 17:989ff25612ad | 23 | #include "mbed.h" |
OmarAlebiary | 17:989ff25612ad | 24 | #include "N5110.h" |
OmarAlebiary | 17:989ff25612ad | 25 | #include "Gamepad.h" |
OmarAlebiary | 17:989ff25612ad | 26 | #include "RocketRacer.h" |
OmarAlebiary | 17:989ff25612ad | 27 | |
OmarAlebiary | 17:989ff25612ad | 28 | // objects |
OmarAlebiary | 17:989ff25612ad | 29 | Gamepad pad; |
OmarAlebiary | 29:e660274d8222 | 30 | RocketRacer Rocket_Racer; |
OmarAlebiary | 28:39607fb67e88 | 31 | |
OmarAlebiary | 19:ad9dc8e418c9 | 32 | |
OmarAlebiary | 17:989ff25612ad | 33 | // prototypes |
OmarAlebiary | 17:989ff25612ad | 34 | void setup(); |
OmarAlebiary | 17:989ff25612ad | 35 | |
OmarAlebiary | 17:989ff25612ad | 36 | int main(){ |
OmarAlebiary | 17:989ff25612ad | 37 | |
OmarAlebiary | 28:39607fb67e88 | 38 | //initializes the gamepad and the lcd |
OmarAlebiary | 17:989ff25612ad | 39 | setup(); |
OmarAlebiary | 28:39607fb67e88 | 40 | |
OmarAlebiary | 28:39607fb67e88 | 41 | // this method displays the game scoresand frames |
OmarAlebiary | 28:39607fb67e88 | 42 | // used in the gameplay |
OmarAlebiary | 28:39607fb67e88 | 43 | |
OmarAlebiary | 28:39607fb67e88 | 44 | Rocket_Racer.Main_Game_Display(lcd); |
OmarAlebiary | 28:39607fb67e88 | 45 | |
OmarAlebiary | 28:39607fb67e88 | 46 | // this method checks the joystick position |
OmarAlebiary | 28:39607fb67e88 | 47 | // if it's right prints "its right" else if its |
OmarAlebiary | 28:39607fb67e88 | 48 | // left prints "its left" else prints "centre" |
OmarAlebiary | 28:39607fb67e88 | 49 | Rocket_Racer.Joystick_position(pad); |
OmarAlebiary | 28:39607fb67e88 | 50 | //this method generates a random number between 1 and 3 |
OmarAlebiary | 28:39607fb67e88 | 51 | //and prints it to the terminal |
OmarAlebiary | 28:39607fb67e88 | 52 | Rocket_Racer.Generate_New_Enemy(); |
OmarAlebiary | 28:39607fb67e88 | 53 | //this method checks if the rocket collide with the enemy |
OmarAlebiary | 28:39607fb67e88 | 54 | //and displays game over screen |
OmarAlebiary | 28:39607fb67e88 | 55 | Rocket_Racer.Check_Enemy_Dead(lcd,pad); |
OmarAlebiary | 28:39607fb67e88 | 56 | //main game loop that has all the method calls in it |
OmarAlebiary | 17:989ff25612ad | 57 | while(1){ |
OmarAlebiary | 22:3e6ff378d651 | 58 | Rocket_Racer.Game_Loop(lcd,pad); |
OmarAlebiary | 17:989ff25612ad | 59 | } |
OmarAlebiary | 28:39607fb67e88 | 60 | //method that adds difficulty to the game |
OmarAlebiary | 28:39607fb67e88 | 61 | //and has 6 levels of difficulty |
OmarAlebiary | 28:39607fb67e88 | 62 | Rocket_Racer.Game_difficulty(pad); |
OmarAlebiary | 28:39607fb67e88 | 63 | //this method places the enemy sprite according |
OmarAlebiary | 28:39607fb67e88 | 64 | //to the randomly generated number(1->3)& the current phase |
OmarAlebiary | 28:39607fb67e88 | 65 | //i added the 2nd and 3rd argument manually for testing |
OmarAlebiary | 28:39607fb67e88 | 66 | Rocket_Racer.enemy_position(lcd,2,3); |
OmarAlebiary | 28:39607fb67e88 | 67 | //this method places the player sprite |
OmarAlebiary | 28:39607fb67e88 | 68 | //according to the postion of the joystick |
OmarAlebiary | 28:39607fb67e88 | 69 | //i added the 2nd argument manually for testing |
OmarAlebiary | 28:39607fb67e88 | 70 | Rocket_Racer.player_position(lcd, 3); |
OmarAlebiary | 28:39607fb67e88 | 71 | //this method displays the gameover screen |
OmarAlebiary | 28:39607fb67e88 | 72 | //and the high score achieved |
OmarAlebiary | 28:39607fb67e88 | 73 | Rocket_Racer.End_Game(pad,lcd); |
OmarAlebiary | 17:989ff25612ad | 74 | |
OmarAlebiary | 17:989ff25612ad | 75 | |
OmarAlebiary | 17:989ff25612ad | 76 | } |
OmarAlebiary | 17:989ff25612ad | 77 | |
OmarAlebiary | 17:989ff25612ad | 78 | @endcode |
OmarAlebiary | 17:989ff25612ad | 79 | */ |
OmarAlebiary | 16:93a8147a4358 | 80 | |
OmarAlebiary | 6:958376d55d70 | 81 | |
OmarAlebiary | 6:958376d55d70 | 82 | class RocketRacer{ |
OmarAlebiary | 6:958376d55d70 | 83 | |
OmarAlebiary | 6:958376d55d70 | 84 | public: |
OmarAlebiary | 17:989ff25612ad | 85 | /** |
OmarAlebiary | 29:e660274d8222 | 86 | * @brief Default Constructor |
OmarAlebiary | 29:e660274d8222 | 87 | * @details Creates the object of class RocketRacer |
OmarAlebiary | 17:989ff25612ad | 88 | */ |
OmarAlebiary | 13:cec06eb1d7b0 | 89 | RocketRacer(); |
OmarAlebiary | 29:e660274d8222 | 90 | /** |
OmarAlebiary | 29:e660274d8222 | 91 | * @brief Default destructor |
OmarAlebiary | 29:e660274d8222 | 92 | * @details destroys the object of class RocketRacer |
OmarAlebiary | 29:e660274d8222 | 93 | */ |
OmarAlebiary | 29:e660274d8222 | 94 | ~RocketRacer(); |
OmarAlebiary | 17:989ff25612ad | 95 | /** |
OmarAlebiary | 17:989ff25612ad | 96 | * @brief method that has all the screen rendering |
OmarAlebiary | 17:989ff25612ad | 97 | * @param lcd @details calls the lcd object to draw strings and objects on the display |
OmarAlebiary | 17:989ff25612ad | 98 | */ |
OmarAlebiary | 12:1d3b0218d8d0 | 99 | void Main_Game_Display(N5110 &lcd); |
OmarAlebiary | 17:989ff25612ad | 100 | /** |
OmarAlebiary | 17:989ff25612ad | 101 | * @brief method that dispalys the game over screen with the high score achieved |
OmarAlebiary | 17:989ff25612ad | 102 | * @param lcd @details calls the lcd object to draw strings on the display |
OmarAlebiary | 17:989ff25612ad | 103 | * @param pad @details calls the Gamepad object to access methods from the Gamepad class |
OmarAlebiary | 17:989ff25612ad | 104 | */ |
OmarAlebiary | 12:1d3b0218d8d0 | 105 | void End_Game(Gamepad &pad,N5110 &lcd); |
OmarAlebiary | 13:cec06eb1d7b0 | 106 | |
OmarAlebiary | 17:989ff25612ad | 107 | /** |
OmarAlebiary | 17:989ff25612ad | 108 | * @brief method that adds difficulty to the game after proceeding each level |
OmarAlebiary | 17:989ff25612ad | 109 | * @param pad @details calls the Gamepad object to access methods from the Gamepad class |
OmarAlebiary | 17:989ff25612ad | 110 | */ |
OmarAlebiary | 12:1d3b0218d8d0 | 111 | void Game_difficulty(Gamepad &pad); |
OmarAlebiary | 17:989ff25612ad | 112 | |
OmarAlebiary | 17:989ff25612ad | 113 | /** |
OmarAlebiary | 17:989ff25612ad | 114 | * @brief method that generates random enemies |
OmarAlebiary | 17:989ff25612ad | 115 | * @param none @details seeds the rand function then generate a random enemies |
OmarAlebiary | 17:989ff25612ad | 116 | */ |
OmarAlebiary | 11:d4aaa959bb20 | 117 | void Generate_New_Enemy(); |
OmarAlebiary | 17:989ff25612ad | 118 | /** |
OmarAlebiary | 17:989ff25612ad | 119 | * @brief method that checks if the randomly generated enemies crossed the player |
OmarAlebiary | 17:989ff25612ad | 120 | * and calls the End_Game method accordingly if they collide else increments the score |
OmarAlebiary | 17:989ff25612ad | 121 | * @param lcd @details calls the lcd object to be passed to the End_Game method |
OmarAlebiary | 17:989ff25612ad | 122 | * @param pad @details calls the Gamepad object to be passed to the End_Game method |
OmarAlebiary | 17:989ff25612ad | 123 | */ |
OmarAlebiary | 11:d4aaa959bb20 | 124 | void Check_Enemy_Dead(N5110 &lcd,Gamepad &pad); |
OmarAlebiary | 17:989ff25612ad | 125 | /** |
OmarAlebiary | 17:989ff25612ad | 126 | * @brief method that checks the joystick (and L &R buttons) direction whether its left,right or centre |
OmarAlebiary | 17:989ff25612ad | 127 | * and increment or decrement according to the current position |
OmarAlebiary | 17:989ff25612ad | 128 | * @param pad @details calls the Gamepad object to access the get_direction method from the Gamepad class |
OmarAlebiary | 17:989ff25612ad | 129 | */ |
OmarAlebiary | 11:d4aaa959bb20 | 130 | void Joystick_position(Gamepad &pad); |
OmarAlebiary | 17:989ff25612ad | 131 | /** |
OmarAlebiary | 17:989ff25612ad | 132 | * @brief method that has the game loop which calls all the methods(from the same class)for the game to operate |
OmarAlebiary | 17:989ff25612ad | 133 | * @param lcd @details calls the lcd object to be passed to the methods called inside this method |
OmarAlebiary | 17:989ff25612ad | 134 | * @param pad @details calls the Gamepad object to be passed to the methods called inside this method |
OmarAlebiary | 17:989ff25612ad | 135 | */ |
OmarAlebiary | 12:1d3b0218d8d0 | 136 | void Game_Loop(N5110 &lcd,Gamepad &pad); |
OmarAlebiary | 17:989ff25612ad | 137 | /** |
OmarAlebiary | 17:989ff25612ad | 138 | * @brief method that draws the rocket sprite according to the player position |
OmarAlebiary | 17:989ff25612ad | 139 | * @param lcd @details calls the lcd object to access the drawSprite method |
OmarAlebiary | 17:989ff25612ad | 140 | * @param RocketPosition @details the position of the rocket |
OmarAlebiary | 17:989ff25612ad | 141 | */ |
OmarAlebiary | 9:edb39a8334ee | 142 | void player_position(N5110 &lcd,char RocketPosition); |
OmarAlebiary | 17:989ff25612ad | 143 | /** |
OmarAlebiary | 17:989ff25612ad | 144 | * @brief method that draws the enemy sprite |
OmarAlebiary | 17:989ff25612ad | 145 | * @param lcd @details calls the lcd object to access the drawSprite method |
OmarAlebiary | 17:989ff25612ad | 146 | * @param place @details the position of the rocket |
OmarAlebiary | 17:989ff25612ad | 147 | * @param phase @details the phase of the rocket |
OmarAlebiary | 17:989ff25612ad | 148 | */ |
OmarAlebiary | 9:edb39a8334ee | 149 | void enemy_position(N5110 &lcd,int place, int phase); |
OmarAlebiary | 29:e660274d8222 | 150 | /** |
OmarAlebiary | 29:e660274d8222 | 151 | * @brief Sets the position |
OmarAlebiary | 29:e660274d8222 | 152 | * @param first_enemy_position @details position of the first enemy (as an int) |
OmarAlebiary | 29:e660274d8222 | 153 | */ |
OmarAlebiary | 29:e660274d8222 | 154 | void set_first_position(int first_enemy_position); |
OmarAlebiary | 29:e660274d8222 | 155 | /** |
OmarAlebiary | 29:e660274d8222 | 156 | * @brief Sets the position |
OmarAlebiary | 29:e660274d8222 | 157 | * @param second_enemy_position @details position of the second enemy (as an int) |
OmarAlebiary | 29:e660274d8222 | 158 | */ |
OmarAlebiary | 29:e660274d8222 | 159 | void set_second_position(int second_enemy_position); |
OmarAlebiary | 29:e660274d8222 | 160 | /** |
OmarAlebiary | 29:e660274d8222 | 161 | * @brief Sets the phase |
OmarAlebiary | 29:e660274d8222 | 162 | * @param enemy_phase @details phase of the enemy (as an int) |
OmarAlebiary | 29:e660274d8222 | 163 | */ |
OmarAlebiary | 29:e660274d8222 | 164 | void set_enemy_phase(int enemy_phase); |
OmarAlebiary | 29:e660274d8222 | 165 | /** |
OmarAlebiary | 29:e660274d8222 | 166 | * @brief Sets the game speed |
OmarAlebiary | 29:e660274d8222 | 167 | * @param game_speed @details speed of the game (as an int) |
OmarAlebiary | 29:e660274d8222 | 168 | */ |
OmarAlebiary | 29:e660274d8222 | 169 | void set_game_speed(int game_speed); |
OmarAlebiary | 29:e660274d8222 | 170 | /** |
OmarAlebiary | 29:e660274d8222 | 171 | * @brief Sets the game score |
OmarAlebiary | 29:e660274d8222 | 172 | * @param score @details score of the game (as an int) |
OmarAlebiary | 29:e660274d8222 | 173 | */ |
OmarAlebiary | 29:e660274d8222 | 174 | void set_game_score(int score); |
OmarAlebiary | 29:e660274d8222 | 175 | /** |
OmarAlebiary | 29:e660274d8222 | 176 | * @brief set enemy dead flag |
OmarAlebiary | 29:e660274d8222 | 177 | * @param enemy_dead @details flag to indicate dead enemy(as a bool) |
OmarAlebiary | 29:e660274d8222 | 178 | */ |
OmarAlebiary | 29:e660274d8222 | 179 | void set_enemy_dead(bool enemy_dead) ; |
OmarAlebiary | 29:e660274d8222 | 180 | /** |
OmarAlebiary | 29:e660274d8222 | 181 | * @brief set control flag |
OmarAlebiary | 29:e660274d8222 | 182 | * @param control @details flag for joystick control(as a bool) |
OmarAlebiary | 29:e660274d8222 | 183 | */ |
OmarAlebiary | 29:e660274d8222 | 184 | void set_control(bool control); |
OmarAlebiary | 29:e660274d8222 | 185 | /** |
OmarAlebiary | 29:e660274d8222 | 186 | * @brief set initial position |
OmarAlebiary | 29:e660274d8222 | 187 | * @param Init_position @details initial position of the player(as an int) |
OmarAlebiary | 29:e660274d8222 | 188 | */ |
OmarAlebiary | 29:e660274d8222 | 189 | void set_init_position(int Init_position); |
OmarAlebiary | 30:c5060010a1e6 | 190 | /** |
OmarAlebiary | 30:c5060010a1e6 | 191 | * @brief checks accelerometer positon |
OmarAlebiary | 30:c5060010a1e6 | 192 | * @param Init_position @details initial position of the player(as an int) |
OmarAlebiary | 30:c5060010a1e6 | 193 | * @param pad @details calls the Gamepad object to be passed to the methods called inside this method |
OmarAlebiary | 30:c5060010a1e6 | 194 | */ |
OmarAlebiary | 30:c5060010a1e6 | 195 | void accelerometer_position(Gamepad &pad); |
OmarAlebiary | 30:c5060010a1e6 | 196 | /** |
OmarAlebiary | 30:c5060010a1e6 | 197 | * @brief method that has the game loop which calls all the methods and control with accelerometer |
OmarAlebiary | 30:c5060010a1e6 | 198 | * @param lcd @details calls the lcd object to be passed to the methods called inside this method |
OmarAlebiary | 30:c5060010a1e6 | 199 | * @param pad @details calls the Gamepad object to be passed to the methods called inside this method |
OmarAlebiary | 30:c5060010a1e6 | 200 | */ |
OmarAlebiary | 30:c5060010a1e6 | 201 | void Game_Loop_accelerometer(N5110 &lcd,Gamepad &pad); |
OmarAlebiary | 9:edb39a8334ee | 202 | |
OmarAlebiary | 31:4d4a9d78cae5 | 203 | |
OmarAlebiary | 31:4d4a9d78cae5 | 204 | |
OmarAlebiary | 9:edb39a8334ee | 205 | private: |
OmarAlebiary | 28:39607fb67e88 | 206 | |
OmarAlebiary | 15:8a768106c297 | 207 | int first_enemy_position; |
OmarAlebiary | 15:8a768106c297 | 208 | int second_enemy_position; |
OmarAlebiary | 15:8a768106c297 | 209 | int enemy_phase; |
OmarAlebiary | 13:cec06eb1d7b0 | 210 | int game_speed; |
OmarAlebiary | 13:cec06eb1d7b0 | 211 | int score; |
OmarAlebiary | 14:8df7e6fced07 | 212 | char Init_position; |
OmarAlebiary | 13:cec06eb1d7b0 | 213 | bool enemy_dead; |
OmarAlebiary | 13:cec06eb1d7b0 | 214 | bool control; |
OmarAlebiary | 28:39607fb67e88 | 215 | GameTones tones; |
OmarAlebiary | 28:39607fb67e88 | 216 | |
OmarAlebiary | 29:e660274d8222 | 217 | |
OmarAlebiary | 30:c5060010a1e6 | 218 | |
OmarAlebiary | 6:958376d55d70 | 219 | }; |
OmarAlebiary | 6:958376d55d70 | 220 | |
OmarAlebiary | 6:958376d55d70 | 221 | #endif |