contains my game for the embedded systems project 2645
Dependencies: mbed FXOS8700CQQQ
GameEngine/RocketRacer.h@22:3e6ff378d651, 2019-04-18 (annotated)
- Committer:
- OmarAlebiary
- Date:
- Thu Apr 18 23:13:24 2019 +0000
- Revision:
- 22:3e6ff378d651
- Parent:
- 19:ad9dc8e418c9
- Child:
- 25:7e3b6df93dd5
added Menus.cpp and .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 | |
OmarAlebiary | 6:958376d55d70 | 4 | #include "mbed.h" |
OmarAlebiary | 6:958376d55d70 | 5 | #include "N5110.h" |
OmarAlebiary | 9:edb39a8334ee | 6 | #include <cstdlib> |
OmarAlebiary | 9:edb39a8334ee | 7 | #include <ctime> |
OmarAlebiary | 6:958376d55d70 | 8 | #include "Gamepad.h" |
OmarAlebiary | 6:958376d55d70 | 9 | |
OmarAlebiary | 17:989ff25612ad | 10 | /** RocketRacer class |
OmarAlebiary | 6:958376d55d70 | 11 | |
OmarAlebiary | 17:989ff25612ad | 12 | @brief C++ class containing the game methods and the interface |
OmarAlebiary | 17:989ff25612ad | 13 | |
OmarAlebiary | 17:989ff25612ad | 14 | @version 1.0 |
OmarAlebiary | 17:989ff25612ad | 15 | |
OmarAlebiary | 17:989ff25612ad | 16 | @author Omar Alebiary |
OmarAlebiary | 17:989ff25612ad | 17 | |
OmarAlebiary | 17:989ff25612ad | 18 | @date April 2019 |
OmarAlebiary | 17:989ff25612ad | 19 | |
OmarAlebiary | 17:989ff25612ad | 20 | @code |
OmarAlebiary | 17:989ff25612ad | 21 | |
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 | 22:3e6ff378d651 | 30 | Menus menus; |
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 | 17:989ff25612ad | 37 | |
OmarAlebiary | 17:989ff25612ad | 38 | setup(); |
OmarAlebiary | 22:3e6ff378d651 | 39 | menus.welcomeMenu(pad,lcd); |
OmarAlebiary | 22:3e6ff378d651 | 40 | menus.InstructionsMenu(pad,lcd); |
OmarAlebiary | 22:3e6ff378d651 | 41 | //keeps looping untill the player loses |
OmarAlebiary | 17:989ff25612ad | 42 | while(1){ |
OmarAlebiary | 22:3e6ff378d651 | 43 | Rocket_Racer.Game_Loop(lcd,pad); |
OmarAlebiary | 17:989ff25612ad | 44 | } |
OmarAlebiary | 17:989ff25612ad | 45 | |
OmarAlebiary | 17:989ff25612ad | 46 | |
OmarAlebiary | 17:989ff25612ad | 47 | } |
OmarAlebiary | 17:989ff25612ad | 48 | |
OmarAlebiary | 17:989ff25612ad | 49 | @endcode |
OmarAlebiary | 17:989ff25612ad | 50 | */ |
OmarAlebiary | 16:93a8147a4358 | 51 | |
OmarAlebiary | 6:958376d55d70 | 52 | |
OmarAlebiary | 6:958376d55d70 | 53 | class RocketRacer{ |
OmarAlebiary | 6:958376d55d70 | 54 | |
OmarAlebiary | 6:958376d55d70 | 55 | public: |
OmarAlebiary | 17:989ff25612ad | 56 | /** |
OmarAlebiary | 17:989ff25612ad | 57 | * @brief Default Constuctor |
OmarAlebiary | 17:989ff25612ad | 58 | * @param None @details Creates the object of class RocketRacer |
OmarAlebiary | 17:989ff25612ad | 59 | */ |
OmarAlebiary | 13:cec06eb1d7b0 | 60 | RocketRacer(); |
OmarAlebiary | 17:989ff25612ad | 61 | |
OmarAlebiary | 13:cec06eb1d7b0 | 62 | |
OmarAlebiary | 17:989ff25612ad | 63 | /** |
OmarAlebiary | 17:989ff25612ad | 64 | * @brief method that has all the screen rendering |
OmarAlebiary | 17:989ff25612ad | 65 | * @param lcd @details calls the lcd object to draw strings and objects on the display |
OmarAlebiary | 17:989ff25612ad | 66 | */ |
OmarAlebiary | 12:1d3b0218d8d0 | 67 | void Main_Game_Display(N5110 &lcd); |
OmarAlebiary | 17:989ff25612ad | 68 | /** |
OmarAlebiary | 17:989ff25612ad | 69 | * @brief method that dispalys the game over screen with the high score achieved |
OmarAlebiary | 17:989ff25612ad | 70 | * @param lcd @details calls the lcd object to draw strings on the display |
OmarAlebiary | 17:989ff25612ad | 71 | * @param pad @details calls the Gamepad object to access methods from the Gamepad class |
OmarAlebiary | 17:989ff25612ad | 72 | */ |
OmarAlebiary | 12:1d3b0218d8d0 | 73 | void End_Game(Gamepad &pad,N5110 &lcd); |
OmarAlebiary | 13:cec06eb1d7b0 | 74 | |
OmarAlebiary | 17:989ff25612ad | 75 | /** |
OmarAlebiary | 17:989ff25612ad | 76 | * @brief method that adds difficulty to the game after proceeding each level |
OmarAlebiary | 17:989ff25612ad | 77 | * @param pad @details calls the Gamepad object to access methods from the Gamepad class |
OmarAlebiary | 17:989ff25612ad | 78 | */ |
OmarAlebiary | 12:1d3b0218d8d0 | 79 | void Game_difficulty(Gamepad &pad); |
OmarAlebiary | 17:989ff25612ad | 80 | |
OmarAlebiary | 17:989ff25612ad | 81 | /** |
OmarAlebiary | 17:989ff25612ad | 82 | * @brief method that generates random enemies |
OmarAlebiary | 17:989ff25612ad | 83 | * @param none @details seeds the rand function then generate a random enemies |
OmarAlebiary | 17:989ff25612ad | 84 | */ |
OmarAlebiary | 11:d4aaa959bb20 | 85 | void Generate_New_Enemy(); |
OmarAlebiary | 17:989ff25612ad | 86 | /** |
OmarAlebiary | 17:989ff25612ad | 87 | * @brief method that checks if the randomly generated enemies crossed the player |
OmarAlebiary | 17:989ff25612ad | 88 | * and calls the End_Game method accordingly if they collide else increments the score |
OmarAlebiary | 17:989ff25612ad | 89 | * @param lcd @details calls the lcd object to be passed to the End_Game method |
OmarAlebiary | 17:989ff25612ad | 90 | * @param pad @details calls the Gamepad object to be passed to the End_Game method |
OmarAlebiary | 17:989ff25612ad | 91 | */ |
OmarAlebiary | 11:d4aaa959bb20 | 92 | void Check_Enemy_Dead(N5110 &lcd,Gamepad &pad); |
OmarAlebiary | 17:989ff25612ad | 93 | /** |
OmarAlebiary | 17:989ff25612ad | 94 | * @brief method that checks the joystick (and L &R buttons) direction whether its left,right or centre |
OmarAlebiary | 17:989ff25612ad | 95 | * and increment or decrement according to the current position |
OmarAlebiary | 17:989ff25612ad | 96 | * @param pad @details calls the Gamepad object to access the get_direction method from the Gamepad class |
OmarAlebiary | 17:989ff25612ad | 97 | */ |
OmarAlebiary | 11:d4aaa959bb20 | 98 | void Joystick_position(Gamepad &pad); |
OmarAlebiary | 17:989ff25612ad | 99 | /** |
OmarAlebiary | 17:989ff25612ad | 100 | * @brief method that has the game loop which calls all the methods(from the same class)for the game to operate |
OmarAlebiary | 17:989ff25612ad | 101 | * @param lcd @details calls the lcd object to be passed to the methods called inside this method |
OmarAlebiary | 17:989ff25612ad | 102 | * @param pad @details calls the Gamepad object to be passed to the methods called inside this method |
OmarAlebiary | 17:989ff25612ad | 103 | */ |
OmarAlebiary | 12:1d3b0218d8d0 | 104 | void Game_Loop(N5110 &lcd,Gamepad &pad); |
OmarAlebiary | 17:989ff25612ad | 105 | /** |
OmarAlebiary | 17:989ff25612ad | 106 | * @brief method that draws the rocket sprite according to the player position |
OmarAlebiary | 17:989ff25612ad | 107 | * @param lcd @details calls the lcd object to access the drawSprite method |
OmarAlebiary | 17:989ff25612ad | 108 | * @param RocketPosition @details the position of the rocket |
OmarAlebiary | 17:989ff25612ad | 109 | */ |
OmarAlebiary | 9:edb39a8334ee | 110 | void player_position(N5110 &lcd,char RocketPosition); |
OmarAlebiary | 17:989ff25612ad | 111 | /** |
OmarAlebiary | 17:989ff25612ad | 112 | * @brief method that draws the enemy sprite |
OmarAlebiary | 17:989ff25612ad | 113 | * @param lcd @details calls the lcd object to access the drawSprite method |
OmarAlebiary | 17:989ff25612ad | 114 | * @param place @details the position of the rocket |
OmarAlebiary | 17:989ff25612ad | 115 | * @param phase @details the phase of the rocket |
OmarAlebiary | 17:989ff25612ad | 116 | */ |
OmarAlebiary | 9:edb39a8334ee | 117 | void enemy_position(N5110 &lcd,int place, int phase); |
OmarAlebiary | 9:edb39a8334ee | 118 | |
OmarAlebiary | 9:edb39a8334ee | 119 | |
OmarAlebiary | 9:edb39a8334ee | 120 | private: |
OmarAlebiary | 15:8a768106c297 | 121 | int first_enemy_position; |
OmarAlebiary | 15:8a768106c297 | 122 | int second_enemy_position; |
OmarAlebiary | 15:8a768106c297 | 123 | int enemy_phase; |
OmarAlebiary | 13:cec06eb1d7b0 | 124 | int game_speed; |
OmarAlebiary | 13:cec06eb1d7b0 | 125 | int score; |
OmarAlebiary | 14:8df7e6fced07 | 126 | char Init_position; |
OmarAlebiary | 13:cec06eb1d7b0 | 127 | bool enemy_dead; |
OmarAlebiary | 13:cec06eb1d7b0 | 128 | bool control; |
OmarAlebiary | 6:958376d55d70 | 129 | |
OmarAlebiary | 6:958376d55d70 | 130 | }; |
OmarAlebiary | 6:958376d55d70 | 131 | |
OmarAlebiary | 6:958376d55d70 | 132 | #endif |