Retro game that let's the player steer a ball through a hole filled maze. Has multiple levels of increasing difficulty.

Dependencies:   LCD_ST7735 MusicEngine RETRO_BallsAndThings mbed

Ball and Holes

In this game I attempted to create somewhat natural movement of the ball by implementing gravity and friction which combined over time determine the speed of the ball. Playing with the settings (aka. the magic numbers) that are spread out all over game.cpp, gives different effects, such as an icy, rough or liquid-like surface.

It took some time to figure out how to post my very first youtube video. Sorry for the shaky recording. Trying to record the video with my phone while playing the game in one hand was quite challenging, but here it is;

The left and right buttons are used to cheat: restart the current or go to the next level. Up and down control the game-tick. During game-play the robot-button shows the accelerator graph and the ship-button mutes the sound.

BTW. If your ball happens to get stuck, tilting the console in the opposite direction will set it free. For sake of argument: these magnetic wall-ends are in the words of Bob Ross "a happy accident". Since there is no specific code for it, others might call it a bug. As it results in more interesting game-play, I didn't attempt to fix it, but left a comment for those who dare to look at the mess I call code.

Files at this revision

API Documentation at this revision

Comitter:
maxint
Date:
Tue Feb 03 19:02:27 2015 +0000
Parent:
1:c1ee4c699517
Child:
3:ca8b21da67dc
Commit message:
Added more balls

Changed in this revision

Ball.cpp Show annotated file Show diff for this revision Revisions of this file
Ball.h Show annotated file Show diff for this revision Revisions of this file
Game.cpp Show annotated file Show diff for this revision Revisions of this file
Game.h Show annotated file Show diff for this revision Revisions of this file
Paddle.cpp Show annotated file Show diff for this revision Revisions of this file
Paddle.h Show annotated file Show diff for this revision Revisions of this file
SoundFX.h Show annotated file Show diff for this revision Revisions of this file
SoundFx.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Ball.cpp	Sun Feb 01 16:21:24 2015 +0000
+++ b/Ball.cpp	Tue Feb 03 19:02:27 2015 +0000
@@ -1,8 +1,13 @@
 #include "Ball.h"
 
+Ball::Ball() : vSpeed()
+{   // constructor
+}
+
 Ball::Ball(LCD_ST7735* pDisp) : vSpeed()
 {   // constructor
     this->pDisp=pDisp;
+    this->fActive=false;
 }
 
 uint16_t Ball::dimmedColor(uint16_t uColor)
@@ -46,7 +51,10 @@
     }
     else
     {
-        if(this->vSpeed.getSize()>=1.0) this->vSpeed.add(-1.0);
+        if(this->vSpeed.getSize()>=1.0)
+            this->vSpeed.add(-1.0);
+        else        // TODO: added code below to allow zero speed pause of ball
+            this->vSpeed.set(0,0);
     }
 }
 
--- a/Ball.h	Sun Feb 01 16:21:24 2015 +0000
+++ b/Ball.h	Tue Feb 03 19:02:27 2015 +0000
@@ -13,7 +13,9 @@
 {
     public:
         static const bool fFixed=false;
+        bool fActive;
 
+        Ball();
         Ball(LCD_ST7735* pDisp);
         void initialize(int X, int Y, int R, uint16_t uColor);
         void setSpeed(int X, int Y);
--- a/Game.cpp	Sun Feb 01 16:21:24 2015 +0000
+++ b/Game.cpp	Tue Feb 03 19:02:27 2015 +0000
@@ -2,9 +2,9 @@
 
 const char* Game::LOSE_1 = "You lose.";
 const char* Game::LOSE_2 = "Press ship to restart.";
-const char* Game::SPLASH_1 = "Press ship to start.";
-const char* Game::SPLASH_2 = "Press robot to switch.";
-const char* Game::SPLASH_3 = "mod:Tilt by Maxint.";
+const char* Game::SPLASH_1 = "-*- Balls and paddle -*-";
+const char* Game::SPLASH_2 = "Press ship to start.";
+const char* Game::SPLASH_3 = "Made by Maxint";
 
 
 #define WHITE Color565::White
@@ -21,7 +21,7 @@
 
 
 Game::Game() : left(P0_14, PullUp), right(P0_11, PullUp), down(P0_12, PullUp), up(P0_13, PullUp), square(P0_16, PullUp), circle(P0_1, PullUp), led1(P0_9), led2(P0_8), 
-    pwm(P0_18), ain(P0_15), i2c(P0_5, P0_4), disp(P0_19, P0_20, P0_7, P0_21, P0_22, P1_15, P0_2, LCD_ST7735::RGB), accel(this->I2C_ADDR, &disp), vGravity(0, 0.1), ball(&disp), paddle(&disp)
+    ain(P0_15), i2c(P0_5, P0_4), disp(P0_19, P0_20, P0_7, P0_21, P0_22, P1_15, P0_2, LCD_ST7735::RGB), accel(this->I2C_ADDR, &disp), vGravity(0, 0.1), ball(&disp), paddle(&disp)
 {
     this->disp.setOrientation(LCD_ST7735::Rotate270, false);
     this->disp.setForegroundColor(WHITE);
@@ -34,10 +34,16 @@
     this->lastDown = false;
     this->mode = true;
 
-    this->initialize();
+
+    //this->aBalls[2]={ Ball(&disp),  Ball(&disp) };
+    for(int i=0; i<NUM_BALLS; i++)
+        this->aBalls[i]=Ball(&(this->disp));
+
+    //this->initialize();
 }
 
-void Game::printDouble(double value, int x, int y) {
+void Game::printDouble(double value, int x, int y)
+{
     char buffer[10];
     int len = sprintf(buffer, "%.1f ", value);
     
@@ -48,33 +54,145 @@
 {
     this->disp.clearScreen();
 
-    this->initializeBall();     // start first ball
+//    this->initializeBall();     // start first ball
+//    this->initializeBalls();     // start first ball
+
+    this->setNoBalls();     // reset all balls
+    this->newBall();     // start first ball
     this->initializePaddle();
+    //this->paddle.draw();
+
        
 //    this->paddleX = WIDTH / 2 - Game::PADDLE_WIDTH / 2;
-    this->pwmTicksLeft = 0;
+    this->snd.reset();
     this->nLives = 4;
     this->nScore = 0;
     
-    this->pwm.period_ms(1);
-    this->pwm.write(0.00);
-
     this->tWait.start();      // start the timer
     
 }
-    
+
+
+void Game::initializePaddle()
+{
+    this->paddle.initialize(WIDTH / 2 - Game::PADDLE_WIDTH/2, HEIGHT - Game::PADDLE_HEIGHT, Game::PADDLE_WIDTH, Game::PADDLE_HEIGHT);
+    this->paddle.draw();
+}
+
+
+void Game::updatePaddle()
+{
+    if (!this->left.read())  // note: read is LOW (0) when button pressed
+        this->paddle.move(Vector(-1 * Game::PADDLE_SPEED, 0));
+    else if (!this->right.read())
+        this->paddle.move(Vector(Game::PADDLE_SPEED, 0));
+    else
+    {
+        int i=this->checkTilt();
+        if(i>0)
+            this->paddle.move(Vector(Game::PADDLE_SPEED, 0));
+        else if(i<0)
+            this->paddle.move(Vector(-1 * Game::PADDLE_SPEED, 0));
+        else if(this->paddle.hasChanged())
+            paddle.move(Vector(0, 0));  // move to same place to restrict redraws
+    }
+}
+
+
+
+
+/*
 void Game::initializeBall()
 {
     this->ball.initialize(WIDTH / 2 - Game::BALL_RADIUS, HEIGHT / 4 - Game::BALL_RADIUS, Game::BALL_RADIUS, Color565::fromRGB(0xFF, 0x33, 0x33));
     this->ball.setSpeed(rand() % 2 ? 1 : -1, rand() % 2 ? 1 : -1);
 }
+*/
 
-void Game::initializePaddle()
+/*
+void Game::initializeBalls()
+{
+    for(int i=0; i<NUM_BALLS; i++)
+    {
+        this->aBalls[i].initialize(WIDTH / 2 - Game::BALL_RADIUS, HEIGHT / 4 - Game::BALL_RADIUS, Game::BALL_RADIUS, Color565::fromRGB(i==0?0xFF:0x33, i==1?0xFF:0x33, i==2?0xFF:0x33));
+        //float ftRandX=rand() % 2 ? 1 : -1;
+        float ftRandX=((rand() % 20) - 10)/10 ;
+        float ftRandY=rand() % 2 ? 1 : -1;
+        this->aBalls[i].setSpeed(ftRandX, ftRandY);
+    }
+}
+*/
+
+void Game::setNoBalls()
 {
-    this->paddle.initialize(WIDTH / 2 - Game::PADDLE_WIDTH/2, HEIGHT - Game::PADDLE_HEIGHT, Game::PADDLE_WIDTH, Game::PADDLE_HEIGHT);
+    for(int i=0; i<NUM_BALLS; i++)
+        this->aBalls[i].fActive=false;
+}
+
+void Game::newBall()
+{
+    for(int i=0; i<NUM_BALLS; i++)
+    {
+        if(this->aBalls[i].fActive)
+            continue;
+        else
+        {
+            this->aBalls[i].initialize(WIDTH / 2 - Game::BALL_RADIUS, HEIGHT / 4 - Game::BALL_RADIUS, Game::BALL_RADIUS, Color565::fromRGB(i==0?0xFF:0x33, i==1?0xFF:0x33, i==2?0xFF:0x33));
+            //float ftRandX=rand() % 2 ? 1 : -1;
+            //float ftRandY=rand() % 2 ? 1 : -1;
+            float ftRandX=((rand() % 20) - 10)/5.0;
+            float ftRandY=((rand() % 10) - 10)/5.0;
+            //this->aBalls[i].setSpeed(ftRandX, ftRandY);
+            this->aBalls[i].vSpeed.set(ftRandX, ftRandY);
+            this->aBalls[i].fActive=true;
+            break;
+        }
+    }
 }
 
-void Game::tick() {  
+void Game::updateBalls()
+{
+    for(int i=0; i<NUM_BALLS; i++)
+    {
+        if(!this->aBalls[i].fActive)
+            continue;
+
+        this->aBalls[i].update();                    // update the ball position 
+
+        // add downward gravity
+        if(this->aBalls[i].vSpeed.getSize() != 0 && this->aBalls[i].vSpeed.getSize()<10.0)            // TODO: added if statement to allow zero speed pause of ball
+            this->aBalls[i].vSpeed.add(this->vGravity);    // add some gravity
+
+    }
+}
+
+void Game::redrawBalls()
+{
+    for(int i=0; i<NUM_BALLS; i++)
+    {
+        if(!this->aBalls[i].fActive)
+            continue;
+        this->aBalls[i].redraw();                    // update the ball position 
+    }
+}
+
+int Game::countBalls()
+{
+    int nResult=0;
+    for(int i=0; i<NUM_BALLS; i++)
+    {
+        if(this->aBalls[i].fActive)
+            nResult++;
+    }
+    return(nResult);
+}
+
+
+
+
+
+void Game::tick()
+{  
     this->checkButtons();
     
     if (this->mode) {
@@ -85,15 +203,26 @@
             this->tWait.reset();
         }
 */
+
+/*
+        if(this->ball.vSpeed.getSize() != 0)            // TODO: added if statement to allow zero speed pause of ball
+            this->ball.vSpeed.add(this->vGravity);    // add some gravity
+            //this->ball.vSpeed.add(Vector(0, 0.1));    // add some gravity
+        this->ball.update();                    // update the ball position 
+*/
+
+        this->updateBalls();                    // update the ball positions
+
         this->updatePaddle();
-        this->ball.vSpeed.add(Vector(0, 0.1));    // add some gravity
-        this->ball.update();                    // update the ball position 
     
-        this->checkCollision();
+//        this->checkCollision();
+        this->checkPaddle();
+        this->checkBallsCollision();
+//        this->ball.redraw();
+        this->redrawBalls();
         this->paddle.redraw();
-        this->ball.redraw();
         
-        this->checkPwm();
+        this->snd.checkPwm();
         //this->checkScore(); 
         this->checkLives(); 
         
@@ -192,25 +321,101 @@
         wait_ms(1);
     }
         
-    this->disp.clearScreen();
+    //this->disp.clearScreen();
+    this->initialize();     // start a new game
 }
 
 
-void Game::updatePaddle() {
-    if (!this->left.read())  // note: read is LOW (0) when button pressed
-        this->paddle.move(Vector(-1 * Game::PADDLE_SPEED, 0));
-    else if (!this->right.read())
-        this->paddle.move(Vector(Game::PADDLE_SPEED, 0));
-    else
+
+void Game::checkBallsCollision()
+{
+    Rectangle rTop=Rectangle(0, -10, WIDTH, 0);                // Rectangle(0, 0, WIDTH, 1);       // top wall
+    Rectangle rBottom=Rectangle(0, HEIGHT, WIDTH, HEIGHT+10);  // Rectangle(0, HEIGHT, WIDTH, HEIGHT);       // bottom gap
+    Rectangle rLeft=Rectangle(-10, 0, 0, HEIGHT);              // Rectangle(0, 0, 0, HEIGHT);       // left wall
+    Rectangle rRight=Rectangle(WIDTH, 0, WIDTH+10, HEIGHT);       // Rectangle(WIDTH, 0, WIDTH, HEIGHT);       // right wall
+    Rectangle rPaddle=Rectangle(paddle.pos.getX(), paddle.pos.getY(), paddle.pos.getX() + Game::PADDLE_WIDTH, HEIGHT+10);       // Rectangle(this->paddleX, HEIGHT - Game::PADDLE_HEIGHT, this->paddleX + Game::PADDLE_WIDTH, HEIGHT);       // paddle
+    Rectangle rPaddleLeft=Rectangle(paddle.pos.getX(), paddle.pos.getY(), paddle.pos.getX() + Game::PADDLE_WIDTH/3, HEIGHT+10);      // paddle left part
+    Rectangle rPaddleRight=Rectangle(paddle.pos.getX()+ Game::PADDLE_WIDTH/3 + Game::PADDLE_WIDTH/3, paddle.pos.getY(), paddle.pos.getX() + Game::PADDLE_WIDTH, HEIGHT+10);      // paddle right part
+    //Rectangle rScreen=Rectangle(0,0, WIDTH, HEIGHT);            // screen boundary
+
+    Ball* pBall;
+    for(int i=0; i<NUM_BALLS; i++)
     {
-        int i=this->checkTilt();        // don't call too often as this I2C is slow and will delay the game
-        if(i>0)
-            this->paddle.move(Vector(Game::PADDLE_SPEED, 0));
-        else if(i<0)
-            this->paddle.move(Vector(-1 * Game::PADDLE_SPEED, 0));
+        if(!this->aBalls[i].fActive)
+            continue;
+
+        pBall=&(this->aBalls[i]);
+
+        if(pBall->collides(rTop) && pBall->vSpeed.isUp())      // top wall
+        {
+            pBall->Bounce(Vector(1,-1));        // bounce vertical
+            this->snd.beepShort();
+        }
+        if(pBall->collides(rRight) && pBall->vSpeed.isRight())      // right wall
+        {
+            pBall->Bounce(Vector(-1,1));        // bounce horizontal
+            this->snd.beepShort();
+        }
+        if(pBall->collides(rLeft) && pBall->vSpeed.isLeft())      // left wall
+        {
+            pBall->Bounce(Vector(-1,1));        // bounce horizontal
+            this->snd.beepShort();
+        }
+        if(pBall->collides(rPaddle) && pBall->vSpeed.isDown())      // paddle
+        {
+            if(pBall->collides(rPaddleLeft))   pBall->vSpeed.add(Vector(-1,0));       // left side of paddle has bias to the left
+            if(pBall->collides(rPaddleRight))  pBall->vSpeed.add(Vector(1,0));       // right side of paddle has bias to the right
+    
+            
+            // increase the speed of the ball when hitting the paddle to increase difficulty
+            //pBall->Bounce(Vector(1,-1));        // bounce vertical at same speed
+            float ftSpeedMax=3.0;
+            if(this->nScore>50)
+                ftSpeedMax=5.0;
+            if(this->nScore>100)
+                ftSpeedMax=10.0;
+            if(this->nScore>150)
+                ftSpeedMax=999.0;
+            if(pBall->vSpeed.getSize()<ftSpeedMax)            // TODO: added if statement to allow zero speed pause of ball
+                pBall->Bounce(Vector(1,-1.02));        // bounce from paddle at higher speed
+            else
+                pBall->Bounce(Vector(1,-1));        // bounce vertical at same speed
+    
+            this->snd.beepLong();
+            this->nScore++;
+            this->printf(100, 0, "Score: %d ", this->nScore);   
+
+            if(this->nScore>0 && this->nScore%10==0)
+            {
+                this->newBall();
+                this->nLives++;
+            }
+        }
+        if(pBall->collides(rBottom) && pBall->vSpeed.isDown())      // bottom gap
+        {
+            pBall->clearPrev();   // clear the ball from its previous position
+            pBall->clear();   // clear the ball from its current position
+            pBall->vSpeed.set(0,0);
+            pBall->fActive=false;
+            this->nLives--;
+            //this->initializeBall();     // start a new ball
+            if(countBalls()==0)
+            {
+                this->newBall();     // start a new ball
+                this->snd.beepLow();
+            }
+        }
     }
 }
 
+void Game::checkPaddle()
+{
+    Rectangle rScreen=Rectangle(0,0, WIDTH, HEIGHT);            // screen boundary
+
+    this->paddle.checkBoundary(rScreen);
+}
+
+/*
 void Game::checkCollision()
 {
     Rectangle rTop=Rectangle(0, -10, WIDTH, 0);                // Rectangle(0, 0, WIDTH, 1);       // top wall
@@ -222,38 +427,32 @@
     Rectangle rPaddleRight=Rectangle(paddle.pos.getX()+ Game::PADDLE_WIDTH/3 + Game::PADDLE_WIDTH/3, paddle.pos.getY(), paddle.pos.getX() + Game::PADDLE_WIDTH, HEIGHT+10);      // paddle right part
     Rectangle rScreen=Rectangle(0,0, WIDTH, HEIGHT);            // screen boundary
 
-/*
-    if (this->paddle.pos.getX() < 0)
-        this->paddle.pos.setX(0);
-    if (this->paddle.pos.getX() + Game::PADDLE_WIDTH > WIDTH)
-        this->paddle.pos.setX(WIDTH - Game::PADDLE_WIDTH);
-*/
     this->paddle.checkBoundary(rScreen);
    
     if(ball.collides(rTop) && this->ball.vSpeed.isUp())      // top wall
     {
         this->ball.Bounce(Vector(1,-1));        // bounce vertical
-        this->pwmTicksLeft = Game::BOUNCE1_SOUND_TICKS;
+        this->snd.beepShort();
     }
     if(ball.collides(rRight) && this->ball.vSpeed.isRight())      // right wall
     {
         this->ball.Bounce(Vector(-1,1));        // bounce horizontal
-        this->pwmTicksLeft = Game::BOUNCE1_SOUND_TICKS;
+        this->snd.beepShort();
     }
     if(ball.collides(rLeft) && this->ball.vSpeed.isLeft())      // left wall
     {
         this->ball.Bounce(Vector(-1,1));        // bounce horizontal
-        this->pwmTicksLeft = Game::BOUNCE1_SOUND_TICKS;
+        this->snd.beepShort();
     }
     if(ball.collides(rPaddle) && this->ball.vSpeed.isDown())      // paddle
     {
         if(ball.collides(rPaddleLeft))   ball.vSpeed.add(Vector(-1,0));       // left side of paddle has bias to the left
         if(ball.collides(rPaddleRight))  ball.vSpeed.add(Vector(1,0));       // right side of paddle has bias to the right
 
-        //this->ball.Bounce(Vector(1,-1));        // bounce vertical at same speed
-        ball.Bounce(Vector(1,-1.1));        // bounce from paddle at higher speed
+        ball.Bounce(Vector(1,-1));        // bounce vertical at same speed
+        //ball.Bounce(Vector(1,-1.05));        // bounce from paddle at higher speed
 
-        this->pwmTicksLeft = Game::BOUNCE2_SOUND_TICKS;
+        this->snd.beepLong();
         this->nScore++;
         this->printf(100, 0, "Score: %d ", this->nScore);   
     }
@@ -264,16 +463,7 @@
         this->initializeBall();     // start a new ball
     }
 }
-
-void Game::checkPwm() {
-    if (this->pwmTicksLeft == 0) {
-        this->pwm.write(0.0);
-    }
-    else {
-        this->pwmTicksLeft--;
-        this->pwm.write(0.5); 
-    }
-}
+*/
 
 void Game::printf(int x, int y, const char *szFormat, ...)
 {
@@ -294,6 +484,7 @@
         this->drawString(Game::LOSE_1, HEIGHT / 2 - CHAR_HEIGHT); 
         this->drawString(Game::LOSE_2, HEIGHT / 2);  
         
+        this->snd.playTune();
         while (this->circle.read())
             wait_ms(1);
             
--- a/Game.h	Sun Feb 01 16:21:24 2015 +0000
+++ b/Game.h	Tue Feb 03 19:02:27 2015 +0000
@@ -5,15 +5,17 @@
 #include "Color565.h"
 #include "font_OEM.h"
 #include "LCD_ST7735.h"
+#include "SoundFX.h"
 #include "Accelerometer.h"
 #include "Shapes.h"
 #include "Ball.h"
 #include "Paddle.h"
 
 
-
+#define NUM_BALLS 3
 
-class Game {    
+class Game
+{
     static const char* LOSE_1;
     static const char* LOSE_2;
     static const char* SPLASH_1;
@@ -26,11 +28,8 @@
     static const int PADDLE_WIDTH = 38;
     static const int PADDLE_HEIGHT = 4;
     static const int PADDLE_SPEED = 4;
-    static const int BOUNCE1_SOUND_TICKS = 1;
-    static const int BOUNCE2_SOUND_TICKS = 2;
     static const char I2C_ADDR = 0x1C << 1;
 
-
     DigitalIn left;
     DigitalIn right;
     DigitalIn down;
@@ -39,20 +38,20 @@
     DigitalIn circle; 
     DigitalOut led1;
     DigitalOut led2;
-    PwmOut pwm;
     AnalogIn ain;
     I2C i2c;
     LCD_ST7735 disp;
 
+    SoundFX snd;
     Accelerometer accel;
     Timer tWait;    // timer used for tickcounts
 
     Vector vGravity;
     Ball ball;
     Paddle paddle;
+    Ball aBalls[NUM_BALLS];
 
 //    int paddleX;
-    int pwmTicksLeft;
     int nLives;
     int nScore;
     bool mode;
@@ -62,22 +61,30 @@
     void printDouble(double value, int x, int y);
     
     void initialize();
-    void initializeBall();
-    void initializePaddle();
     
     void drawString(const char* str, int y);
     
+
+    void initializePaddle();
+    void updatePaddle();
 /*
     void clearPaddle();
     void drawPaddle();
 */
-    void updatePaddle();
-
+    //void initializeBall();
+    //void initializeBalls();
+    void setNoBalls();
+    void newBall();
+    void updateBalls();
+    void redrawBalls();
+    int countBalls();
+    void checkBallsCollision();
     
     int checkTilt();
     void checkButtons();
-    void checkCollision();
-    void checkPwm();
+
+    void checkPaddle();
+    //void checkCollision();
     void printf(int x, int y, const char *szFormat, ...);
     void checkLives();
     
--- a/Paddle.cpp	Sun Feb 01 16:21:24 2015 +0000
+++ b/Paddle.cpp	Tue Feb 03 19:02:27 2015 +0000
@@ -28,6 +28,10 @@
         pos.setX(rBoundary.getX2()-dim.nWidth);
 }
 
+bool Paddle::hasChanged()
+{
+    return(pos.hasChanged());
+}
 
 void Paddle::move(Vector vDiff)
 {
@@ -59,16 +63,24 @@
 {
     Point p=pos.getCur();
     this->pDisp->drawLine(p.getX(), p.getY()+dim.nHeight, p.getX()+dim.nWidth/3, p.getY(), Color565::Blue);
-    //this->pDisp->fillRect(p.getX(), p.getY()+1, p.getX()+dim.nWidth/3, p.getY()+dim.nHeight, Color565::Blue);
-    this->pDisp->fillRect(p.getX()+dim.nWidth/3, p.getY(), p.getX()+dim.nWidth/3+dim.nWidth/3, p.getY()+dim.nHeight, Color565::fromRGB(0, 0, 0xAA));
-    //this->pDisp->fillRect(p.getX()+dim.nWidth/3+dim.nWidth/3, p.getY()+1, p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Blue);
+    this->pDisp->fillRect(p.getX()+dim.nWidth/3, p.getY(), p.getX()+dim.nWidth/3+dim.nWidth/3, p.getY()+dim.nHeight, Color565::Blue);
     this->pDisp->drawLine(p.getX()+dim.nWidth/3+dim.nWidth/3, p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Blue);
 }
 
 void Paddle::redraw()
 {   // redraw the paddle if its position has changed
+    //static int n=0;
+    char szBuffer[256];
+    
     if(pos.hasChanged())
     {
+        Point pPrev=pos.getPrev();
+        Point pCur=pos.getCur();
+/*
+n++;        
+sprintf(szBuffer, "%d %d,%d - %d,%d", n, pPrev.getX(), pPrev.getY(), pCur.getX(), pCur.getY());
+this->pDisp->drawString(font_oem, 20, 0, szBuffer);
+*/
         clearPrev();
         draw();
     }
--- a/Paddle.h	Sun Feb 01 16:21:24 2015 +0000
+++ b/Paddle.h	Tue Feb 03 19:02:27 2015 +0000
@@ -19,6 +19,7 @@
      
         void move(Vector vDiff);
         void checkBoundary(Rectangle rBoundary);
+        bool hasChanged();
 
         void clearPrev();
         void clear();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SoundFX.h	Tue Feb 03 19:02:27 2015 +0000
@@ -0,0 +1,22 @@
+#pragma once
+#include "mbed.h"
+
+class SoundFX
+{
+    public:
+        SoundFX();
+        void checkPwm();
+        void reset();
+        void beep(int nDuration=1);
+        void beepShort();
+        void beepLong();
+        void beepLow();
+        void playTune();
+
+    private:
+        static const int BOUNCE1_SOUND_TICKS = 1;
+        static const int BOUNCE2_SOUND_TICKS = 2;
+
+        PwmOut pwm;
+        int pwmTicksLeft;
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SoundFx.cpp	Tue Feb 03 19:02:27 2015 +0000
@@ -0,0 +1,68 @@
+#include "SoundFX.h"
+
+SoundFX::SoundFX() : pwm(P0_18)
+{
+    this->pwmTicksLeft=0;
+}
+
+void SoundFX::checkPwm()
+{
+    if (this->pwmTicksLeft == 0) {
+        this->pwm.write(0.0);
+    }
+    else {
+        this->pwmTicksLeft--;
+        this->pwm.write(0.5); 
+    }
+}
+
+void SoundFX::reset()
+{
+    this->pwmTicksLeft=0;
+
+    this->pwm.period_ms(1);
+    this->pwm.write(0.00);
+}
+
+void SoundFX::beep(int nDuration)       //nDuration=1
+{
+    this->pwmTicksLeft = nDuration;
+}
+
+void SoundFX::beepShort()
+{
+    this->pwm.period_ms(2);
+    this->pwmTicksLeft = SoundFX::BOUNCE1_SOUND_TICKS;
+}
+
+void SoundFX::beepLong()
+{
+    this->pwm.period_ms(1);
+    this->pwmTicksLeft = SoundFX::BOUNCE2_SOUND_TICKS;
+}
+
+void SoundFX::beepLow()
+{
+    this->pwm.period(1.0/220);
+    this->pwm.write(0.5);
+    wait_ms(150);
+    this->pwm.write(0.0);
+}
+
+void SoundFX::playTune()
+{
+    this->pwm.period(1.0/220);
+    this->pwm.write(0.5);
+    wait_ms(150);
+    this->pwm.write(0.0);
+    
+    this->pwm.period(1.0/196);
+    this->pwm.write(0.5);
+    wait_ms(150);
+    this->pwm.write(0.0);
+    
+    this->pwm.period(1.0/164.81);
+    this->pwm.write(0.5);
+    wait_ms(150);
+    this->pwm.write(0.0);
+}
\ No newline at end of file