Racing Cars game using N5110 LCD and thumb Joystick
Dependencies: N5110 PowerControl beep mbed
Diff: main.h
- Revision:
- 8:699055e89c7d
- Parent:
- 7:edf0f1fcb16b
--- a/main.h Fri May 08 12:58:22 2015 +0000 +++ b/main.h Mon May 11 16:23:55 2015 +0000 @@ -79,104 +79,92 @@ UNKNOWN }; -/** A structure that includes joystick properties -*/ -typedef struct JoyStick Joystick; + +typedef struct JoyStick Joystick; /*!< A structure that includes joystick properties */ struct JoyStick { - float x; /** current x value */ - float x0; /** 'centred' x value */ - float y; /** current y value */ - float y0; /** 'centred' y value */ - int button; /** button state (assume pull-down used, so 1 = pressed, 0 = unpressed) */ - DirectionName direction; /** current direction */ + float x; /*!< current x value*/ + float x0; /*!< 'centred' x value */ + float y; /*!< current y value */ + float y0; /*!< 'centred' y value */ + int button; /*!< button state (assume pull-down used, so 1 = pressed, 0 = unpressed) */ + DirectionName direction; /*!< current direction */ }; -/** create Joystick struct variable */ -Joystick joystick; -/**flag pointers when interrupt comes in */ +Joystick joystick; /*!< Create Joystick struct variable*/ + int printFlag = 0; int startButtonFlag=0; int resetButtonFlag=0; -char livesBuffer[1]; -char roundBuffer[1]; -char coinsBuffer[2]; -char soundString[3]; // Create buffer String that stores the sound state String("YES","NO") -char brightnessBuffer[2]; - -int gamePlays=1; -int sounds=1; -int coinAppear=1; -int optionsPointer=1; +char livesBuffer[1]; /*!< character Buffer stores number of lives*/ +char roundBuffer[1]; /*!< character Buffer stores number of rounds*/ +char coinsBuffer[2]; /*!< character Buffer stores number of coins*/ +char soundString[3]; /*!< character Buffer stores Sound State String*/ +char brightnessBuffer[2]; /*!< character Buffer stores value of Brightness*/ -/**initial enemies Y positions (p,q,c) */ -int p=-20; -int q=-100; -int c=0; -int j=0; +int gamePlays=1; /*!< integer indicating that game is being played*/ +int sounds=1; /*!< integer indicating that sound is ON or OFF*/ +int coinAppear=1; /*!< integer indicating that coin has appeared*/ +int optionsPointer=1; /*!< integer pointing which submenu has been selectd in Options Menu*/ -/** enemies X positions (p,q,c)*/ -int enemy1x=46; -int enemy2x=6; -int enemy3x=26; +int p=-20; /*!< enemy 2 y-position*/ +int q=-100; /*!< enemy 3 y-position*/ +int c=0; /*!< coin y-position*/ +int j=0; /*!< enemy 1 y-position*/ -/** initial player's Car position and its dimensions(w,h) */ -int x=26; /** x-position*/ -int v=30; /** y-position*/ -int w=8; /** width*/ -int h=12; /** height*/ +int enemy1x=46; /*!< enemy 1 initial x-position*/ +int enemy2x=6; /*!< enemy 2 initial x-position*/ +int enemy3x=26; /*!< enemy 3 initial x-position*/ +int xPos=6; /*!<coin's initial x-position*/ -/**initial Coin Xposition */ -int xPos=6; +int x=26; /*!<player's initial x-position*/ +int v=30; /*!<player's initial y-position*/ +int w=8; /*!<player's width */ +int h=12; /*!<player's height */ -/** initial Game States, Number of lives, Number of coins, Round Number */ -int lives; -int coins; -int round; +int lives; /*!<number of lives */ +int coins; /*!<number of coins */ +int round; /*!<number of rounds */ -/** brightness Initial Values, brightnessDisplay is the value displayed to the user */ -float brightness=0.9; -int brightnessDisplay=9; +float brightness=0.9; /*!<brightness value (0.1-0.9)*/ +int brightnessDisplay=9; /*!<brightness value displayed to the user (1-9)*/ -/** table array that will store cell conditions (either 0,1,2) */ -int table[84][48]; +int table[84][48]; /*!<table array that will store cell conditions (either 0,1,2)*/ -/** enemies acceleration initial value */ -int a=4; +int a=4; /*!<value of the enemies acceleration, integer being added to enemies y-positions*/ /* FUNCTION DECLERATIONS */ - -/** Initialise GameScreen -* Draws the lanes of the road, that are fixed. -* This function is called when the player moves on the screen and pixels need to be reset +/** Set the Game Lanes and Borders +* @brief Draws the lanes of the road, that are fixed. +* @brief This function is called when the player moves on the screen and pixels need to be reset */ void gameLanes(); /** Initialise Table Array -* It initialises the array used in the game by setting all the array cells value equal to 0 +* @brief It initialises the array used in the game by setting all the array cells value equal to 0 */ void initTable(); /** Calibrate Joystick Function -* read default positions of the joystick to calibrate later readings +* @brief Read default positions of the joystick to calibrate later readings */ void calibrateJoystick(); /** Update Joystick Function -* read current joystick values relative to calibrated values (in range -0.5 to 0.5, 0.0 is centred) +* @brief read current joystick values relative to calibrated values (in range -0.5 to 0.5, 0.0 is centred) */ void updateJoystick(); /** Clear Rectangle Function -* This function clears the rectangle +* @brief This function clears the rectangle * @param x - x-coordinate of top left point * @param v - y-coordinate of top left point * @param w - width of the Rectangle @@ -186,46 +174,62 @@ /** MovePlayer Function -* This function is being called every 0.1 sec, checks the direction of the joystick +* @brief This function is being called every 0.1 sec, checks the direction of the joystick * and moves the Player by clearing and drawing Rectangle */ void movePlayer(); /** Loose Function -* This function is being called when the player loose (i.e touches an enemy) +* @brief This function is being called when the player loose (i.e touches an enemy) */ void loose(); /** Check Player Function -* Function can be used to check if the Player touched an enemy +* @brief Function can be used to check if the Player touched an enemy * or if he has touched a coin. Depending on the situation calls the * appropriate function and implements some certain tasks */ void checkPlayerPos();//Constantly checking player's position -/** Enemy Move Functions -* 3 Enemy Functions, each one is responsible to move the Enemy downwards +/** Enemy 1 Move Function +* @brief Enemy Function is responsible to move the Enemy downwards * The functions use an integer that defines the y position of the enemy * As this integer is increasing, rectangle is being drawn and cleared continuously * This integer variable restarts from a random value after reaching a specific point */ void enemy1MovesDown(); + + +/** Enemy 2 Move Function +* @brief Enemy Function is responsible to move the Enemy downwards +* The functions use an integer that defines the y position of the enemy +* As this integer is increasing, rectangle is being drawn and cleared continuously +* This integer variable restarts from a random value after reaching a specific point +*/ void enemy2MovesDown(); + + +/** Enemy 3 Move Function +* @brief Enemy Function is responsible to move the Enemy downwards +* The functions use an integer that defines the y position of the enemy +* As this integer is increasing, rectangle is being drawn and cleared continuously +* This integer variable restarts from a random value after reaching a specific point +*/ void enemy3MovesDown(); /** Coin Moves Function -* Function that causes a coin to move downwards +* @brief Function that causes a coin to move downwards * It calls the drawCoin and clearCoin functions so the coin is continuously moving down when it appears */ void coinMoves(); /** Draw Coin Function -* Function that draws a coin on the screen +* @brief Function that draws a coin on the screen * This is a circle with a 'c' symbol at the centre of the circle * It calls the drawCircle function and setPixel function to draw the coin * It also sets the array cells value equal to 2, indicating there is a coin @@ -235,7 +239,7 @@ /** Clear Coin Function -* Function that clears the coin that was drawn previously +* @brief Function that clears the coin that was drawn previously * This is a circle with a 'c' symbol at the centre of the circle * It calls the clearCircle function and clearPixel function to clear the coin * It also clears the array cells (set their values to 0), indicating there is nothing in these cells @@ -245,55 +249,55 @@ /** Set Circle Cells Function -* Function is responsible to set the values of the Table Array cells within a Circle range equal to 2 +* @brief Function is responsible to set the values of the Table Array cells within a Circle range equal to 2 * This is done to identify where the coin is at a certain time -* @param x0-the x coordinate of the Circle's centre -* @param y0-the y coordinate of the Circle's centre -* @param radius-radius of the circle +* @param x0 -the x coordinate of the Circle's centre +* @param y0 -the y coordinate of the Circle's centre +* @param radius -radius of the circle */ void setCircleCells(int x0,int y0,int radius); //Set selected Circle cells to 1 /** Clear Circle Cells Function -* Function that clears the values of the Table Array cells within a Circle (set them equal to 0) -* @param x0-the x coordinate of the Circle's centre -* @param y0-the y coordinate of the Circle's centre -* @param radius-radius of the circle +* @brief Function that clears the values of the Table Array cells within a Circle (set them equal to 0) +* @param x0 -the x coordinate of the Circle's centre +* @param y0 -the y coordinate of the Circle's centre +* @param radius -radius of the circle */ void clearCircleCells(int x0,int y0,int radius);//Set selected Circle cells to 0 /** Set Rectangle Cells Function -* Function that cells the values of the Table Array cells within a Rectanlge Shape equal to 1 -* This is done for all enemies moving downwards, thus we can check where the enemies are located -* @param x-the x-direction of the Rectangle's top left corner -* @param v-the y-direction of the Rectangle's top right corner -* @param w-the width of the Rectangle -* @param h-the height of the Rectangle +* @brief Function that cells the values of the Table Array cells within a Rectanlge Shape equal to 1 +* @brief This is done for all enemies moving downwards, thus we can check where the enemies are located +* @param x -the x-direction of the Rectangle's top left corner +* @param v -the y-direction of the Rectangle's top right corner +* @param w -the width of the Rectangle +* @param h -the height of the Rectangle */ void setRectCells(int x,int v,int w,int h); //set Cells range to 1 /** Clear Cells Function -* Clears the pixel and sets the array table cells value equal to 0 , from 0 to x and from 0 to y -* @param x-x coordinate of the array to clear -* @param y-y coordinate of the array to clear +* @brief Clears the pixel and sets the array table cells value equal to 0 , from 0 to x and from 0 to y +* @param x -x coordinate of the array to clear +* @param y -y coordinate of the array to clear */ void clearCells(int x,int y); //set Cells range to 0 /** Start Button Pressed Function -* Flips the Start Button Flag indicator showing that button was pressed +* @brief Flips the Start Button Flag indicator showing that button was pressed */ void startButtonPressed();//Function that checks for an Interupt at pin 24 /** Start Button Pressed Function -* Flips the Start Button Flag indicator showing that button was pressed +* @brief Flips the Start Button Flag indicator showing that button was pressed */ void resetButtonPressed();//Function that checks for an Interupt at pin 25 /** Set Line's Cells Function -* Sets the cells of a line equal to 2 +* @brief Sets the cells of a line equal to 2 * @param x0 - x-coordinate of first point * @param y0 - y-coordinate of first point * @param x1 - x-coordinate of last point @@ -304,7 +308,7 @@ /** Clear Line's Cells Function -* Clears the cells of a line(set them equal to 0) +* @brief Clears the cells of a line(set them equal to 0) * @param x0 - x-coordinate of first point * @param y0 - y-coordinate of first point * @param x1 - x-coordinate of last point @@ -315,6 +319,6 @@ /** Initialisation Game Function -* Sets the initial game values +* @brief Sets the initial game values */ void gameReset(); \ No newline at end of file