![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
contains my game for the embedded systems project 2645
Dependencies: mbed FXOS8700CQQQ
GameEngine/RocketRacer.h@28:39607fb67e88, 2019-04-24 (annotated)
- Committer:
- OmarAlebiary
- Date:
- Wed Apr 24 10:19:07 2019 +0000
- Revision:
- 28:39607fb67e88
- Parent:
- 27:771d186b1bc8
- Child:
- 29:e660274d8222
added doxygen comments to RocketRacer.h
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 | 25:7e3b6df93dd5 | 10 | |
OmarAlebiary | 17:989ff25612ad | 11 | /** RocketRacer class |
OmarAlebiary | 6:958376d55d70 | 12 | |
OmarAlebiary | 17:989ff25612ad | 13 | @brief C++ class containing the game methods and the interface |
OmarAlebiary | 17:989ff25612ad | 14 | |
OmarAlebiary | 17:989ff25612ad | 15 | @version 1.0 |
OmarAlebiary | 17:989ff25612ad | 16 | |
OmarAlebiary | 17:989ff25612ad | 17 | @author Omar Alebiary |
OmarAlebiary | 17:989ff25612ad | 18 | |
OmarAlebiary | 17:989ff25612ad | 19 | @date April 2019 |
OmarAlebiary | 17:989ff25612ad | 20 | |
OmarAlebiary | 17:989ff25612ad | 21 | @code |
OmarAlebiary | 17:989ff25612ad | 22 | #include "mbed.h" |
OmarAlebiary | 17:989ff25612ad | 23 | #include "N5110.h" |
OmarAlebiary | 17:989ff25612ad | 24 | #include "Gamepad.h" |
OmarAlebiary | 17:989ff25612ad | 25 | #include "RocketRacer.h" |
OmarAlebiary | 17:989ff25612ad | 26 | |
OmarAlebiary | 17:989ff25612ad | 27 | // objects |
OmarAlebiary | 17:989ff25612ad | 28 | Gamepad pad; |
OmarAlebiary | 17:989ff25612ad | 29 | RocketRacer rc; |
OmarAlebiary | 28:39607fb67e88 | 30 | |
OmarAlebiary | 19:ad9dc8e418c9 | 31 | |
OmarAlebiary | 17:989ff25612ad | 32 | // prototypes |
OmarAlebiary | 17:989ff25612ad | 33 | void setup(); |
OmarAlebiary | 17:989ff25612ad | 34 | |
OmarAlebiary | 17:989ff25612ad | 35 | int main(){ |
OmarAlebiary | 17:989ff25612ad | 36 | |
OmarAlebiary | 28:39607fb67e88 | 37 | //initializes the gamepad and the lcd |
OmarAlebiary | 17:989ff25612ad | 38 | setup(); |
OmarAlebiary | 28:39607fb67e88 | 39 | |
OmarAlebiary | 28:39607fb67e88 | 40 | // this method displays the game scoresand frames |
OmarAlebiary | 28:39607fb67e88 | 41 | // used in the gameplay |
OmarAlebiary | 28:39607fb67e88 | 42 | |
OmarAlebiary | 28:39607fb67e88 | 43 | Rocket_Racer.Main_Game_Display(lcd); |
OmarAlebiary | 28:39607fb67e88 | 44 | |
OmarAlebiary | 28:39607fb67e88 | 45 | // this method checks the joystick position |
OmarAlebiary | 28:39607fb67e88 | 46 | // if it's right prints "its right" else if its |
OmarAlebiary | 28:39607fb67e88 | 47 | // left prints "its left" else prints "centre" |
OmarAlebiary | 28:39607fb67e88 | 48 | Rocket_Racer.Joystick_position(pad); |
OmarAlebiary | 28:39607fb67e88 | 49 | //this method generates a random number between 1 and 3 |
OmarAlebiary | 28:39607fb67e88 | 50 | //and prints it to the terminal |
OmarAlebiary | 28:39607fb67e88 | 51 | Rocket_Racer.Generate_New_Enemy(); |
OmarAlebiary | 28:39607fb67e88 | 52 | //this method checks if the rocket collide with the enemy |
OmarAlebiary | 28:39607fb67e88 | 53 | //and displays game over screen |
OmarAlebiary | 28:39607fb67e88 | 54 | Rocket_Racer.Check_Enemy_Dead(lcd,pad); |
OmarAlebiary | 28:39607fb67e88 | 55 | //main game loop that has all the method calls in it |
OmarAlebiary | 17:989ff25612ad | 56 | while(1){ |
OmarAlebiary | 22:3e6ff378d651 | 57 | Rocket_Racer.Game_Loop(lcd,pad); |
OmarAlebiary | 17:989ff25612ad | 58 | } |
OmarAlebiary | 28:39607fb67e88 | 59 | //method that adds difficulty to the game |
OmarAlebiary | 28:39607fb67e88 | 60 | //and has 6 levels of difficulty |
OmarAlebiary | 28:39607fb67e88 | 61 | Rocket_Racer.Game_difficulty(pad); |
OmarAlebiary | 28:39607fb67e88 | 62 | //this method places the enemy sprite according |
OmarAlebiary | 28:39607fb67e88 | 63 | //to the randomly generated number(1->3)& the current phase |
OmarAlebiary | 28:39607fb67e88 | 64 | //i added the 2nd and 3rd argument manually for testing |
OmarAlebiary | 28:39607fb67e88 | 65 | Rocket_Racer.enemy_position(lcd,2,3); |
OmarAlebiary | 28:39607fb67e88 | 66 | //this method places the player sprite |
OmarAlebiary | 28:39607fb67e88 | 67 | //according to the postion of the joystick |
OmarAlebiary | 28:39607fb67e88 | 68 | //i added the 2nd argument manually for testing |
OmarAlebiary | 28:39607fb67e88 | 69 | Rocket_Racer.player_position(lcd, 3); |
OmarAlebiary | 28:39607fb67e88 | 70 | //this method displays the gameover screen |
OmarAlebiary | 28:39607fb67e88 | 71 | //and the high score achieved |
OmarAlebiary | 28:39607fb67e88 | 72 | Rocket_Racer.End_Game(pad,lcd); |
OmarAlebiary | 17:989ff25612ad | 73 | |
OmarAlebiary | 17:989ff25612ad | 74 | |
OmarAlebiary | 17:989ff25612ad | 75 | } |
OmarAlebiary | 17:989ff25612ad | 76 | |
OmarAlebiary | 17:989ff25612ad | 77 | @endcode |
OmarAlebiary | 17:989ff25612ad | 78 | */ |
OmarAlebiary | 16:93a8147a4358 | 79 | |
OmarAlebiary | 6:958376d55d70 | 80 | |
OmarAlebiary | 6:958376d55d70 | 81 | class RocketRacer{ |
OmarAlebiary | 6:958376d55d70 | 82 | |
OmarAlebiary | 6:958376d55d70 | 83 | public: |
OmarAlebiary | 17:989ff25612ad | 84 | /** |
OmarAlebiary | 17:989ff25612ad | 85 | * @brief Default Constuctor |
OmarAlebiary | 17:989ff25612ad | 86 | * @param None @details Creates the object of class RocketRacer |
OmarAlebiary | 17:989ff25612ad | 87 | */ |
OmarAlebiary | 13:cec06eb1d7b0 | 88 | RocketRacer(); |
OmarAlebiary | 17:989ff25612ad | 89 | |
OmarAlebiary | 13:cec06eb1d7b0 | 90 | |
OmarAlebiary | 17:989ff25612ad | 91 | /** |
OmarAlebiary | 17:989ff25612ad | 92 | * @brief method that has all the screen rendering |
OmarAlebiary | 17:989ff25612ad | 93 | * @param lcd @details calls the lcd object to draw strings and objects on the display |
OmarAlebiary | 17:989ff25612ad | 94 | */ |
OmarAlebiary | 12:1d3b0218d8d0 | 95 | void Main_Game_Display(N5110 &lcd); |
OmarAlebiary | 17:989ff25612ad | 96 | /** |
OmarAlebiary | 17:989ff25612ad | 97 | * @brief method that dispalys the game over screen with the high score achieved |
OmarAlebiary | 17:989ff25612ad | 98 | * @param lcd @details calls the lcd object to draw strings on the display |
OmarAlebiary | 17:989ff25612ad | 99 | * @param pad @details calls the Gamepad object to access methods from the Gamepad class |
OmarAlebiary | 17:989ff25612ad | 100 | */ |
OmarAlebiary | 12:1d3b0218d8d0 | 101 | void End_Game(Gamepad &pad,N5110 &lcd); |
OmarAlebiary | 13:cec06eb1d7b0 | 102 | |
OmarAlebiary | 17:989ff25612ad | 103 | /** |
OmarAlebiary | 17:989ff25612ad | 104 | * @brief method that adds difficulty to the game after proceeding each level |
OmarAlebiary | 17:989ff25612ad | 105 | * @param pad @details calls the Gamepad object to access methods from the Gamepad class |
OmarAlebiary | 17:989ff25612ad | 106 | */ |
OmarAlebiary | 12:1d3b0218d8d0 | 107 | void Game_difficulty(Gamepad &pad); |
OmarAlebiary | 17:989ff25612ad | 108 | |
OmarAlebiary | 17:989ff25612ad | 109 | /** |
OmarAlebiary | 17:989ff25612ad | 110 | * @brief method that generates random enemies |
OmarAlebiary | 17:989ff25612ad | 111 | * @param none @details seeds the rand function then generate a random enemies |
OmarAlebiary | 17:989ff25612ad | 112 | */ |
OmarAlebiary | 11:d4aaa959bb20 | 113 | void Generate_New_Enemy(); |
OmarAlebiary | 17:989ff25612ad | 114 | /** |
OmarAlebiary | 17:989ff25612ad | 115 | * @brief method that checks if the randomly generated enemies crossed the player |
OmarAlebiary | 17:989ff25612ad | 116 | * and calls the End_Game method accordingly if they collide else increments the score |
OmarAlebiary | 17:989ff25612ad | 117 | * @param lcd @details calls the lcd object to be passed to the End_Game method |
OmarAlebiary | 17:989ff25612ad | 118 | * @param pad @details calls the Gamepad object to be passed to the End_Game method |
OmarAlebiary | 17:989ff25612ad | 119 | */ |
OmarAlebiary | 11:d4aaa959bb20 | 120 | void Check_Enemy_Dead(N5110 &lcd,Gamepad &pad); |
OmarAlebiary | 17:989ff25612ad | 121 | /** |
OmarAlebiary | 17:989ff25612ad | 122 | * @brief method that checks the joystick (and L &R buttons) direction whether its left,right or centre |
OmarAlebiary | 17:989ff25612ad | 123 | * and increment or decrement according to the current position |
OmarAlebiary | 17:989ff25612ad | 124 | * @param pad @details calls the Gamepad object to access the get_direction method from the Gamepad class |
OmarAlebiary | 17:989ff25612ad | 125 | */ |
OmarAlebiary | 11:d4aaa959bb20 | 126 | void Joystick_position(Gamepad &pad); |
OmarAlebiary | 17:989ff25612ad | 127 | /** |
OmarAlebiary | 17:989ff25612ad | 128 | * @brief method that has the game loop which calls all the methods(from the same class)for the game to operate |
OmarAlebiary | 17:989ff25612ad | 129 | * @param lcd @details calls the lcd object to be passed to the methods called inside this method |
OmarAlebiary | 17:989ff25612ad | 130 | * @param pad @details calls the Gamepad object to be passed to the methods called inside this method |
OmarAlebiary | 17:989ff25612ad | 131 | */ |
OmarAlebiary | 12:1d3b0218d8d0 | 132 | void Game_Loop(N5110 &lcd,Gamepad &pad); |
OmarAlebiary | 17:989ff25612ad | 133 | /** |
OmarAlebiary | 17:989ff25612ad | 134 | * @brief method that draws the rocket sprite according to the player position |
OmarAlebiary | 17:989ff25612ad | 135 | * @param lcd @details calls the lcd object to access the drawSprite method |
OmarAlebiary | 17:989ff25612ad | 136 | * @param RocketPosition @details the position of the rocket |
OmarAlebiary | 17:989ff25612ad | 137 | */ |
OmarAlebiary | 9:edb39a8334ee | 138 | void player_position(N5110 &lcd,char RocketPosition); |
OmarAlebiary | 17:989ff25612ad | 139 | /** |
OmarAlebiary | 17:989ff25612ad | 140 | * @brief method that draws the enemy sprite |
OmarAlebiary | 17:989ff25612ad | 141 | * @param lcd @details calls the lcd object to access the drawSprite method |
OmarAlebiary | 17:989ff25612ad | 142 | * @param place @details the position of the rocket |
OmarAlebiary | 17:989ff25612ad | 143 | * @param phase @details the phase of the rocket |
OmarAlebiary | 17:989ff25612ad | 144 | */ |
OmarAlebiary | 9:edb39a8334ee | 145 | void enemy_position(N5110 &lcd,int place, int phase); |
OmarAlebiary | 28:39607fb67e88 | 146 | |
OmarAlebiary | 28:39607fb67e88 | 147 | |
OmarAlebiary | 9:edb39a8334ee | 148 | |
OmarAlebiary | 9:edb39a8334ee | 149 | private: |
OmarAlebiary | 28:39607fb67e88 | 150 | |
OmarAlebiary | 15:8a768106c297 | 151 | int first_enemy_position; |
OmarAlebiary | 15:8a768106c297 | 152 | int second_enemy_position; |
OmarAlebiary | 15:8a768106c297 | 153 | int enemy_phase; |
OmarAlebiary | 13:cec06eb1d7b0 | 154 | int game_speed; |
OmarAlebiary | 13:cec06eb1d7b0 | 155 | int score; |
OmarAlebiary | 14:8df7e6fced07 | 156 | char Init_position; |
OmarAlebiary | 13:cec06eb1d7b0 | 157 | bool enemy_dead; |
OmarAlebiary | 13:cec06eb1d7b0 | 158 | bool control; |
OmarAlebiary | 28:39607fb67e88 | 159 | GameTones tones; |
OmarAlebiary | 28:39607fb67e88 | 160 | |
OmarAlebiary | 6:958376d55d70 | 161 | }; |
OmarAlebiary | 6:958376d55d70 | 162 | |
OmarAlebiary | 6:958376d55d70 | 163 | #endif |