contains my game for the embedded systems project 2645

Dependencies:   mbed FXOS8700CQQQ

Committer:
OmarAlebiary
Date:
Tue Apr 09 15:33:52 2019 +0000
Revision:
19:ad9dc8e418c9
Parent:
17:989ff25612ad
Child:
22:3e6ff378d651
fixed check_event for buttonA

Who changed what in which revision?

UserRevisionLine numberNew 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 17:989ff25612ad 30 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
OmarAlebiary 19:ad9dc8e418c9 31
OmarAlebiary 17:989ff25612ad 32 // prototypes
OmarAlebiary 17:989ff25612ad 33 void welcome();
OmarAlebiary 17:989ff25612ad 34 void nextmenu();
OmarAlebiary 17:989ff25612ad 35 void setup();
OmarAlebiary 17:989ff25612ad 36
OmarAlebiary 17:989ff25612ad 37 int main(){
OmarAlebiary 17:989ff25612ad 38
OmarAlebiary 17:989ff25612ad 39
OmarAlebiary 17:989ff25612ad 40 setup();
OmarAlebiary 17:989ff25612ad 41 welcome();
OmarAlebiary 17:989ff25612ad 42 nextmenu();
OmarAlebiary 17:989ff25612ad 43
OmarAlebiary 17:989ff25612ad 44
OmarAlebiary 17:989ff25612ad 45 while(1){
OmarAlebiary 17:989ff25612ad 46 rc.Game_Loop(lcd,pad);
OmarAlebiary 17:989ff25612ad 47 }
OmarAlebiary 17:989ff25612ad 48
OmarAlebiary 17:989ff25612ad 49
OmarAlebiary 17:989ff25612ad 50 }
OmarAlebiary 17:989ff25612ad 51
OmarAlebiary 17:989ff25612ad 52 @endcode
OmarAlebiary 17:989ff25612ad 53 */
OmarAlebiary 16:93a8147a4358 54
OmarAlebiary 6:958376d55d70 55
OmarAlebiary 6:958376d55d70 56 class RocketRacer{
OmarAlebiary 6:958376d55d70 57
OmarAlebiary 6:958376d55d70 58 public:
OmarAlebiary 17:989ff25612ad 59 /**
OmarAlebiary 17:989ff25612ad 60 * @brief Default Constuctor
OmarAlebiary 17:989ff25612ad 61 * @param None @details Creates the object of class RocketRacer
OmarAlebiary 17:989ff25612ad 62 */
OmarAlebiary 13:cec06eb1d7b0 63 RocketRacer();
OmarAlebiary 17:989ff25612ad 64
OmarAlebiary 13:cec06eb1d7b0 65
OmarAlebiary 17:989ff25612ad 66 /**
OmarAlebiary 17:989ff25612ad 67 * @brief method that has all the screen rendering
OmarAlebiary 17:989ff25612ad 68 * @param lcd @details calls the lcd object to draw strings and objects on the display
OmarAlebiary 17:989ff25612ad 69 */
OmarAlebiary 12:1d3b0218d8d0 70 void Main_Game_Display(N5110 &lcd);
OmarAlebiary 17:989ff25612ad 71 /**
OmarAlebiary 17:989ff25612ad 72 * @brief method that dispalys the game over screen with the high score achieved
OmarAlebiary 17:989ff25612ad 73 * @param lcd @details calls the lcd object to draw strings on the display
OmarAlebiary 17:989ff25612ad 74 * @param pad @details calls the Gamepad object to access methods from the Gamepad class
OmarAlebiary 17:989ff25612ad 75 */
OmarAlebiary 12:1d3b0218d8d0 76 void End_Game(Gamepad &pad,N5110 &lcd);
OmarAlebiary 13:cec06eb1d7b0 77
OmarAlebiary 17:989ff25612ad 78 /**
OmarAlebiary 17:989ff25612ad 79 * @brief method that adds difficulty to the game after proceeding each level
OmarAlebiary 17:989ff25612ad 80 * @param pad @details calls the Gamepad object to access methods from the Gamepad class
OmarAlebiary 17:989ff25612ad 81 */
OmarAlebiary 12:1d3b0218d8d0 82 void Game_difficulty(Gamepad &pad);
OmarAlebiary 17:989ff25612ad 83
OmarAlebiary 17:989ff25612ad 84 /**
OmarAlebiary 17:989ff25612ad 85 * @brief method that generates random enemies
OmarAlebiary 17:989ff25612ad 86 * @param none @details seeds the rand function then generate a random enemies
OmarAlebiary 17:989ff25612ad 87 */
OmarAlebiary 11:d4aaa959bb20 88 void Generate_New_Enemy();
OmarAlebiary 17:989ff25612ad 89 /**
OmarAlebiary 17:989ff25612ad 90 * @brief method that checks if the randomly generated enemies crossed the player
OmarAlebiary 17:989ff25612ad 91 * and calls the End_Game method accordingly if they collide else increments the score
OmarAlebiary 17:989ff25612ad 92 * @param lcd @details calls the lcd object to be passed to the End_Game method
OmarAlebiary 17:989ff25612ad 93 * @param pad @details calls the Gamepad object to be passed to the End_Game method
OmarAlebiary 17:989ff25612ad 94 */
OmarAlebiary 11:d4aaa959bb20 95 void Check_Enemy_Dead(N5110 &lcd,Gamepad &pad);
OmarAlebiary 17:989ff25612ad 96 /**
OmarAlebiary 17:989ff25612ad 97 * @brief method that checks the joystick (and L &R buttons) direction whether its left,right or centre
OmarAlebiary 17:989ff25612ad 98 * and increment or decrement according to the current position
OmarAlebiary 17:989ff25612ad 99 * @param pad @details calls the Gamepad object to access the get_direction method from the Gamepad class
OmarAlebiary 17:989ff25612ad 100 */
OmarAlebiary 11:d4aaa959bb20 101 void Joystick_position(Gamepad &pad);
OmarAlebiary 17:989ff25612ad 102 /**
OmarAlebiary 17:989ff25612ad 103 * @brief method that has the game loop which calls all the methods(from the same class)for the game to operate
OmarAlebiary 17:989ff25612ad 104 * @param lcd @details calls the lcd object to be passed to the methods called inside this method
OmarAlebiary 17:989ff25612ad 105 * @param pad @details calls the Gamepad object to be passed to the methods called inside this method
OmarAlebiary 17:989ff25612ad 106 */
OmarAlebiary 12:1d3b0218d8d0 107 void Game_Loop(N5110 &lcd,Gamepad &pad);
OmarAlebiary 17:989ff25612ad 108 /**
OmarAlebiary 17:989ff25612ad 109 * @brief method that draws the rocket sprite according to the player position
OmarAlebiary 17:989ff25612ad 110 * @param lcd @details calls the lcd object to access the drawSprite method
OmarAlebiary 17:989ff25612ad 111 * @param RocketPosition @details the position of the rocket
OmarAlebiary 17:989ff25612ad 112 */
OmarAlebiary 9:edb39a8334ee 113 void player_position(N5110 &lcd,char RocketPosition);
OmarAlebiary 17:989ff25612ad 114 /**
OmarAlebiary 17:989ff25612ad 115 * @brief method that draws the enemy sprite
OmarAlebiary 17:989ff25612ad 116 * @param lcd @details calls the lcd object to access the drawSprite method
OmarAlebiary 17:989ff25612ad 117 * @param place @details the position of the rocket
OmarAlebiary 17:989ff25612ad 118 * @param phase @details the phase of the rocket
OmarAlebiary 17:989ff25612ad 119 */
OmarAlebiary 9:edb39a8334ee 120 void enemy_position(N5110 &lcd,int place, int phase);
OmarAlebiary 9:edb39a8334ee 121
OmarAlebiary 9:edb39a8334ee 122
OmarAlebiary 9:edb39a8334ee 123 private:
OmarAlebiary 15:8a768106c297 124 int first_enemy_position;
OmarAlebiary 15:8a768106c297 125 int second_enemy_position;
OmarAlebiary 15:8a768106c297 126 int enemy_phase;
OmarAlebiary 13:cec06eb1d7b0 127 int game_speed;
OmarAlebiary 13:cec06eb1d7b0 128 int score;
OmarAlebiary 14:8df7e6fced07 129 char Init_position;
OmarAlebiary 13:cec06eb1d7b0 130 bool enemy_dead;
OmarAlebiary 13:cec06eb1d7b0 131 bool control;
OmarAlebiary 6:958376d55d70 132
OmarAlebiary 6:958376d55d70 133 };
OmarAlebiary 6:958376d55d70 134
OmarAlebiary 6:958376d55d70 135 #endif