Racing Cars game using N5110 LCD and thumb Joystick
Dependencies: N5110 PowerControl beep mbed
Revision 8:699055e89c7d, committed 2015-05-11
- Comitter:
- el13gs
- Date:
- Mon May 11 16:23:55 2015 +0000
- Parent:
- 7:edf0f1fcb16b
- Commit message:
- Handheld Arcade Game "Racing Cars"
Changed in this revision
diff -r edf0f1fcb16b -r 699055e89c7d N5110.lib --- a/N5110.lib Fri May 08 12:58:22 2015 +0000 +++ b/N5110.lib Mon May 11 16:23:55 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/eencae/code/N5110/#428cbc6df6ea +http://developer.mbed.org/users/el13gs/code/N5110/#603c9e138aca
diff -r edf0f1fcb16b -r 699055e89c7d main.cpp --- a/main.cpp Fri May 08 12:58:22 2015 +0000 +++ b/main.cpp Mon May 11 16:23:55 2015 +0000 @@ -7,22 +7,47 @@ int main() { + + Peripheral_PowerDown(0xFFFFFFFF); //turn off all peripherals + /* turn on only the required peripherals */ + Peripheral_PowerUp(0x800000); + Peripheral_PowerUp(0x200000); + Peripheral_PowerUp(0x40); + Peripheral_PowerUp(0x8000); + Peripheral_PowerUp(0x1000); + sprintf(soundString,"%s","YES"); //set the Sound Initial String to YES calibrateJoystick(); // get centred values of joystick - pollJoystick.attach(&updateJoystick,1.0/10.0); // read joystick 30 times per second + pollJoystick.attach(&updateJoystick,1.0/20.0); // read joystick 30 times per second lcd.setXYAddress(0,0);//set the XY address to 0.0 as initialising condition initTable();//initialise the array table lcd.init();//initialise LCD screen lcd.refresh(); + /* PRINT WELCOMING MESSAGES */ + lcd.printString("RACING CARS",9,1); + wait(0.5); + lcd.printString("GAME",29,2); + wait(0.5); + lcd.printString("by Giorgos",14,4); + wait(0.5); + lcd.printString("Savvides",16,5); + wait(2); + lcd.clear(); + lcd.refresh(); + lcd.printString("USE JOYSTICK",0,0); + lcd.printString("AND BUTTONS ",0,1); + lcd.printString("ON THE RIGHT",0,2); + lcd.printString("TO NAVIGATE",0,3); + lcd.printString("HAVE FUN!!!",12,5); + wait(3.5); start.rise(&startButtonPressed); // Call function startButtonPressed when START button pressed reset.rise(&resetButtonPressed); // Call function resetButtonPressed when RESET button pressed - MainMenu: /* INITIAL DISPLAY IN MAIN MENU */ - calibrateJoystick(); // calibrate the Joystick + int menuPointer=1; // set the Pointer in Main Menu initially to 1 startButtonFlag=0; // reset the pointing flags resetButtonFlag=0; // reset the pointing flags @@ -35,7 +60,7 @@ lcd.printString("Play",26,2); //print submenu title lcd.printString("Options",20,3); //print submenu title lcd.drawLine(15,9,65,9,1);//underline main menu title - + wait(0.1); /* While start Button is not pressed user can navigate through main Menu Submenus */ while(startButtonFlag==0) { @@ -49,7 +74,6 @@ menuPointer=2; //set Pointer to 2 } - wait(0.25); // some delay between joystick movement /* when joystick moves up, pointer selects Options subMenu */ if(joystick.direction==UP) { @@ -60,6 +84,7 @@ lcd.clearCircle(64,27,2,1); //clear pointer around Options submenu menuPointer=1; //set Pointer to 1 } + sleep(); } /* SELECT POINTER CONDITION */ @@ -74,8 +99,19 @@ round=1; // set round number to 1 coins=0; // set coin number to 0 clearCells(84,48); //clear the whole LCD screen + + lcd.refresh(); + lcd.printString("READY?",20,3); + wait(0.75); + lcd.printString("GET SET",20,3); + wait(1); + lcd.printString(" GO !!!",20,3); + wait(1); + lcd.clear(); + lcd.refresh(); + + gameReset(); // set and draw initial player and enemies position - lcd.refresh(); timer.attach(&movePlayer,0.1);// attach timer to call function that moves the Player @@ -84,31 +120,42 @@ //print Round number on buffer and display sprintf(roundBuffer,"%d",round); lcd.printString(roundBuffer,74,3); + lcd.refresh(); //print Lives number on buffer and display sprintf(livesBuffer,"%d",lives); lcd.printString(livesBuffer,74,1); + lcd.refresh(); //print Coins number on buffer and display sprintf(coinsBuffer,"%d",coins); lcd.printString(coinsBuffer,72,5); + lcd.refresh(); enemy1MovesDown(); //move enemy 1 downwards + checkPlayerPos(); //check player position frequently - // if gameplay is 0 returns to initial MAIN MENU - if (gamePlays==0) { + if (gamePlays==0) { // if gameplay is 0 returns to initial MAIN MENU goto MainMenu; } + lcd.refresh(); enemy2MovesDown(); //move enemy 2 downwards + checkPlayerPos(); if (gamePlays==0) { goto MainMenu; } + lcd.refresh(); enemy3MovesDown(); //move enemy 3 downwards + checkPlayerPos(); + if (gamePlays==0) { + goto MainMenu; + } coinMoves(); // move coin downwards + lcd.refresh(); checkPlayerPos(); if (gamePlays==0) { goto MainMenu; @@ -120,7 +167,7 @@ case 2: int optionsMenu=1; // set options Menu enabled - + optionsPointer=1; startButtonFlag=0; //reset START Button Flag clearCells(84,48); // clear all screen Cells @@ -150,9 +197,9 @@ optionsPointer=1; } } - wait(0.1); + wait(0.05); - /* If direction is down pointer value increase by 1 (cannot increase to more than 3) */ + /* If direction is down, pointer value increase by 1 (cannot increase to more than 3) */ if(joystick.direction==DOWN) { optionsPointer++; if(optionsPointer>3) { @@ -160,7 +207,6 @@ } } /* CASES FOR EACH POINTER VALUE */ - wait(0.1); /* when it is 1, Sound submenu is selected */ if (optionsPointer==1) { /* print Circle pointer around Sound submenu */ @@ -181,7 +227,7 @@ sprintf(soundString,"%s","NO "); //print string in buffer lcd.printString(soundString,40,2); //display value of buffer } - + sleep(); } /* when it is 2, brightness submenu is selected */ if (optionsPointer==2) { @@ -219,7 +265,7 @@ sprintf(brightnessBuffer,"%d",brightnessDisplay); lcd.printString(brightnessBuffer,68,3); } - + sleep(); } if (optionsPointer==3) { /* print Circle pointer around Exit submenu */ @@ -229,13 +275,15 @@ /* if START button is press while pointer is on Exit goes back to Main Menu label */ if(startButtonFlag) { - wait(0.1); startButtonFlag=0; + wait(0.5); optionsMenu=0; goto MainMenu; } + sleep(); } - wait(0.1); + wait(0.05); + sleep(); } break; @@ -255,7 +303,7 @@ void movePlayer() { if (gamePlays) { - //lcd.refresh(); + /* if direction is RIGHT clears the previous Car shape and draws the next one by increasing the x position */ if (joystick.direction==RIGHT&&x+w<58) { clearRect(x,v,w,h); @@ -264,7 +312,7 @@ lcd.drawRect(x,v,w,h,0); lcd.refresh(); } - + /* if direction is LEFT clears the previous Car shape and draws the next one by decreasing the x position */ if (joystick.direction==LEFT&&x+w>10) { clearRect(x,v,w,h); @@ -274,7 +322,7 @@ lcd.drawRect(x,v,w,h,0); lcd.refresh(); } - + /* if direction is UP clears the previous Car shape and draws the next one by decreasing the y position */ if (joystick.direction==UP && v>2) { clearRect(x,v,w,h); @@ -283,6 +331,7 @@ lcd.drawRect(x,v,w,h,0); lcd.refresh(); } + /* if direction is DOWN clears the previous Car shape and draws the next one by increasing the y position */ if (joystick.direction==DOWN && v<32) { clearRect(x,v,w,h); lcd.refresh(); @@ -331,6 +380,7 @@ void clearRect(int x,int v,int w,int h) { + // loop through the array cells, clear the Pixels and array cells value(=0) for(int i=x; i<=x+w; i++) { for(int j=v; j<=v+h; j++) { lcd.clearPixel(i,j); @@ -342,40 +392,35 @@ void enemy1MovesDown() { - clearRect(enemy1x,(j-a),w,h); + clearRect(enemy1x,(j-a),w,h); // clears the previous Enemy Car lcd.refresh(); - lcd.drawRect(enemy1x,j,w,h,1); + lcd.drawRect(enemy1x,j,w,h,1); //draws the next enemy Car lcd.refresh(); - setRectCells(enemy1x,j,w,h); + setRectCells(enemy1x,j,w,h); //set the current enemy cells to 1 lcd.refresh(); wait(0.05); - j=j+a; - //lcd.refresh(); + j=j+a; //increase the y-position counter - if(j>60) { - j=-(rand()%100+80); + if(j>70) { // after reaching certain y position, randomize it again br + j=-(rand()%95+85); } } void enemy2MovesDown() { - clearRect(enemy2x,(p-a),w,h); + clearRect(enemy2x,(p-a),w,h); // clears the previous Enemy Car lcd.refresh(); - lcd.drawRect(enemy2x,p,w,h,1); + lcd.drawRect(enemy2x,p,w,h,1); //draws the next enemy Car lcd.refresh(); - setRectCells(enemy2x,p,w,h); + setRectCells(enemy2x,p,w,h); //set the current enemy cells to 1 lcd.refresh(); wait(0.05); - p=p+a; - //lcd.refresh(); + p=p+a; //increase the y-position counter - if(p>60) { - p=-(rand()%40+20); - } - while(p==q) { - p=-(rand()%40+20); + if(p>70) { + p=-(rand()%60+40); } } @@ -392,14 +437,14 @@ lcd.refresh(); q=q+a; if (q>70) { - q=-(rand()%10+1); + q=-(rand()%34+3); } } void setRectCells(int x,int v,int w,int h) { - +// Sets the Rectangle Array Cells equal to 1, indicating there is an enemy for(int i=x; i<=x+w; i++) { for(int j=v; j<=v+h; j++) { if(j>0&&j<48) { @@ -411,6 +456,7 @@ void initTable() { + // initialise the Array's cells, set them equal to 0 for (int i=0; i<=83; i++) { for(int j=0; j<=47; j++) { table[i][j]=0; @@ -420,63 +466,74 @@ void checkPlayerPos() { + // frequently calling this function to check if player touched an enemy or a coin + /* if player cells equal to 1, means he touched enemy, so loose function is being called */ if (table[x+w][v+h]==1||table[x][v+h]==1||table[x][v]==1||table[x+w][v]==1) { loose(); } + /* if player cells equal to 2, means he touched a coin */ if (table[x+w][v+h]==2||table[x][v+h]==2||table[x][v]==2||table[x+w][v]==2) { - coins=coins+5; - clearCoin(c); - if(sounds) { - buzzer.beep(2200,0.4); + coins=coins+5; //each coin's value is 5,total coins increase by 5 + clearCoin(c); //clear the collected Coin + lcd.drawRect(x,v,w,h,0);//redraw Player boundaries that were cleared by Coin + if(sounds) { // if sound is enabled in options menu sound produced when got a coin + buzzer.beep(2200,0.4); //produce sound of frequency 2200 Hz and duration 0.4 s buzzer.beep(1000,0.2); - lcd.setBrightness(brightness); + lcd.setBrightness(brightness); //set brightness again, frequency produced interfere with LCD pin } - coinAppear=0; + coinAppear=0; //switch coin status to disappear + + /* then Check the total number of coins, to produce to next Round */ - if(coins==30) { - round=2; - gamePlays=0; - clearCells(84,48); + if(coins==30) { // if coins are 40 proceed to next Round + round=2; // change Round Value + gamePlays=0; // stop gameplay, preventing user moving on screen + clearCells(84,48); //clear all Cells lcd.refresh(); - lcd.printString("ROUND 2",10,2); + lcd.printString("ROUND 2",10,2); //print Round message wait(1); - clearCells(84,48); + clearCells(84,48);// clear all Cells lcd.refresh(); - gamePlays=1; - gameReset(); - a=6; + gamePlays=1;//start gameplay + gameReset();//reset player and enemies positions + a=6; //change enemies acceleration (a is added to y positions counter) } - if(coins==70) { - round=3; - gamePlays=0; - clearCells(84,48); + if(coins==70) { // if coins are 70 proceed to next Round + round=3; // change Round Value + gamePlays=0;// stop gameplay, preventing user moving on screen + clearCells(84,48); //clear all Cells lcd.refresh(); - lcd.printString("ROUND 3",10,2); + lcd.printString("ROUND 3",10,2); //print Round message wait(1); - clearCells(84,48); + clearCells(84,48); // clear all Cells lcd.refresh(); - gamePlays=1; - gameReset(); - a=8; + gamePlays=1; //start gameplay + gameReset(); //reset player and enemies positions + a=8; //change enemies acceleration (a is added to y positions counter) } - if(coins==90) { - lcd.printString("YOU WIN!",8,3); - wait(3); - gamePlays=0; + if(coins==90) { // if coins are 90, player WINS the game + timer.detach(); //stop player moving + clearCells(84,48); //clear pixels + lcd.clear(); //clear LCD + lcd.refresh(); + lcd.printString("CONGRATS!",0,2); //print win message + lcd.printString("YOU WON!",8,3); //print win message + wait(4); + gamePlays=0; //game finishes } } } - void coinMoves() { - if(table[xPos][c]==1) { //prevent coin from appearing above enemies - coinAppear=0; + if(table[xPos][c]==1||table[xPos][c+4]==1||table[xPos+4][c+4]==1) { //prevent coin from appearing above enemies + clearCoin(c); //clear current Coin + coinAppear=0; //make coin disappear (prevent from being redrawn) } - clearCoin(c); - c=c+4; - drawCoin(c); - if(c>80) { + clearCoin(c); //clear current Coin + c=c+4; // increase Coin's y coordinate counter + drawCoin(c); //draw next Coin position + if(c>80) { // if counter exceeds 80, randomizes x and y positions and make it reappear c=-(rand()%10); xPos=rand()%52+4; coinAppear=1; @@ -485,7 +542,7 @@ void drawCoin(int c) { - if (c>4&&c<48&&coinAppear==1) { + if (c>4&&c<48&&coinAppear==1) { //check if coin c point(y pos) is within LCD limits lcd.drawCircle(xPos,c,4,0); //Draw Coin Circle Pixels setCircleCells(xPos,c,4);// Set Coin array's cells values to 2 @@ -503,17 +560,83 @@ void clearCoin(int c) { - if(c>4&&c<48&&coinAppear==1) { + if(c>4&&c<48&&coinAppear==1) { // if c point of the Coin within the LCD limits lcd.clearCircle(xPos,c,4,1); //Clear the Coin clearCircleCells(xPos,c,4);// Set Coin array's cells values to 0 lcd.refresh(); } } +void loose() +{ + + if (sounds) { //check if sound is enabled and produce a "loose" sound of frequency 400 Hz + buzzer.beep(400,0.2); + lcd.setBrightness(brightness); //set brightness + } + timer.detach(); //detach moving Player function timer, so player cannot move + lives=lives-1; //decrease lives value + startButtonFlag=0; //reset START button flag + resetButtonFlag=0;//reset SELECT button flag + if(lives==0) { //if lives are equal to 0, Game Over is displayed + + clearCells(84,48); + lcd.refresh(); + lcd.clear(); + + wait(1); + while(startButtonFlag==0&&resetButtonFlag==0) { //while no button is pressed + lcd.printString("Game Over!!!",0,0); + lcd.printString("Press START",0,2); + lcd.printString("to try again",0,3); + lcd.printString("or RESET",0,4); + lcd.printString("to exit :)",0,5); + } + if(startButtonFlag) { //START button pressed, resets the game + a=4; + gamePlays=1; + lives=5; + coins=0; + round=1; + clearCells(84,48); + gameReset(); + startButtonFlag=0; + wait(1); + timer.attach(&movePlayer,0.1); + } + if (resetButtonFlag) { //RESET button pressed, sets gameplay to 0 ( when gameplay is 0 , returns to MAIN MENU) + gamePlays=0; + resetButtonFlag=0; + } + } + + else { + clearCells(60,48); //else if lives are not 0, clearCells and reset the game + lcd.refresh(); + gameReset(); // reset player and enemies values + wait(2); + gamePlays=1;// game is being played + timer.attach(&movePlayer,0.1); //attach move Player function + } +} + +void gameReset() +{ + initTable(); // initialise the array (set cells values to 0) + x=26; //initial player x position + v=30; //initial player y position + lcd.drawRect(x,v,w,h,0); //draw player at initial position + lcd.refresh(); + j=-70; // enemy y position, initialise + q=-10; // enemy y position, initialise + p=-40; // enemy y position, initialise + +} + void setCircleCells(int x0,int y0,int radius) { - //function from N5110 Library + //function from N5110 Library, works only for filled circle int x = radius; int y = 0; @@ -530,21 +653,22 @@ void clearCircleCells(int x0,int y0,int radius) { - //function from N5110 Library + //function from N5110 Library, works only for filled circle int x = radius; int y = 0; while(x >= y) { - clearLineCells(x+x0,y+y0,-x+x0,y+y0,0); - clearLineCells(y+x0,x+y0,-y+x0,x+y0,0); - clearLineCells(y+x0,-x+y0,-y+x0,-x+y0,0); - clearLineCells(x+x0,-y+y0,-x+x0,-y+y0,0); + clearLineCells(x+x0,y+y0,-x+x0,y+y0,0);//set line's Cells values to 0 + clearLineCells(y+x0,x+y0,-y+x0,x+y0,0);//set line's Cells values to 0 + clearLineCells(y+x0,-x+y0,-y+x0,-x+y0,0);//set line's Cells values to 0 + clearLineCells(x+x0,-y+y0,-x+x0,-y+y0,0);//set line's Cells values to 0 y++; } } void clearCells(int x,int y) { + // loops through cells, clears the pixels and set the cells value equal to 0 for(int i=0; i<=x; i++) { for (int j=0; j<=y; j++) { lcd.clearPixel(i,j); @@ -554,71 +678,6 @@ lcd.refresh(); } -void loose() -{ - if (sounds) { - buzzer.beep(500,0.2); - lcd.setBrightness(brightness); - } - timer.detach(); - lives=lives-1; - startButtonFlag=0; - resetButtonFlag=0; - if(lives==0) { - - clearCells(84,48); - lcd.refresh(); - lcd.clear(); - - wait(1); - while(startButtonFlag==0&&resetButtonFlag==0) { - lcd.printString("Game Over!!!",0,0); - lcd.printString("Press START",0,2); - lcd.printString("to try again",0,3); - lcd.printString("or RESET",0,4); - lcd.printString("to exit :)",0,5); - } - if(startButtonFlag) { - a=4; - gamePlays=1; - lives=5; - coins=0; - round=1; - clearCells(84,48); - gameReset(); - startButtonFlag=0; - wait(1); - timer.attach(&movePlayer,0.1); - } - if (resetButtonFlag) { - gamePlays=0; - resetButtonFlag=0; - } - } - - else { - clearCells(60,48); - lcd.refresh(); - gameReset(); - wait(2); - gamePlays=1; - timer.attach(&movePlayer,0.1); - } -} - -void gameReset() -{ - initTable(); - x=26; - v=30; - lcd.drawRect(x,v,w,h,0); - lcd.refresh(); - j=-70; - q=-10; - p=-40; - -} - void setLineCells(int x0,int y0,int x1,int y1,int type) { @@ -643,12 +702,7 @@ for (int x = start; x<= stop ; x+=step) { // do linear interpolation int y = y0 + (y1-y0)*(x-x0)/(x1-x0); - - if (type == 0) // if 'white' line, turn off pixel - table[x][y]=2; - else - table[x][y]=2; // else if 'black' or 'dotted' turn on pixel - + table[x][y]=2; // set table values to 2 } } else { @@ -659,12 +713,7 @@ for (int y = start; y<= stop ; y+=step) { // do linear interpolation int x = x0 + (x1-x0)*(y-y0)/(y1-y0); - - if (type == 0) // if 'white' line, turn off pixel - table[x][y]=2; - else - table[x][y]=2; // else if 'black' or 'dotted' turn on pixel - + table[x][y]=2; // set table values to 2 } } @@ -688,20 +737,13 @@ // ensure we loop from smallest to largest or else for-loop won't run as expected start = x1>x0 ? x0:x1; stop = x1>x0 ? x1:x0; - // loop between x pixels for (int x = start; x<= stop ; x+=step) { // do linear interpolation int y = y0 + (y1-y0)*(x-x0)/(x1-x0); - - if (type == 0) // if 'white' line, turn off pixel - table[x][y]=0; - else - table[x][y]=0; // else if 'black' or 'dotted' turn on pixel - + table[x][y]=0; // set Table Cell to 0 } } else { - // ensure we loop from smallest to largest or else for-loop won't run as expected start = y1>y0 ? y0:y1; stop = y1>y0 ? y1:y0; @@ -709,12 +751,8 @@ for (int y = start; y<= stop ; y+=step) { // do linear interpolation int x = x0 + (x1-x0)*(y-y0)/(y1-y0); - - if (type == 0) // if 'white' line, turn off pixel - table[x][y]=0; - else - table[x][y]=0; // else if 'black' or 'dotted' turn on pixel - + table[x][y]=0; // set Table Cell to 0 } } } +
diff -r edf0f1fcb16b -r 699055e89c7d main.h --- 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