Ball drop game with menus and highscore tracking developed for ELEC2645 at the University of Leeds.

Dependencies:   N5110 mbed PowerControl

Game developed for ELEC 2645.

Extremely detailed report outlining all aspects of project found below. /media/uploads/AppleJuice/projectreport.pdf

Files at this revision

API Documentation at this revision

Comitter:
AppleJuice
Date:
Fri May 08 16:30:15 2015 +0000
Parent:
19:97e0516dd6b2
Commit message:
backlight enabled

Changed in this revision

GameScreen.cpp Show annotated file Show diff for this revision Revisions of this file
GameScreen.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- a/GameScreen.cpp	Fri May 08 12:17:39 2015 +0000
+++ b/GameScreen.cpp	Fri May 08 16:30:15 2015 +0000
@@ -6,32 +6,30 @@
 void GameScreen::Initialize()
 {
     init();         //power up screen and set brightness
-    
+    setBrightness(1.0);
     //set ball pos
-    playerBall.x = maxX_/2; 
+    playerBall.x = maxX_/2;
     playerBall.y = maxY_ - (int)(maxY_/3 * 2) - 5;
-    
-    createAllPlatforms(); 
+
+    createAllPlatforms();
 }
 
 //draw platform
 //  ___________  ________  < y
-//               ^ x       
+//               ^ x
 void GameScreen::drawPlatform(int x,int y)
-{    
-    for (int a = 0; a < 48; a ++)
-    {
-        for (int b = y; b < (y+platThickness_); b++)
-        {
+{
+    for (int a = 0; a < 48; a ++) {
+        for (int b = y; b < (y+platThickness_); b++) {
             //skip pixels of gap
             if (a > x && a < (x + platGapSize_))
-                break;            
-            
+                break;
+
             //skip pixels below maxY (lets platforms 'emerge' instead of 'appear')
             if (b > (maxY_ - 1))
                 break;
-            
-            setPixel(b,a);    
+
+            setPixel(b,a);
         }
     }
 }
@@ -39,26 +37,24 @@
 //erase platform
 void GameScreen::erasePlatform(int y)
 {
-    for (int a = 0; a < 48; a ++)
-    {
-        for (int b = y; b < (y+platThickness_); b++)
-        {            
+    for (int a = 0; a < 48; a ++) {
+        for (int b = y; b < (y+platThickness_); b++) {
             //skip pixels below maxY (lets platforms 'emerge' instead of 'appear')
             if (b > (maxY_ - 1))
                 break;
-            
-            clearPixel(b,a);    
+
+            clearPixel(b,a);
         }
     }
 }
 
 //draw the player ball where (x,y) is top right corner.
-//      XXP <-- P(x,y) 
+//      XXP <-- P(x,y)
 //     XXXX
 //     XXXX
-//      XX    
+//      XX
 void GameScreen::drawBall()
-{   
+{
     //more elegant ways to do this...but this is most efficient
     setPixel(playerBall.y,playerBall.x+1);
     setPixel(playerBall.y,playerBall.x+2);
@@ -71,12 +67,12 @@
     setPixel(playerBall.y+2,playerBall.x+2);
     setPixel(playerBall.y+2,playerBall.x+3);
     setPixel(playerBall.y+3,playerBall.x+1);
-    setPixel(playerBall.y+3,playerBall.x+2);    
+    setPixel(playerBall.y+3,playerBall.x+2);
 }
 
 //draw the player ball where (x,y) is top right corner.
 void GameScreen::eraseBall()
-{   
+{
     clearPixel(playerBall.y,playerBall.x+1);
     clearPixel(playerBall.y,playerBall.x+2);
     clearPixel(playerBall.y+1,playerBall.x);
@@ -88,18 +84,17 @@
     clearPixel(playerBall.y+2,playerBall.x+2);
     clearPixel(playerBall.y+2,playerBall.x+3);
     clearPixel(playerBall.y+3,playerBall.x+1);
-    clearPixel(playerBall.y+3,playerBall.x+2);     
+    clearPixel(playerBall.y+3,playerBall.x+2);
 }
 
-void GameScreen::createAllPlatforms() 
-{            
-    for (int n = 0; n < numPlatforms_ ; n++)
-    {
+void GameScreen::createAllPlatforms()
+{
+    for (int n = 0; n < numPlatforms_ ; n++) {
         //create new platform and add to allPlatform array.
-        Platform *newPlatform = new Platform;                           
-        newPlatform->id = n;                                
+        Platform *newPlatform = new Platform;
+        newPlatform->id = n;
         newPlatform->x = rand() % (maxX_-platGapSize_ + 1) - 1;         //randomlly select platform location
-        newPlatform->y = maxY_ - n*platSpacing_ - platThickness_ + 1;   
+        newPlatform->y = maxY_ - n*platSpacing_ - platThickness_ + 1;
         allPlatforms[n] = newPlatform;
     }
 }
@@ -107,39 +102,34 @@
 //Garbage cleanup, free all the platforms!
 void GameScreen::freeAllPlatforms()
 {
-    for (int n = 0; n < numPlatforms_ ; n++)
-    {
+    for (int n = 0; n < numPlatforms_ ; n++) {
         delete allPlatforms[n];
-    }    
+    }
 }
 
 void GameScreen::drawAllPlatforms()
 {
-    for (int n = 0; n < numPlatforms_ ; n++)
-    {
+    for (int n = 0; n < numPlatforms_ ; n++) {
         drawPlatform (allPlatforms[n]->x,allPlatforms[n]->y);
-    } 
+    }
 }
 
 void GameScreen::eraseAllPlatforms()
 {
-    for (int n = 0; n < numPlatforms_ ; n++)
-    {
+    for (int n = 0; n < numPlatforms_ ; n++) {
         erasePlatform (allPlatforms[n]->y);
-    } 
+    }
 }
 
 void GameScreen::shiftAllPlatforms(int n )
 {
-    for (int i = 0; i < numPlatforms_ ; i++)
-    {
+    for (int i = 0; i < numPlatforms_ ; i++) {
         if (allPlatforms[i]->y > (platThickness_+5+n))
             allPlatforms[i]->y = allPlatforms[i]->y - n;
-        else
-        {
+        else {
             allPlatforms[i]->y =  maxY_ - platThickness_ + 1+6; //send back to bottom.
             allPlatforms[i]->x = rand() % (maxX_-platGapSize_ + 1) - 1; //select a new random position of gap!
-            
+
         }
     }
 }
@@ -149,13 +139,11 @@
     int closestY = 100;
     Platform closestPlatform;
     //scan each platform and determin which is closest.
-    for (int i = 0; i < numPlatforms_; i++)
-    {
-        
-        if (((allPlatforms[i]->y - y) < closestY) && ((allPlatforms[i]->y - y) >  -1))
-        {
+    for (int i = 0; i < numPlatforms_; i++) {
+
+        if (((allPlatforms[i]->y - y) < closestY) && ((allPlatforms[i]->y - y) >  -1)) {
             closestY = allPlatforms[i]->y-y;
-            closestPlatform = *allPlatforms[i];            
+            closestPlatform = *allPlatforms[i];
         }
     }
     return closestPlatform;
@@ -171,51 +159,43 @@
 void GameScreen::printString(const char * str,int x,int y,bool invert)
 {
     //set all pixels in rows to black
-    if (invert){
-        for (int a = 0; a < 48; a ++)
-        {
-            for (int b = y; b < (y+9); b++)
-            {          
-                setPixel(b,a);    
+    if (invert) {
+        for (int a = 0; a < 48; a ++) {
+            for (int b = y; b < (y+9); b++) {
+                setPixel(b,a);
             }
         }
     }
-    
+
     //scan through string, rotating font5x7 array and printing charector.
-    while (*str)
-    {
+    while (*str) {
 
         //each byte in row
-        for (int i = 0; i < 5; i++)
-        {
+        for (int i = 0; i < 5; i++) {
             //each bit in byte
-            for (int b = 0; b < 7; b++)
-            {   
+            for (int b = 0; b < 7; b++) {
                 if (invert)
-                    setPixel(y+b+1,x-i+1);     
-                            
-                if (font5x7[(*str - 32)*5 + i] & (1<<b)) //bitwise comparison to mask at desired pixel
-                {             
-                    setPixel(y+b+1,x-i+1); 
+                    setPixel(y+b+1,x-i+1);
+
+                if (font5x7[(*str - 32)*5 + i] & (1<<b)) { //bitwise comparison to mask at desired pixel
+                    setPixel(y+b+1,x-i+1);
                     if (invert)
-                        clearPixel(y+b+1,x-i+1);                   
+                        clearPixel(y+b+1,x-i+1);
+                } else {
+                    if (!invert)
+                        clearPixel(y+b+1,x-i+1);
                 }
-                else
-                {
-                    if (!invert)
-                        clearPixel(y+b+1,x-i+1); 
-                }   
-            }    
-        }        
+            }
+        }
         str ++; //next char in string
         x -= 6;
-    }            
+    }
 }
 
 void GameScreen::displayStartScreen()
 {
     clear();
-    printString("LET",maxX_ - 14,-1);   
+    printString("LET",maxX_ - 14,-1);
     printString("THE BALL",maxX_ - 2,7);
     printString("DROP!",maxX_ - 12,16);
     printString("This way",maxX_ - 2,30);
@@ -224,7 +204,7 @@
     printString("by: ",maxX_ - 2,61);
     printString("Thomas",maxX_ - 9,69);
     printString("Davies",maxX_ - 9,76);
-    refresh();    
+    refresh();
 }
 
 void GameScreen::displayInstructionScreen()
@@ -238,14 +218,14 @@
     printString("you'll",maxX_ - 2,39);
     printString("surely",maxX_ - 2,47);
     printString("DIE!!",maxX_ - 2,55);
-    printString("------->",maxX_ - 2,75);    
-    refresh();    
+    printString("------->",maxX_ - 2,75);
+    refresh();
 }
 
 void GameScreen::displayInstructionScreen2()
 {
     clear();
-    printString("CONTROLS",maxX_ - 2,-1);    
+    printString("CONTROLS",maxX_ - 2,-1);
     printString("Use the",maxX_ - 2,15);
     printString("joystick",maxX_ - 2,23);
     printString("to move",maxX_ - 2,32);
@@ -253,8 +233,8 @@
     printString("right.",maxX_ - 2,47);
     printString("Click to",maxX_ - 2,55);
     printString("Pause!",maxX_ - 2,63);
-    printString("------->",maxX_ - 2,75);    
-    refresh();    
+    printString("------->",maxX_ - 2,75);
+    refresh();
 }
 
 void GameScreen::displayCountdown()
@@ -263,22 +243,20 @@
     Timer countdown;        //timer for countdown
     char buffer[10];
     countdown.start();
-    printString("Survive!",maxX_ - 2,10);  
-    refresh(); 
-    
+    printString("Survive!",maxX_ - 2,10);
+    refresh();
+
     int prevTime = -1;
     //countdown from 5 to 1, in seconds.
-    while (countdown.read() < 5)
-    {
-        if (floor(countdown.read()) > prevTime)
-        {
+    while (countdown.read() < 5) {
+        if (floor(countdown.read()) > prevTime) {
             sprintf(buffer,"..%1.0f..",(5 - floor(countdown.read())));
             printString(buffer,maxX_ - 10,20 + 10*countdown.read());
             refresh();
-            prevTime = countdown.read(); 
+            prevTime = countdown.read();
         }
     }
-    countdown.stop();     
+    countdown.stop();
 }
 
 void GameScreen::displayEndScreen(int lvl,int *cursor, bool isRecord)
@@ -289,14 +267,14 @@
     printString("GameOver",maxX_ - 2,-1);
     printString("   :(  ",maxX_ - 2,7);
     printString(buffer,maxX_ - 2,23);
-    printString("Reached!",maxX_ - 2,32);    
+    printString("Reached!",maxX_ - 2,32);
 
     //only display record option if player achieved record!
     if (isRecord)
         printString("Record",maxX_ - 8,55,cursor[0]);
-           
+
     printString("View",maxX_ - 15,63,cursor[1]);
-    printString("Restart",maxX_ - 5,71,cursor[2]); 
+    printString("Restart",maxX_ - 5,71,cursor[2]);
     refresh();
 }
 
@@ -305,8 +283,8 @@
     clear();
     printString("Enter",maxX_ - 2,-1);
     printString("Initials",maxX_ - 2,7);
-    
-    //letter entry  
+
+    //letter entry
     char buffer[2];
     sprintf(buffer,"%c",ltr1);
     printString(buffer,maxX_ - 23,20,cursor[0]);
@@ -317,9 +295,9 @@
 
     printString("Click",maxX_ - 2,59);
     printString("when",maxX_ - 2,67);
-    printString("finished",maxX_ - 2,75);   
+    printString("finished",maxX_ - 2,75);
     refresh();
-    
+
 }
 
 void GameScreen::displayHighScores(char *s_hs0,char *s_hs1,char *s_hs2,int *d_hs)
@@ -328,24 +306,24 @@
     printString("SCORES",maxX_ - 2,-1);
 
     char buffer[10];
-    
+
     sprintf(buffer,"%s %d",s_hs0,d_hs[0]);
     printString(buffer,maxX_ - 2,15);
 
-    sprintf(buffer,"%s %d",s_hs1,d_hs[1]);    
+    sprintf(buffer,"%s %d",s_hs1,d_hs[1]);
     printString(buffer,maxX_ - 2,33);
-    
-    sprintf(buffer,"%s %d",s_hs2,d_hs[2]);  
-    printString(buffer,maxX_ - 2,51);    
-    
+
+    sprintf(buffer,"%s %d",s_hs2,d_hs[2]);
+    printString(buffer,maxX_ - 2,51);
+
     printString("Click to",maxX_ - 2,68);
     printString("reset!",maxX_ - 2,76);
-    refresh(); 
+    refresh();
 }
 
 void GameScreen::displayPauseScreen(int *cursor,char isSound)
 {
-    clear();   
+    clear();
     printString("PAUSED",maxX_ - 2,7);
 
     char buffer[10];
--- a/GameScreen.h	Fri May 08 12:17:39 2015 +0000
+++ b/GameScreen.h	Fri May 08 16:30:15 2015 +0000
@@ -2,9 +2,9 @@
 @file GameScreen.h
 @brief Simple library for managing "Let The Ball Drop" Game screen
 @brief extends on N5110 library created by Craig.A.Evans
-@brief Adds functionality to animate game platforms and ball, 
+@brief Adds functionality to animate game platforms and ball,
 @brief also displays various game screens throughout gameplay.
-@brief printString function from base class N5110 is overwritten and 
+@brief printString function from base class N5110 is overwritten and
 @brief extened to vertical orientation text and inverted pixel scheme.
 @author Thomas Davies
 @date May 2015
@@ -52,11 +52,11 @@
     * @param dc  Pin connected to data/command select (pin 5)
     * @param mosi Pin connected to data input (MOSI) (pin 6)
     * @param sclk Pin connected to serial clock (SCLK) (pin 7)
-    * @param led Pin connected to LED backlight (must be PWM) (pin 8) 
+    * @param led Pin connected to LED backlight (must be PWM) (pin 8)
     *
-    */        
+    */
     explicit GameScreen(PinName pwrPin, PinName scePin, PinName rstPin, PinName dcPin, PinName mosiPin, PinName sclkPin, PinName ledPin)
-        :N5110(pwrPin, scePin,rstPin,dcPin,mosiPin,sclkPin,ledPin) {}   
+        :N5110(pwrPin, scePin,rstPin,dcPin,mosiPin,sclkPin,ledPin) {}
 
     /** Initialise Game Screen
     *
@@ -65,7 +65,7 @@
     *
     */
     void Initialize();
-    
+
     /** Print String
     *
     * Overrides N5110::printString(*) to allow vertical orientation text.
@@ -77,36 +77,36 @@
     *@param invert - color inversion toggle (default = false)
     *
     */
-    void printString(const char * str,int x,int y,bool invert = false);   
-    
+    void printString(const char * str,int x,int y,bool invert = false);
+
     /** Draw Ball
     *
     * Draws ball on screen from playerBall struct in object, requires refresh.
     *
-    */  
+    */
     void drawBall();
-    
+
     /** Erases Ball
     *
     * Erases ball on screen from playerBall struct in object, requires refresh.
     *
-    */ 
-    void eraseBall();  
-    
+    */
+    void eraseBall();
+
     /** Draws All Platforms
     *
     * Draws all platforms from array allPlatforms in object, requires refresh.
     *
-    */      
+    */
     void drawAllPlatforms();
-    
+
     /** Erases All Platforms
     *
     * Erases all platforms on screen from array allPlatforms in object, requires refresh.
     *
-    */   
+    */
     void eraseAllPlatforms();
-    
+
     /** Shifts Platforms Up
     *
     * Alter array of platforms to shift each platform up n pisxels, requires refresh.
@@ -114,47 +114,47 @@
     *
     */
     void shiftAllPlatforms(int n=1);
-    
+
     /** Finds next closest platform
-    * 
+    *
     *@param y - vertical position on screen
     *@return next closest platform to y.
     *
     */
     Platform nextClosestPlatform(int y);
-    
+
     /** Displays The Start Screen
     *
     * first screen user sees, author name & title
     *
     */
     void displayStartScreen();
-    
+
     /** Displays Instruction Screen
     *
     * shows game instructions, navigation method and "back story"
     *
     */
     void displayInstructionScreen();
-    
+
     /** Displays Countdown
     *
     * countdown from 5 to 1 displayed on screen.
     *
     */
     void displayCountdown();
-    
+
     /** displays Game Over Screen
-    * 
-    * shows player level, and displays options. 
+    *
+    * shows player level, and displays options.
     * options can be highlighted according to cursor location array
     * @param lvl - game level to be displayed.
     * @param cursor - array of ints used to highlight options.
     * @param isRecord - only display record option if player achieved a record
-    * 
+    *
     */
     void displayEndScreen(int lvl,int *cursor,bool isRecord);
-    
+
     /** Display Initial Entry Screen
     *
     * screen for user to enter initials.
@@ -166,21 +166,21 @@
     *
     */
     void displayRecordScreen(int *cursor, char ltr1, char ltr2,char ltr3);
-    
+
     /** Display High Score Screen
-    *  
+    *
     *@param s_hs0 - initials of top player.
     *@param s_hs1 - initials of second player.
     *@param s_hs2 - initials of third player.
     *@param d_hs - array of high score levels.
     */
     void displayHighScores(char *s_hs0,char *s_hs1,char *s_hs2,int *d_hs);
-    
+
     /** Display Second instruction Screen
     *
     */
     void displayInstructionScreen2();
-    
+
     /** Display Pause Menu Screen
     *
     *@param cursor - array of ints used to highlight selection
@@ -188,36 +188,53 @@
     *
     */
     void displayPauseScreen(int *cursor, char isSound);
-    
+
     /** Sets Ball Position
     *
     *@param x - new x coordinate of ball (right side)
     *@param y - new y coordinate of ball (top)
     */
-    void        setBallPos(int x, int y)        { playerBall.x = x; playerBall.y = y; }
+    void        setBallPos(int x, int y)        {
+        playerBall.x = x;
+        playerBall.y = y;
+    }
 
     //ACCESSOR FUNCTIONS
-    /** @return platform gap size */    
-    int         getPlatGapSize()                { return platGapSize_;       } 
+    /** @return platform gap size */
+    int         getPlatGapSize()                {
+        return platGapSize_;
+    }
+
+    /** @return screen max Y */
+    int         getMaxY()                          {
+        return maxY_;
+    }
+
+    /** @return screen max X */
+    int         getMaxX()                          {
+        return maxX_;
+    }
 
-    /** @return screen max Y */ 
-    int         getMaxY()                          { return maxY_;             }
-    
-    /** @return screen max X */ 
-    int         getMaxX()                          { return maxX_;             }
-    
-    /** @return platform thickness */ 
-    int         getPlatThickness()                 { return platThickness_;    }
-    
-    /** @return ball radius */ 
-    int         getBallR()                      { return ballRadius_;       }
-    
-    /** @return ball X coordinate */ 
-    int         getBallX()                      { return playerBall.x;      }
-    
-    /** @return ball Y coordinate*/ 
-    int         getBallY()                      { return playerBall.y;      }
-    
+    /** @return platform thickness */
+    int         getPlatThickness()                 {
+        return platThickness_;
+    }
+
+    /** @return ball radius */
+    int         getBallR()                      {
+        return ballRadius_;
+    }
+
+    /** @return ball X coordinate */
+    int         getBallX()                      {
+        return playerBall.x;
+    }
+
+    /** @return ball Y coordinate*/
+    int         getBallY()                      {
+        return playerBall.y;
+    }
+
 
     /** Creates All Platforms
     *
@@ -225,17 +242,17 @@
     *
     */
     void createAllPlatforms();
-    
-   /** Draws Platform
-   *
-   * Draws a platform with thickness _platThickness at height y and gap x.
-   *
-   *@param x - location of gap on platform (right hand pixel)
-   *@param y - y position of platform
-   *
-   */
+
+    /** Draws Platform
+    *
+    * Draws a platform with thickness _platThickness at height y and gap x.
+    *
+    *@param x - location of gap on platform (right hand pixel)
+    *@param y - y position of platform
+    *
+    */
     void drawPlatform(int x,int y);
-    
+
     /** Draws Platform
     *
     * Erases a platform with thickness _platThickness at height y.
@@ -244,14 +261,14 @@
     *
     */
     void erasePlatform(int y);
-    
+
     /** Free All Platforms
     *
     * frees memory of each platform in 'allPlatforms' array and destroys the array.
     *
     */
-    void freeAllPlatforms();      
-    
+    void freeAllPlatforms();
+
     static const int platGapSize_ = 8;          ///< standard platform gap width in pixels
     static const int platThickness_ = 2;        ///< platform thickness in pixels
     static const int platSpacing_ = 14;         ///< subsequent platform spacing in pixels
--- a/main.cpp	Fri May 08 12:17:39 2015 +0000
+++ b/main.cpp	Fri May 08 16:30:15 2015 +0000
@@ -10,18 +10,19 @@
 
 int main()
 {
-    
+    DigitalOut backLight(p26);
+    backLight.write(1);
     lcd.Initialize();
     powerSave();
-    
+
     lcd.displayStartScreen();
     while(!isRight()) {}       //wait until right button pressed
 
     wait(0.5);          //just to ignore layover from first button press.
-    
+
     lcd.displayInstructionScreen();
     while(!isRight()) {}    //wait until right button pressed.
-    
+
     wait(0.5);
     lcd.displayInstructionScreen2();
     while(!isRight()) {}    //wait until right button pressed.
@@ -47,11 +48,10 @@
                 //advance platforms
                 advancePlatforms(numPixelsToJump);
                 numPlatformShifts ++;
-                
-                if (numPlatformShifts%5 == 0)
-                {
+
+                if (numPlatformShifts%5 == 0) {
                     gameLevel ++;
-                 }   
+                }
                 refresh = true;
             }
 
@@ -78,8 +78,8 @@
                     isFirstHit = true;
                 }
             }
-            
-            if ((clockCount%(-45*gameSpeed + 2045) == 0)) {    //starting levels are quick to progress, later slower.                  
+
+            if ((clockCount%(-45*gameSpeed + 2045) == 0)) {    //starting levels are quick to progress, later slower.
                 if (isFirstSpeedUp) //skip first accepted modulus!
                     isFirstSpeedUp = false;
                 else {
@@ -87,15 +87,14 @@
                     isFirstSpeedUp = true;
                 }
             }
-            
-            if (joystickButton.read())      //pause menu!
-            {
+
+            if (joystickButton.read()) {    //pause menu!
                 int oldClock = clockCount;  //save the clock count!
                 pauseScreenController();
                 clockCount = oldClock;
                 wait(0.3);
                 lcd.clear();
-                refresh = true;    
+                refresh = true;
             }
 
             if (refresh) {
@@ -107,13 +106,13 @@
                 lcd.refresh();
                 refresh = false;
             }
-            
+
 
             //check if ball hit roof
             if (lcd.getBallY() == 7) {
                 break;
             }
-            
+
 
             isFirstCheck = false;
         }
@@ -140,7 +139,7 @@
     if(!isBallFalling(lcd.getBallY()-n)) {
         //auditory feedback if first collision
         if (isFirstHit) {
-            boop(); 
+            boop();
             isFirstHit = false;
         }
         //move ball up with platform
@@ -181,22 +180,22 @@
     Platform closestPlatform = lcd.nextClosestPlatform(lcd.getBallY() - lcd.getBallR()+2);
 
     int ballRight = lcd.getBallX();
-    int ballLeft = ballRight+lcd.getBallR();    
+    int ballLeft = ballRight+lcd.getBallR();
     int ballTop = lcd.getBallY();
     int ballBottom = ballTop + lcd.getBallR();
 
-    if (dir == 1) {        
+    if (dir == 1) {
         if (ballBottom > closestPlatform.y)    //is ball inside a gap in platform?
             if (ballLeft >= (closestPlatform.x+lcd.getPlatGapSize()))    //is the ball next to gap wall?
-                    return false;
+                return false;
         if (ballLeft < lcd.getMaxX()) {    //is ball next to left hand wall?
-            return true;            
+            return true;
         }
     } else if (dir == 0) {
         if (ballBottom > closestPlatform.y)    //is ball inside a gap in platform?
             if (ballRight <= closestPlatform.x)
                 return false;
-        
+
         if (ballRight > 0) {   //right hand wall check
             return true;
         }
@@ -283,14 +282,14 @@
 
     //check if user achieved high score
     bool record = isRecord();
-    
+
     //if not a record move mouse start to second option
     if (!record)
         cursorLoc = 1;
-    
+
     lcd.displayEndScreen(gameLevel,cursorArray[cursorLoc],record);
-    bool change = false;    
-    
+    bool change = false;
+
     while (true) {
         if (isUp()) {
             cursorLoc ++;   //advance cursor menu
@@ -350,7 +349,7 @@
 
     //array of ints, each corresponding to letter in letters array
     int ptr[3] = {0,0,0};
-    
+
     //cursor management variables
     int cursorLoc = 0;
     int cursorArray[3][3] = {
@@ -418,14 +417,14 @@
     if (fp != NULL) {
 
         char buffer[2];
-    
+
         fscanf(fp,"%3s,%s",s_hs0,buffer);
         d_hs[0] = atoi(buffer);
         fscanf(fp,"%3s,%s",s_hs1,buffer);
         d_hs[1] = atoi(buffer);
         fscanf(fp,"%3s,%s",s_hs2,buffer);
         d_hs[2] = atoi(buffer);
-    
+
         fclose(fp);
     }
     //else set arbitrary values!
@@ -433,10 +432,10 @@
         d_hs[0] = 0;
         d_hs[1] = 0;
         d_hs[2] = 0;
-        
+
         strcpy(s_hs0,"---");
         strcpy(s_hs1,"---");
-        strcpy(s_hs2,"---");    
+        strcpy(s_hs2,"---");
     }
 
     if (isRecord) {
@@ -472,11 +471,11 @@
 {
     //check if lvl is in top 3
     FILE *fp = fopen("/local/scores.csv","r");  //open for reading.
-    
+
     //if file doesn't exist, then player has a highscore!
     if (fp == NULL)
         return true;
-        
+
     int highScore;
     char buffer[2];
     char temp[3];
@@ -494,24 +493,21 @@
 }
 
 void boop ()
-{ 
-    if (isSound == 'Y')
-    {
+{
+    if (isSound == 'Y') {
         buzzer.write(1);
         lowFlipper.attach_us(&pwmLow,pwmCount);
-    }        
+    }
 }
 
 void pwmLow()
 {
-    if (pwmCount != 4000)
-    {
+    if (pwmCount != 4000) {
         buzzer.write(0);
         highFlipper.attach_us(&boop,pwmCount);
         pwmCount += 50;
-   } 
-   else
-    pwmCount = 1000;
+    } else
+        pwmCount = 1000;
 
 }
 
@@ -524,9 +520,9 @@
         {0,1,0},
         {0,0,1}
     };
-    
+
     lcd.displayPauseScreen(cursorArray[cursorLoc],isSound);
-    
+
     bool change = false;
     bool resume = false;
 
@@ -543,7 +539,7 @@
             else
                 isSound = 'Y';
             change = true;
-        } 
+        }
 
         //cyclical mouse management
         if (cursorLoc == 3)
@@ -566,14 +562,14 @@
                     resume = true;
                     break;
                 default:
-                    break;   
-                    }                 
+                    break;
+            }
         }
     }
 }
 
 void powerSave()
 {
-        PHY_PowerDown();    //power down ethernet
-        //mbed automatically manages peripheral power, no need to manually disable each
+    PHY_PowerDown();    //power down ethernet
+    //mbed automatically manages peripheral power, no need to manually disable each
 }
--- a/main.h	Fri May 08 12:17:39 2015 +0000
+++ b/main.h	Fri May 08 16:30:15 2015 +0000
@@ -1,4 +1,4 @@
-/** 
+/**
 @file main.h
 @brief Header file for main game containing function prototypes, namespaces and global variables.
 @autor Thomas Davies
@@ -65,7 +65,7 @@
 @namespace gameClock
 @brief the master clock of game operation. All animation timings are based on this clock.
 */
-Ticker gameClock;   
+Ticker gameClock;
 
 /**
 @namespace lowFlipper
@@ -75,9 +75,9 @@
 
 /**
 @namespace highFlipper
-@brief used for PWM speaker control, triggers pin high. 
+@brief used for PWM speaker control, triggers pin high.
 */
-Timeout highFlipper; 
+Timeout highFlipper;
 
 //##############GLOBAL VARIABLES##################//
 
@@ -100,7 +100,7 @@
 /** Advance Platforms
 *
 * animate platforms shift up n pixels
-* 
+*
 * @param n - number of pixels to shift
 */
 void advancePlatforms(int n=1);
@@ -155,7 +155,7 @@
 */
 bool isBallDirClear(int dir);
 
-/** Game Over Controller 
+/** Game Over Controller
 *
 * Displays end game screen, and allows user interaction with options via joystick.
 * Also controls option selection and next screens.
@@ -190,7 +190,7 @@
 
 /** PWM speaker control function
 *
-* makes a boop sound used for collisions with platforms. 
+* makes a boop sound used for collisions with platforms.
 */
 void boop ();