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:
Sun Feb 01 16:21:24 2015 +0000
Parent:
0:87ab172a74b4
Child:
2:d4de5a5866fe
Commit message:
moved graph to accelerometer class

Changed in this revision

Accelerometer.cpp Show annotated file Show diff for this revision Revisions of this file
Accelerometer.h Show annotated file Show diff for this revision Revisions of this file
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
LCD_ST7735.lib 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
Physics.cpp Show annotated file Show diff for this revision Revisions of this file
Physics.h Show annotated file Show diff for this revision Revisions of this file
--- a/Accelerometer.cpp	Wed Jan 28 17:32:54 2015 +0000
+++ b/Accelerometer.cpp	Sun Feb 01 16:21:24 2015 +0000
@@ -1,9 +1,14 @@
 #include "Accelerometer.h"
 
-Accelerometer::Accelerometer(int nI2cAddress) : i2cAddress(nI2cAddress), i2c(P0_5, P0_4)
+Accelerometer::Accelerometer(int nI2cAddress, LCD_ST7735* pDisp) : i2cAddress(nI2cAddress), i2c(P0_5, P0_4)
 {   // constructor
     this->i2c.frequency(400000);        // fast I2C is 400 KHz, not 400 Hz. Default frequency is 100 KHz
     this->writeRegister(0x2A, 0x01); // initialize accelerometer (set CTRL_REG1 bit ACTIVE)
+    this->pDisp=pDisp;
+
+    this->colors[0] = Color565::Red;
+    this->colors[1] = Color565::Green;
+    this->colors[2] = Color565::Blue;
 }
 
 void Accelerometer::readRegisters(char address, char* buffer, int len) {
@@ -36,4 +41,62 @@
     x = this->convert(buffer);
     y = this->convert(buffer + 2);
     z = this->convert(buffer + 4);
-}
\ No newline at end of file
+}
+
+//
+// Accellerator graph for debug purposes
+//
+
+void Accelerometer::drawAxes()
+{
+    for (int i = 0; i < 3; i++) {
+        this->pDisp->fillRect(0, i * (Accelerometer::GRAPH_HEIGHT + Accelerometer::GRAPH_SPACING), this->pDisp->getWidth(), i * (Accelerometer::GRAPH_HEIGHT + Accelerometer::GRAPH_SPACING) + Accelerometer::GRAPH_HEIGHT, Color565::fromRGB(i==0?0x22:0, i==1?0x22:0, i==2?0x22:0));
+        this->pDisp->drawLine(0, i * (Accelerometer::GRAPH_HEIGHT + Accelerometer::GRAPH_SPACING), 0, i * (Accelerometer::GRAPH_HEIGHT + Accelerometer::GRAPH_SPACING) + Accelerometer::GRAPH_HEIGHT, Color565::White);
+        this->pDisp->drawLine(0, i * (Accelerometer::GRAPH_HEIGHT + Accelerometer::GRAPH_SPACING) + Accelerometer::GRAPH_HEIGHT / 2, this->pDisp->getWidth(), i * (Accelerometer::GRAPH_HEIGHT + Accelerometer::GRAPH_SPACING) + Accelerometer::GRAPH_HEIGHT / 2, Color565::White);
+    }
+}
+
+void Accelerometer::drawPoint(int axis, double value)
+{
+    if (value < -1.0)
+        value = -1.0;
+
+    if (value > 1.0)
+        value = 1.0;
+
+    value += 1.0;
+    value /= 2.0;
+    value = 1.0 - value;
+    value *= Accelerometer::GRAPH_HEIGHT;
+
+    this->pDisp->setPixel(this->graphX, axis * (Accelerometer::GRAPH_HEIGHT + Accelerometer::GRAPH_SPACING) + (int)value, this->colors[axis]);
+}
+
+void Accelerometer::resetGraph()
+{
+    this->graphX = 0;
+    this->pDisp->clearScreen();
+    //this->pDisp->fillRect(0, 0, this->pDisp->getWidth(), this->pDisp->getHeight(), Color565::fromRGB(0x11, 0x33, 0x22));
+    this->drawAxes();
+}
+
+void Accelerometer::checkGraphReset()
+{
+    if (this->graphX > this->pDisp->getWidth())
+    {
+        this->resetGraph();
+    }
+}
+
+void Accelerometer::updateGraph()
+{
+    double x, y, z;
+    this->getXYZ(x, y, z);
+    
+    this->checkGraphReset();
+    this->drawPoint(0, x);
+    this->drawPoint(1, y);
+    this->drawPoint(2, z);
+    this->graphX++;
+}
+
--- a/Accelerometer.h	Wed Jan 28 17:32:54 2015 +0000
+++ b/Accelerometer.h	Sun Feb 01 16:21:24 2015 +0000
@@ -1,15 +1,32 @@
 #pragma once
 #include "mbed.h"
 
+#include "Color565.h"
+#include "LCD_ST7735.h"
+
 class Accelerometer
 {
     public:
-        Accelerometer(int nI2cAddress);
+        Accelerometer(int nI2cAddress, LCD_ST7735* pDisp);
         void getXYZ(double& x, double& y, double& z);
+        void resetGraph();
+        void updateGraph();
+
     private:
+        static const int GRAPH_HEIGHT = 40;
+        static const int GRAPH_SPACING = 2;
+
         void readRegisters(char address, char* buffer, int len);
         int writeRegister(char address, char value);
         double convert(char* buffer);
+
         int i2cAddress;
         I2C i2c;
+        LCD_ST7735* pDisp;
+        unsigned short colors[3];
+        int graphX;    
+
+        void drawAxes();
+        void drawPoint(int axis, double value);
+        void checkGraphReset();
 };
\ No newline at end of file
--- a/Ball.cpp	Wed Jan 28 17:32:54 2015 +0000
+++ b/Ball.cpp	Sun Feb 01 16:21:24 2015 +0000
@@ -1,17 +1,36 @@
 #include "Ball.h"
 
-Ball::Ball() : cBall(0,0,0), vSpeed()
+Ball::Ball(LCD_ST7735* pDisp) : vSpeed()
 {   // constructor
-    uColorHigh=Color565::fromRGB(0xFF, 66, 66);
-    uColorMid=Color565::fromRGB(0xBB, 22, 22);
-    uColorLow=Color565::fromRGB(0x88, 0, 0);
+    this->pDisp=pDisp;
 }
 
-void Ball::initialize(LCD_ST7735* pDisp, int nX, int nY, int nR)
+uint16_t Ball::dimmedColor(uint16_t uColor)
 {
-    this->pDisp=pDisp;
+    uint16_t r, g, b;
+   
+    r=(uColor >> 11) <<3;
+    g=((uColor >> 5) & 0x3F) <<2;
+    b=(uColor & 0x1F) << 3;
+    r=r*2/3;
+    g=g*2/3;
+    b=b*2/3;
+//    r=r/2;
+//    g=g/2;
+//    b=b/2;
+
+    return(Color565::fromRGB((uint16_t)r,(uint16_t)g,(uint16_t)b));
+}
+
+void Ball::initialize(int nX, int nY, int nR, uint16_t uColor)
+{
     this->pos.set(nX, nY);
-    this->cBall=Circle(nX, nY, nR);
+    this->nRadius=nR;
+    this->uColor=uColor;
+    this->uColorHigh=uColor;
+    this->uColorMid=dimmedColor(uColorHigh);
+    this->uColorLow=dimmedColor(uColorMid);
+
 }
 
 void Ball::setSpeed(int X, int Y)
@@ -31,31 +50,38 @@
     }
 }
 
+void Ball::unmove()
+{   // move back to previous position
+    pos.set(pos.getPrev());
+}
+
 void Ball::update()
 {
     this->pos.move(this->vSpeed);
-    this->cBall.setXY(this->pos.getX(), this->pos.getY());
 }
 
 Circle Ball::getBoundingCircle()
 {
-    return(cBall);
+    return(Circle(this->pos.getX(), this->pos.getY(), this->nRadius));
 }
 
 bool Ball::collides(Rectangle r)
 {
-    Rectangle rBall=this->cBall.getBoundingRectangle();
+    Circle cBall=this->getBoundingCircle();
+    Rectangle rBall=cBall.getBoundingRectangle();
 
 /*    
 char szBuffer[256];
 sprintf(szBuffer, "c:%d,%d      ", cBall.getX(), cBall.getY());
-this->pDisp->drawString(font_ibm, 0, 0, szBuffer);
+this->pDisp->drawString(font_oem, 0, 0, szBuffer);
 */
     return(rBall.collides(r));
 }
 
 void Ball::Bounce(Vector vBounce)
 {   // change the direction in a certain direction
+    this->unmove(); // undo move to pre-bouncing position to avoid drawing on colliding position
+
     this->vSpeed.multiply(vBounce);
 
     // check speed w/max
@@ -67,27 +93,27 @@
 void Ball::clear()
 {
     Point p=pos.getCur();
-    this->pDisp->fillCircle(p.getX(),p.getY(), cBall.getRadius(), Color565::Black, Color565::Black);
+    this->pDisp->fillCircle(p.getX(),p.getY(), this->nRadius, Color565::Black, Color565::Black);
 }
 
 void Ball::clearPrev()
 {
     Point p=pos.getPrev();
-    this->pDisp->fillCircle(p.getX(),p.getY(), cBall.getRadius(), Color565::Black, Color565::Black);
+    this->pDisp->fillCircle(p.getX(),p.getY(), this->nRadius, Color565::Black, Color565::Black);
 }
 
 
 void Ball::draw()
 {   // render the object on the screen, based on its current position
     Point p=pos.getCur();
-    if(cBall.getRadius()>3)
+    if(this->nRadius>3)
     {
-        this->pDisp->fillCircle(p.getX(), p.getY(), cBall.getRadius(), this->uColorLow, this->uColorLow);
-        this->pDisp->fillCircle(p.getX()-cBall.getRadius()/3, p.getY()-cBall.getRadius()/3, cBall.getRadius()/2, this->uColorMid, this->uColorMid);
-        this->pDisp->setPixel(p.getX()-cBall.getRadius()/2, p.getY()-cBall.getRadius()/2, this->uColorHigh);
+        this->pDisp->fillCircle(p.getX(), p.getY(), this->nRadius, this->uColorLow, this->uColorLow);
+        this->pDisp->fillCircle(p.getX()-this->nRadius/3, p.getY()-this->nRadius/3, this->nRadius/2, this->uColorMid, this->uColorMid);
+        this->pDisp->setPixel(p.getX()-this->nRadius/2, p.getY()-this->nRadius/2, this->uColorHigh);
     }
     else
-        this->pDisp->fillCircle(p.getX(), p.getY(), cBall.getRadius(), this->uColorMid, this->uColorMid);
+        this->pDisp->fillCircle(p.getX(), p.getY(), this->nRadius, this->uColorMid, this->uColorMid);
 }
 
 void Ball::redraw()
--- a/Ball.h	Wed Jan 28 17:32:54 2015 +0000
+++ b/Ball.h	Sun Feb 01 16:21:24 2015 +0000
@@ -2,7 +2,7 @@
 #include "mbed.h"
 
 #include "Color565.h"
-#include "font_IBM.h"
+#include "font_OEM.h"
 #include "LCD_ST7735.h"
 
 #include "Shapes.h"
@@ -14,10 +14,11 @@
     public:
         static const bool fFixed=false;
 
-        Ball();
-        void initialize(LCD_ST7735* pDisp, int X, int Y, int R);
+        Ball(LCD_ST7735* pDisp);
+        void initialize(int X, int Y, int R, uint16_t uColor);
         void setSpeed(int X, int Y);
         void changeSpeed(bool fUp);
+        void unmove();
         void update();
         void clear();
         void clearPrev();
@@ -25,23 +26,20 @@
         void redraw();
         
         Position pos;
-        Circle cBall;
+        int nRadius;
         Vector vSpeed;
 
-/*
-        int speedX;
-        int speedY;
-*/
         Circle getBoundingCircle();
         bool collides(Rectangle r);
         void Bounce(Vector vBounce);
 
     private:
-
+        uint16_t uColor;
         uint16_t uColorHigh;
         uint16_t uColorMid;
         uint16_t uColorLow;
         LCD_ST7735* pDisp;
-        
+
+        uint16_t dimmedColor(uint16_t uColor);
 };
 
--- a/Game.cpp	Wed Jan 28 17:32:54 2015 +0000
+++ b/Game.cpp	Sun Feb 01 16:21:24 2015 +0000
@@ -21,77 +21,40 @@
 
 
 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), vGravity(0, 0.1)
+    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)
 {
+    this->disp.setOrientation(LCD_ST7735::Rotate270, false);
+    this->disp.setForegroundColor(WHITE);
+    this->disp.setBackgroundColor(BLACK);
+    this->disp.clearScreen();
+
     srand(this->ain.read_u16());
     
     this->lastUp = false;
     this->lastDown = false;
     this->mode = true;
 
-    this->colors[0] = Color565::Red;
-    this->colors[1] = Color565::Green;
-    this->colors[2] = Color565::Blue;
-    
     this->initialize();
 }
 
-/*
-void Game::getXYZ(double& x, double& y, double& z) {
-    this->accel.getXYZ(x, y, z);
-}
-*/
-
 void Game::printDouble(double value, int x, int y) {
     char buffer[10];
     int len = sprintf(buffer, "%.1f ", value);
     
-    this->disp.drawString(font_ibm, x, y, buffer);
-}
-
-void Game::drawAxes() {
-    for (int i = 0; i < 3; i++) {
-        this->disp.drawLine(0, i * (Game::GRAPH_HEIGHT + Game::GRAPH_SPACING), 0, i * (Game::GRAPH_HEIGHT + Game::GRAPH_SPACING) + Game::GRAPH_HEIGHT, WHITE);
-        this->disp.drawLine(0, i * (Game::GRAPH_HEIGHT + Game::GRAPH_SPACING) + Game::GRAPH_HEIGHT / 2, WIDTH, i * (Game::GRAPH_HEIGHT + Game::GRAPH_SPACING) + Game::GRAPH_HEIGHT / 2, WHITE);
-    }
+    this->disp.drawString(font_oem, x, y, buffer);
 }
 
-void Game::drawPoint(int axis, double value) {
-    if (value < -1.0)
-        value = -1.0;
-
-    if (value > 1.0)
-        value = 1.0;
-
-    value += 1.0;
-    value /= 2.0;
-    value = 1.0 - value;
-    value *= Game::GRAPH_HEIGHT;
-
-    this->disp.setPixel(this->graphX, axis * (Game::GRAPH_HEIGHT + Game::GRAPH_SPACING) + (int)value, this->colors[axis]);
-}
-
-void Game::checkGraphReset() {
-    if (this->graphX > WIDTH) {
-        this->graphX = 0;
-        this->disp.clearScreen();
-        this->drawAxes();
-    }
-}
-
-void Game::initialize() {    
-    //this->disp.clear();
-    this->disp.setOrientation(LCD_ST7735::Rotate270, false);
-    this->disp.setForegroundColor(WHITE);
-    this->disp.setBackgroundColor(BLACK);
+void Game::initialize()
+{
     this->disp.clearScreen();
 
-    this->initializeBall();
+    this->initializeBall();     // start first ball
     this->initializePaddle();
        
-    this->paddleX = WIDTH / 2 - Game::PADDLE_WIDTH / 2;
+//    this->paddleX = WIDTH / 2 - Game::PADDLE_WIDTH / 2;
     this->pwmTicksLeft = 0;
-    this->lives = 4;
+    this->nLives = 4;
+    this->nScore = 0;
     
     this->pwm.period_ms(1);
     this->pwm.write(0.00);
@@ -102,21 +65,19 @@
     
 void Game::initializeBall()
 {
-    this->ball.initialize(&(this->disp),WIDTH / 2 - Game::BALL_RADIUS, HEIGHT / 4 - Game::BALL_RADIUS, Game::BALL_RADIUS);
+    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()
 {
-    this->paddle.initialize(&(this->disp), WIDTH / 2 - Game::PADDLE_WIDTH/2, HEIGHT - Game::PADDLE_HEIGHT, Game::PADDLE_WIDTH, Game::PADDLE_HEIGHT);
+    this->paddle.initialize(WIDTH / 2 - Game::PADDLE_WIDTH/2, HEIGHT - Game::PADDLE_HEIGHT, Game::PADDLE_WIDTH, Game::PADDLE_HEIGHT);
 }
 
 void Game::tick() {  
     this->checkButtons();
     
     if (this->mode) {
-        //this->clearPaddle();
-        //this->paddle.clear();        
 /*
         if(this->tWait.read_ms()>100)
         {
@@ -129,27 +90,17 @@
         this->ball.update();                    // update the ball position 
     
         this->checkCollision();
-        //this->drawPaddle();
-        //this->paddle.draw();
         this->paddle.redraw();
-
         this->ball.redraw();
         
         this->checkPwm();
+        //this->checkScore(); 
         this->checkLives(); 
         
         wait_ms(25);
     }
-    else {    
-        double x, y, z;
-        this->accel.getXYZ(x, y, z);
-        
-        this->checkGraphReset();
-        this->drawPoint(0, x);
-        this->drawPoint(1, y);
-        this->drawPoint(2, z);
-        this->graphX++;
-
+    else {
+        this->accel.updateGraph();
         wait_ms(100);
     } 
 }
@@ -184,9 +135,7 @@
         
         if (!this->mode)
         {
-            this->graphX = 0;
-            
-            this->drawAxes();
+            this->accel.resetGraph();
         }
         
         this->led1.write(this->mode);
@@ -218,8 +167,14 @@
     }
 }
 
-void Game::drawString(const char* str, int y) {
-    this->disp.drawString(font_ibm, WIDTH / 2 - CHAR_WIDTH * strlen(str) / 2, y, str);         
+void Game::drawString(const char* str, int y)
+{
+    uint8_t width;
+    uint8_t height;
+    
+    this->disp.measureString(font_oem, str, width, height);
+    this->disp.drawString(font_oem, WIDTH / 2 - width / 2, y, str);
+    
 }
 
 void Game::showSplashScreen() {
@@ -231,7 +186,7 @@
     {
 int i=this->checkTilt();
 char buf[256];
-sprintf(buf,"tilt:%d ", i);
+sprintf(buf,"  tilt:%d  ", i);
 this->drawString(buf, HEIGHT / 2 - CHAR_HEIGHT / 2 + (4*CHAR_HEIGHT) ); 
 
         wait_ms(1);
@@ -243,28 +198,16 @@
 
 void Game::updatePaddle() {
     if (!this->left.read())  // note: read is LOW (0) when button pressed
-    {
-        this->paddleX -= Game::PADDLE_SPEED;
         this->paddle.move(Vector(-1 * Game::PADDLE_SPEED, 0));
-    }
     else if (!this->right.read())
-    {
-        this->paddleX += Game::PADDLE_SPEED;
         this->paddle.move(Vector(Game::PADDLE_SPEED, 0));
-    }
     else
     {
         int i=this->checkTilt();        // don't call too often as this I2C is slow and will delay the game
         if(i>0)
-        {
-            this->paddleX += Game::PADDLE_SPEED;
             this->paddle.move(Vector(Game::PADDLE_SPEED, 0));
-        }
         else if(i<0)
-        {
-            this->paddleX -= Game::PADDLE_SPEED;
             this->paddle.move(Vector(-1 * Game::PADDLE_SPEED, 0));
-        }
     }
 }
 
@@ -277,15 +220,16 @@
     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
 
-
+/*
     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
@@ -303,20 +247,22 @@
     }
     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
-        this->ball.Bounce(Vector(1,-1.1));        // bounce from paddle at higher speed
-        if(ball.collides(rPaddleLeft)) ball.vSpeed.add(Vector(-1,0));
-        if(ball.collides(rPaddleRight)) ball.vSpeed.add(Vector(1,0));
+        ball.Bounce(Vector(1,-1.1));        // bounce from paddle at higher speed
 
-        this->pwmTicksLeft = Game::BOUNCE2_SOUND_TICKS;                       
+        this->pwmTicksLeft = Game::BOUNCE2_SOUND_TICKS;
+        this->nScore++;
+        this->printf(100, 0, "Score: %d ", this->nScore);   
     }
     if(ball.collides(rBottom) && this->ball.vSpeed.isDown())      // bottom gap
     {
-        ball.clearPrev();
-        this->initializeBall();
-        this->lives--;
+        ball.clearPrev();   // clear the ball from its previous position
+        this->nLives--;
+        this->initializeBall();     // start a new ball
     }
-
 }
 
 void Game::checkPwm() {
@@ -329,7 +275,7 @@
     }
 }
 
-void Game::Printf(int x, int y, const char *szFormat, ...)
+void Game::printf(int x, int y, const char *szFormat, ...)
 {
     char szBuffer[256];
     va_list args;
@@ -337,12 +283,12 @@
     va_start(args, szFormat);
     vsprintf(szBuffer, szFormat, args);
     va_end(args);
-    this->disp.drawString(font_ibm, x, y, szBuffer);
+    this->disp.drawString(font_oem, x, y, szBuffer);
 }
 
 
 void Game::checkLives() {
-    if (this->lives == 0) {
+    if (this->nLives == 0) {
         this->disp.clearScreen();
         
         this->drawString(Game::LOSE_1, HEIGHT / 2 - CHAR_HEIGHT); 
@@ -354,6 +300,6 @@
         this->initialize();
     }
     else {
-        this->Printf(0, 0, "%d", this->lives);   
+        this->printf(0, 0, "%d", this->nLives);   
     }
 }
\ No newline at end of file
--- a/Game.h	Wed Jan 28 17:32:54 2015 +0000
+++ b/Game.h	Sun Feb 01 16:21:24 2015 +0000
@@ -3,15 +3,13 @@
 #include "mbed.h"
 
 #include "Color565.h"
-#include "font_IBM.h"
+#include "font_OEM.h"
 #include "LCD_ST7735.h"
 #include "Accelerometer.h"
 #include "Shapes.h"
 #include "Ball.h"
 #include "Paddle.h"
 
-//#include "DisplayN18.h"
-
 
 
 
@@ -30,8 +28,6 @@
     static const int PADDLE_SPEED = 4;
     static const int BOUNCE1_SOUND_TICKS = 1;
     static const int BOUNCE2_SOUND_TICKS = 2;
-    static const int GRAPH_HEIGHT = 40;
-    static const int GRAPH_SPACING = 2;
     static const char I2C_ADDR = 0x1C << 1;
 
 
@@ -46,7 +42,6 @@
     PwmOut pwm;
     AnalogIn ain;
     I2C i2c;
-//    DisplayN18 disp;
     LCD_ST7735 disp;
 
     Accelerometer accel;
@@ -56,43 +51,34 @@
     Ball ball;
     Paddle paddle;
 
-    int paddleX;
+//    int paddleX;
     int pwmTicksLeft;
-    int lives;
-    int graphX;    
+    int nLives;
+    int nScore;
     bool mode;
     bool lastUp;
     bool lastDown;
-    unsigned short colors[3];
 
-    
-/*
-    void readRegisters(char address, char* buffer, int len);
-    int writeRegister(char address, char value);
-    double convert(char* buffer);
-    void getXYZ(double& x, double& y, double& z);
-*/
     void printDouble(double value, int x, int y);
     
-    void drawAxes();
-    void drawPoint(int axis, double value);
-    void checkGraphReset();
-    
     void initialize();
     void initializeBall();
     void initializePaddle();
     
     void drawString(const char* str, int y);
     
+/*
     void clearPaddle();
     void drawPaddle();
+*/
     void updatePaddle();
+
     
     int checkTilt();
     void checkButtons();
     void checkCollision();
     void checkPwm();
-    void Printf(int x, int y, const char *szFormat, ...);
+    void printf(int x, int y, const char *szFormat, ...);
     void checkLives();
     
     public:
--- a/LCD_ST7735.lib	Wed Jan 28 17:32:54 2015 +0000
+++ b/LCD_ST7735.lib	Sun Feb 01 16:21:24 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/taylorza/code/LCD_ST7735/#7ecd74dcb8ef
+http://mbed.org/users/taylorza/code/LCD_ST7735/#c94d0a2c2ba0
--- a/Paddle.cpp	Wed Jan 28 17:32:54 2015 +0000
+++ b/Paddle.cpp	Sun Feb 01 16:21:24 2015 +0000
@@ -1,7 +1,8 @@
 #include "Paddle.h"
 
-Paddle::Paddle()
+Paddle::Paddle(LCD_ST7735* pDisp)
 {   // constructor
+    this->pDisp=pDisp;
 }
 
 Paddle::Paddle(LCD_ST7735* pDisp, int nX, int nY, int nWidth, int nHeight)
@@ -9,14 +10,14 @@
     this->pos.set(nX, nY);
     this->dim.nWidth=nWidth;
     this->dim.nHeight=nHeight;
+    this->pDisp=pDisp;
 }
 
-void Paddle::initialize(LCD_ST7735* pDisp, int nX, int nY, int nWidth, int nHeight)
+void Paddle::initialize(int nX, int nY, int nWidth, int nHeight)
 {
     this->pos.set(nX, nY);
     this->dim.nWidth=nWidth;
     this->dim.nHeight=nHeight;
-    this->pDisp=pDisp;
 }
 
 void Paddle::checkBoundary(Rectangle rBoundary)
@@ -33,9 +34,11 @@
     this->pos.move(vDiff);
 //    this->rPaddle.move(vDiff);
 
+/*
 char szBuffer[256];
 sprintf(szBuffer, "p:%d,%d      ", pos.getX(), pos.getY());
-this->pDisp->drawString(font_ibm, 0, 0, szBuffer);
+this->pDisp->drawString(font_oem, 0, 0, szBuffer);
+*/
 
 }
 
@@ -55,7 +58,11 @@
 void Paddle::draw()
 {
     Point p=pos.getCur();
-    this->pDisp->fillRect(p.getX(), p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Blue);    
+    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->drawLine(p.getX()+dim.nWidth/3+dim.nWidth/3, p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Blue);
 }
 
 void Paddle::redraw()
--- a/Paddle.h	Wed Jan 28 17:32:54 2015 +0000
+++ b/Paddle.h	Sun Feb 01 16:21:24 2015 +0000
@@ -2,7 +2,7 @@
 #include "mbed.h"
 
 #include "Color565.h"
-#include "font_IBM.h"
+#include "font_OEM.h"
 #include "LCD_ST7735.h"
 
 #include "Shapes.h"
@@ -12,9 +12,9 @@
 class Paddle
 {
     public:
-        Paddle();
+        Paddle(LCD_ST7735* pDisp);
         Paddle(LCD_ST7735* pDisp, int nX, int nY, int nWidth, int nHeight);
-        void initialize(LCD_ST7735* pDisp, int nX, int nY, int nWidth, int nHeight);
+        void initialize(int nX, int nY, int nWidth, int nHeight);
 
      
         void move(Vector vDiff);
--- a/Physics.cpp	Wed Jan 28 17:32:54 2015 +0000
+++ b/Physics.cpp	Sun Feb 01 16:21:24 2015 +0000
@@ -41,6 +41,11 @@
     set((float)x, (float)y);
 }
 
+void Position::set(Point ptNew)
+{
+    set(ptNew.getX(), ptNew.getY());
+}
+
 void Position::setX(int x)
 {
     set((float)x, vPos.y);
@@ -51,12 +56,6 @@
     set(vPos.x, (float)y);
 }
 
-
-void Position::set(Vector vNew)
-{
-    move(vNew.x, vNew.y);
-}
-
 void Position::move(float fDiffX, float fDiffY)
 {
     //nPrevX=nCurX;
--- a/Physics.h	Wed Jan 28 17:32:54 2015 +0000
+++ b/Physics.h	Sun Feb 01 16:21:24 2015 +0000
@@ -14,7 +14,7 @@
 
         void set(float x, float y);
         void set(int x, int y);
-        void set(Vector vNew);
+        void set(Point ptNew);
         void setX(int x);
         void setY(int y);