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:
Wed Jan 28 17:32:54 2015 +0000
Child:
1:c1ee4c699517
Commit message:
Separated elements as objects, added gravity and bouncespeed.

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
Main.cpp 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
Shapes.cpp Show annotated file Show diff for this revision Revisions of this file
Shapes.h Show annotated file Show diff for this revision Revisions of this file
Vector.cpp Show annotated file Show diff for this revision Revisions of this file
Vector.h Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Accelerometer.cpp	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,39 @@
+#include "Accelerometer.h"
+
+Accelerometer::Accelerometer(int nI2cAddress) : 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)
+}
+
+void Accelerometer::readRegisters(char address, char* buffer, int len) {
+//    int nStart=this->tWait.read_ms();
+    this->i2c.write(i2cAddress, &address, 1, true);
+    this->i2c.read(i2cAddress | 1, buffer, len);
+//    printDouble((double)this->tWait.read_ms()-nStart, 10, 10);
+}
+
+int Accelerometer::writeRegister(char address, char value) {    
+    char buffer[2] = { address, value };
+    
+    return this->i2c.write(i2cAddress, buffer, 2);
+}
+
+double Accelerometer::convert(char* buffer) {
+    double val = ((buffer[0] << 2) | (buffer[1] >> 6));
+            
+    if (val > 511.0) 
+        val -= 1024.0;
+    
+    return val / 512.0;
+}
+
+void Accelerometer::getXYZ(double& x, double& y, double& z) {
+    char buffer[6];
+    
+    this->readRegisters(0x01, buffer, 6);
+    
+    x = this->convert(buffer);
+    y = this->convert(buffer + 2);
+    z = this->convert(buffer + 4);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Accelerometer.h	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,15 @@
+#pragma once
+#include "mbed.h"
+
+class Accelerometer
+{
+    public:
+        Accelerometer(int nI2cAddress);
+        void getXYZ(double& x, double& y, double& z);
+    private:
+        void readRegisters(char address, char* buffer, int len);
+        int writeRegister(char address, char value);
+        double convert(char* buffer);
+        int i2cAddress;
+        I2C i2c;
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ball.cpp	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,100 @@
+#include "Ball.h"
+
+Ball::Ball() : cBall(0,0,0), vSpeed()
+{   // constructor
+    uColorHigh=Color565::fromRGB(0xFF, 66, 66);
+    uColorMid=Color565::fromRGB(0xBB, 22, 22);
+    uColorLow=Color565::fromRGB(0x88, 0, 0);
+}
+
+void Ball::initialize(LCD_ST7735* pDisp, int nX, int nY, int nR)
+{
+    this->pDisp=pDisp;
+    this->pos.set(nX, nY);
+    this->cBall=Circle(nX, nY, nR);
+}
+
+void Ball::setSpeed(int X, int Y)
+{
+    this->vSpeed.set(X, Y);
+}
+
+void Ball::changeSpeed(bool fUp)
+{
+    if(fUp)
+    {
+        if(this->vSpeed.getSize()<=4.0) this->vSpeed.add(1.0);
+    }
+    else
+    {
+        if(this->vSpeed.getSize()>=1.0) this->vSpeed.add(-1.0);
+    }
+}
+
+void Ball::update()
+{
+    this->pos.move(this->vSpeed);
+    this->cBall.setXY(this->pos.getX(), this->pos.getY());
+}
+
+Circle Ball::getBoundingCircle()
+{
+    return(cBall);
+}
+
+bool Ball::collides(Rectangle r)
+{
+    Rectangle rBall=this->cBall.getBoundingRectangle();
+
+/*    
+char szBuffer[256];
+sprintf(szBuffer, "c:%d,%d      ", cBall.getX(), cBall.getY());
+this->pDisp->drawString(font_ibm, 0, 0, szBuffer);
+*/
+    return(rBall.collides(r));
+}
+
+void Ball::Bounce(Vector vBounce)
+{   // change the direction in a certain direction
+    this->vSpeed.multiply(vBounce);
+
+    // check speed w/max
+    if(this->vSpeed.y>5.0) this->vSpeed.y=5;
+}
+
+
+
+void Ball::clear()
+{
+    Point p=pos.getCur();
+    this->pDisp->fillCircle(p.getX(),p.getY(), cBall.getRadius(), Color565::Black, Color565::Black);
+}
+
+void Ball::clearPrev()
+{
+    Point p=pos.getPrev();
+    this->pDisp->fillCircle(p.getX(),p.getY(), cBall.getRadius(), 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)
+    {
+        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);
+    }
+    else
+        this->pDisp->fillCircle(p.getX(), p.getY(), cBall.getRadius(), this->uColorMid, this->uColorMid);
+}
+
+void Ball::redraw()
+{   // redraw the ball if its position has changed
+    if(pos.hasChanged())
+    {
+        clearPrev();
+        draw();
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Ball.h	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,47 @@
+#pragma once
+#include "mbed.h"
+
+#include "Color565.h"
+#include "font_IBM.h"
+#include "LCD_ST7735.h"
+
+#include "Shapes.h"
+#include "Vector.h"
+#include "Physics.h"
+
+class Ball
+{
+    public:
+        static const bool fFixed=false;
+
+        Ball();
+        void initialize(LCD_ST7735* pDisp, int X, int Y, int R);
+        void setSpeed(int X, int Y);
+        void changeSpeed(bool fUp);
+        void update();
+        void clear();
+        void clearPrev();
+        void draw();
+        void redraw();
+        
+        Position pos;
+        Circle cBall;
+        Vector vSpeed;
+
+/*
+        int speedX;
+        int speedY;
+*/
+        Circle getBoundingCircle();
+        bool collides(Rectangle r);
+        void Bounce(Vector vBounce);
+
+    private:
+
+        uint16_t uColorHigh;
+        uint16_t uColorMid;
+        uint16_t uColorLow;
+        LCD_ST7735* pDisp;
+        
+};
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Game.cpp	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,359 @@
+#include "Game.h"
+
+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.";
+
+
+#define WHITE Color565::White
+#define BLACK Color565::Black
+#define BLUE Color565::Blue
+#define RED Color565::Red
+#define YELLOW Color565::Yellow
+
+#define CHAR_WIDTH 8
+#define CHAR_HEIGHT 8
+#define HEIGHT this->disp.getHeight()
+#define WIDTH this->disp.getWidth()
+
+
+
+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)
+{
+    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);
+    }
+}
+
+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);
+    this->disp.clearScreen();
+
+    this->initializeBall();
+    this->initializePaddle();
+       
+    this->paddleX = WIDTH / 2 - Game::PADDLE_WIDTH / 2;
+    this->pwmTicksLeft = 0;
+    this->lives = 4;
+    
+    this->pwm.period_ms(1);
+    this->pwm.write(0.00);
+
+    this->tWait.start();      // start the timer
+    
+}
+    
+void Game::initializeBall()
+{
+    this->ball.initialize(&(this->disp),WIDTH / 2 - Game::BALL_RADIUS, HEIGHT / 4 - Game::BALL_RADIUS, Game::BALL_RADIUS);
+    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);
+}
+
+void Game::tick() {  
+    this->checkButtons();
+    
+    if (this->mode) {
+        //this->clearPaddle();
+        //this->paddle.clear();        
+/*
+        if(this->tWait.read_ms()>100)
+        {
+            this->updatePaddle();
+            this->tWait.reset();
+        }
+*/
+        this->updatePaddle();
+        this->ball.vSpeed.add(Vector(0, 0.1));    // add some gravity
+        this->ball.update();                    // update the ball position 
+    
+        this->checkCollision();
+        //this->drawPaddle();
+        //this->paddle.draw();
+        this->paddle.redraw();
+
+        this->ball.redraw();
+        
+        this->checkPwm();
+        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++;
+
+        wait_ms(100);
+    } 
+}
+
+int Game::checkTilt()
+{    // move the paddle by tilting the board left or righr
+    double x, y, z;
+    //int nStart=this->tWait.read_ms();
+    this->accel.getXYZ(x, y, z);
+
+    //printDouble((double)this->tWait.read_ms()-nStart, 10, 10);
+/*
+printDouble(x, 0, 0);
+char buf[256];
+sprintf(buf,"tilt:%0.1f", x);
+this->drawString(buf, DisplayN18::HEIGHT / 2 - DisplayN18::CHAR_HEIGHT / 2 + 4*DisplayN18::CHAR_HEIGHT ); 
+*/
+
+    if(x<-0.1) return(-1);
+    else if(x>0.1) return(1);
+    else return(0);
+}
+
+void Game::checkButtons()
+{
+    if (!this->square.read())
+    {
+        this->mode = !this->mode;
+        
+        //this->disp.clear();
+        this->disp.clearScreen();
+        
+        if (!this->mode)
+        {
+            this->graphX = 0;
+            
+            this->drawAxes();
+        }
+        
+        this->led1.write(this->mode);
+        this->led2.write(!this->mode);
+    }
+    else
+    {  
+        bool isUp = !this->up.read();
+        bool isDown = !this->down.read();
+        
+        if (isUp && isDown) goto end;
+        if (!isUp && !isDown) goto end;
+        
+        if (isUp && this->lastUp) goto end;
+        if (isDown && this->lastDown) goto end;
+        
+        if (isUp)
+        {
+            this->ball.changeSpeed(true);
+        }
+        else if (isDown)
+        {
+            this->ball.changeSpeed(false);
+        }
+    
+end:
+        this->lastUp = isUp;
+        this->lastDown = isDown;
+    }
+}
+
+void Game::drawString(const char* str, int y) {
+    this->disp.drawString(font_ibm, WIDTH / 2 - CHAR_WIDTH * strlen(str) / 2, y, str);         
+}
+
+void Game::showSplashScreen() {
+    this->drawString(Game::SPLASH_1, HEIGHT / 2 - CHAR_HEIGHT / 2);  
+    this->drawString(Game::SPLASH_2, HEIGHT / 2 + CHAR_HEIGHT / 2); 
+    this->drawString(Game::SPLASH_3, HEIGHT / 2 + CHAR_HEIGHT / 2 + 2*(8)); 
+           
+    while (this->circle.read())
+    {
+int i=this->checkTilt();
+char buf[256];
+sprintf(buf,"tilt:%d ", i);
+this->drawString(buf, HEIGHT / 2 - CHAR_HEIGHT / 2 + (4*CHAR_HEIGHT) ); 
+
+        wait_ms(1);
+    }
+        
+    this->disp.clearScreen();
+}
+
+
+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));
+        }
+    }
+}
+
+void Game::checkCollision()
+{
+    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
+
+
+    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);
+
+
+    
+    if(ball.collides(rTop) && this->ball.vSpeed.isUp())      // top wall
+    {
+        this->ball.Bounce(Vector(1,-1));        // bounce vertical
+        this->pwmTicksLeft = Game::BOUNCE1_SOUND_TICKS;
+    }
+    if(ball.collides(rRight) && this->ball.vSpeed.isRight())      // right wall
+    {
+        this->ball.Bounce(Vector(-1,1));        // bounce horizontal
+        this->pwmTicksLeft = Game::BOUNCE1_SOUND_TICKS;
+    }
+    if(ball.collides(rLeft) && this->ball.vSpeed.isLeft())      // left wall
+    {
+        this->ball.Bounce(Vector(-1,1));        // bounce horizontal
+        this->pwmTicksLeft = Game::BOUNCE1_SOUND_TICKS;
+    }
+    if(ball.collides(rPaddle) && this->ball.vSpeed.isDown())      // paddle
+    {
+        //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));
+
+        this->pwmTicksLeft = Game::BOUNCE2_SOUND_TICKS;                       
+    }
+    if(ball.collides(rBottom) && this->ball.vSpeed.isDown())      // bottom gap
+    {
+        ball.clearPrev();
+        this->initializeBall();
+        this->lives--;
+    }
+
+}
+
+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, ...)
+{
+    char szBuffer[256];
+    va_list args;
+
+    va_start(args, szFormat);
+    vsprintf(szBuffer, szFormat, args);
+    va_end(args);
+    this->disp.drawString(font_ibm, x, y, szBuffer);
+}
+
+
+void Game::checkLives() {
+    if (this->lives == 0) {
+        this->disp.clearScreen();
+        
+        this->drawString(Game::LOSE_1, HEIGHT / 2 - CHAR_HEIGHT); 
+        this->drawString(Game::LOSE_2, HEIGHT / 2);  
+        
+        while (this->circle.read())
+            wait_ms(1);
+            
+        this->initialize();
+    }
+    else {
+        this->Printf(0, 0, "%d", this->lives);   
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Game.h	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,103 @@
+#pragma once
+#include <stdarg.h>
+#include "mbed.h"
+
+#include "Color565.h"
+#include "font_IBM.h"
+#include "LCD_ST7735.h"
+#include "Accelerometer.h"
+#include "Shapes.h"
+#include "Ball.h"
+#include "Paddle.h"
+
+//#include "DisplayN18.h"
+
+
+
+
+class Game {    
+    static const char* LOSE_1;
+    static const char* LOSE_2;
+    static const char* SPLASH_1;
+    static const char* SPLASH_2;
+    static const char* SPLASH_3;
+    //char buf[256];
+    
+    //static const int BALL_RADIUS = 3;
+    static const int BALL_RADIUS = 6;
+    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 int GRAPH_HEIGHT = 40;
+    static const int GRAPH_SPACING = 2;
+    static const char I2C_ADDR = 0x1C << 1;
+
+
+    DigitalIn left;
+    DigitalIn right;
+    DigitalIn down;
+    DigitalIn up;
+    DigitalIn square;
+    DigitalIn circle; 
+    DigitalOut led1;
+    DigitalOut led2;
+    PwmOut pwm;
+    AnalogIn ain;
+    I2C i2c;
+//    DisplayN18 disp;
+    LCD_ST7735 disp;
+
+    Accelerometer accel;
+    Timer tWait;    // timer used for tickcounts
+
+    Vector vGravity;
+    Ball ball;
+    Paddle paddle;
+
+    int paddleX;
+    int pwmTicksLeft;
+    int lives;
+    int graphX;    
+    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 checkLives();
+    
+    public:
+        Game();
+        
+        void showSplashScreen();
+        void tick();
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD_ST7735.lib	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/taylorza/code/LCD_ST7735/#7ecd74dcb8ef
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Main.cpp	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,12 @@
+#include "mbed.h"
+
+#include "Game.h"
+
+int main() {
+    Game game;
+        
+    game.showSplashScreen();
+    
+    while (true)
+        game.tick();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Paddle.cpp	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,68 @@
+#include "Paddle.h"
+
+Paddle::Paddle()
+{   // constructor
+}
+
+Paddle::Paddle(LCD_ST7735* pDisp, int nX, int nY, int nWidth, int nHeight)
+{   // constructor
+    this->pos.set(nX, nY);
+    this->dim.nWidth=nWidth;
+    this->dim.nHeight=nHeight;
+}
+
+void Paddle::initialize(LCD_ST7735* pDisp, 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)
+{
+    if(pos.getX()<rBoundary.getX1())
+        pos.setX(rBoundary.getX1());
+    if(pos.getX()+dim.nWidth>rBoundary.getX2())
+        pos.setX(rBoundary.getX2()-dim.nWidth);
+}
+
+
+void Paddle::move(Vector vDiff)
+{
+    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);
+
+}
+
+
+void Paddle::clearPrev()
+{
+    Point p=pos.getPrev();
+    this->pDisp->fillRect(p.getX(), p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Black);    
+}
+
+void Paddle::clear()
+{
+    Point p=pos.getCur();
+    this->pDisp->fillRect(p.getX(), p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Black);    
+}
+
+void Paddle::draw()
+{
+    Point p=pos.getCur();
+    this->pDisp->fillRect(p.getX(), p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Blue);    
+}
+
+void Paddle::redraw()
+{   // redraw the paddle if its position has changed
+    if(pos.hasChanged())
+    {
+        clearPrev();
+        draw();
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Paddle.h	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,36 @@
+#pragma once
+#include "mbed.h"
+
+#include "Color565.h"
+#include "font_IBM.h"
+#include "LCD_ST7735.h"
+
+#include "Shapes.h"
+#include "Vector.h"
+#include "Physics.h"
+
+class Paddle
+{
+    public:
+        Paddle();
+        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 move(Vector vDiff);
+        void checkBoundary(Rectangle rBoundary);
+
+        void clearPrev();
+        void clear();
+        void draw();
+        void redraw();
+
+        Position pos;
+        Dimension dim;
+        Vector vSpeed;
+
+
+
+    private:
+        LCD_ST7735* pDisp;
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Physics.cpp	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,92 @@
+#include "Physics.h"
+
+Position::Position() : vPos(), pPrev(), pCur()
+{   // constructor
+
+}
+
+Point Position::getPrev()
+{
+    return(pPrev);
+}
+
+Point Position::getCur()
+{
+    return(pCur);
+}
+
+int Position::getX()
+{
+    return(pCur.getX());
+}
+int Position::getY()
+{
+    return(pCur.getY());
+}
+
+void Position::set(float x, float y)
+{
+    //nPrevX=nCurX;
+    //nPrevY=nCurY;
+    pPrev=pCur;
+    vPos.x=x;
+    vPos.y=y;
+    pCur.set(rint(vPos.x), rint(vPos.y));
+    //nCurX=rint(vPos.x);
+    //nCurY=rint(vPos.y);
+}
+
+void Position::set(int x, int y)
+{
+    set((float)x, (float)y);
+}
+
+void Position::setX(int x)
+{
+    set((float)x, vPos.y);
+}
+
+void Position::setY(int y)
+{
+    set(vPos.x, (float)y);
+}
+
+
+void Position::set(Vector vNew)
+{
+    move(vNew.x, vNew.y);
+}
+
+void Position::move(float fDiffX, float fDiffY)
+{
+    //nPrevX=nCurX;
+    //nPrevY=nCurY;
+    pPrev=pCur;
+    vPos.x+=fDiffX;
+    vPos.y+=fDiffY;
+    pCur.set(rint(vPos.x), rint(vPos.y));
+    //nCurX=rint(vPos.x);
+    //nCurY=rint(vPos.y);
+}
+
+void Position::move(int nDiffX, int nDiffY)
+{
+    move((float)nDiffX, (float)nDiffY);
+}
+
+void Position::move(Vector vDiff)
+{
+    move(vDiff.x, vDiff.y);
+}
+
+bool Position::hasChanged()
+{
+    //return(nPrevX!=nCurX || nPrevy!=nCury);
+    return(pPrev.getX()!=pCur.getX() || pPrev.getY()!=pCur.getY());
+}
+
+Dimension::Dimension()
+{
+    nWidth=0;
+    nHeight=0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Physics.h	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,37 @@
+#pragma once
+#include "mbed.h"
+#include "Vector.h"
+#include "Shapes.h"
+
+class Position
+{
+    public:
+        Position();
+        Point getPrev();
+        Point getCur();
+        int getX();
+        int getY();
+
+        void set(float x, float y);
+        void set(int x, int y);
+        void set(Vector vNew);
+        void setX(int x);
+        void setY(int y);
+
+        void move(float fDiffX, float fDiffY);
+        void move(int nDiffX, int nDiffY);
+        void move(Vector vDiff);
+        bool hasChanged();
+    private:
+        Vector vPos;
+        Point pPrev;
+        Point pCur;
+};
+
+class Dimension
+{
+    public:
+        Dimension();
+        int nWidth;
+        int nHeight;
+};
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shapes.cpp	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,227 @@
+#include "mbed.h"
+#include "Shapes.h"
+
+
+
+///////////////////
+// POINT
+///////////////////
+Point::Point()
+{   // constructor
+    x1=0;
+    y1=0;
+}
+
+Point::Point(int x, int y)
+{   // constructor
+    x1=x;
+    y1=y;
+}
+
+int Point::getX()
+{
+    return x1;
+}
+
+int Point::getY()
+{
+    return y1;
+}
+
+void Point::set(int x, int y)
+{
+    x1=x;
+    y1=y;
+}
+
+
+///////////////////
+// RECTANGLE
+///////////////////
+
+Rectangle::Rectangle(int x,int y, int xx, int yy)
+{
+    x1 = x;
+    x2 = xx;
+    y1 = y;
+    y2 = yy;
+}
+
+Rectangle::Rectangle(Point pt1, Point pt2)
+{
+    x1 = pt1.getX();
+    x2 = pt2.getX();
+    y1 = pt1.getY();
+    y2 = pt2.getY();
+}
+
+
+bool Rectangle::collides(Point pt)
+{
+    if(pt.getX() >= x1 && pt.getX() <= x2) {
+        if(pt.getY() >= y1 && pt.getY() <= y2) {
+            return true;
+        }
+    }
+    return false;
+}
+
+/*
+Rectangle Rectangle::intersection(Rectangle r)
+{   // return the intersection of two rectangles or null
+    Rectangle rResult;
+    rResult=Rectangle()
+    if(this->x2 >= 
+}
+*/
+
+bool Rectangle::collides(Rectangle r)
+{   // check if two rectangles collide
+    // method 1: check if corners of eithter rectangle collide
+    // method 2: compare sides
+    if(this->collides(r.get1()) || this->collides(r.get2())) return(true);
+    if(this->collides(r.get3()) || this->collides(r.get4())) return(true);
+    if(r.collides(this->get1()) || r.collides(this->get2())) return(true);
+    if(r.collides(this->get3()) || r.collides(this->get4())) return(true);
+    // TODO: check other corners
+    return(false);
+}
+
+
+Point Rectangle::get1()
+{
+    return(Point(x1, y1));
+}
+
+Point Rectangle::get2()
+{
+    return(Point(x2, y2));
+}
+
+Point Rectangle::get3()
+{
+    return(Point(x2, y1));
+}
+
+Point Rectangle::get4()
+{
+    return(Point(x1, y2));
+}
+ 
+
+ 
+int Rectangle::getX1()
+{
+    return x1;
+}
+ 
+int Rectangle::getX2()
+{
+    return x2;
+}
+ 
+int Rectangle::getY1()
+{
+    return y1;
+}
+ 
+int Rectangle::getY2()
+{
+    return y2;
+}
+ 
+int Rectangle::getCenterX()
+{
+    return x1 + (x2-x1)/2;
+}
+ 
+int Rectangle::getCenterY()
+{
+    return y1 + (y2-y1)/2;
+}
+
+Point Rectangle::getCenter()
+{
+    return(Point(x1 + (x2-x1)/2, y1 + (y2-y1)/2));
+}
+
+void Rectangle::set(Rectangle rNew)
+{
+    x1=rNew.getX1();
+    y1=rNew.getY1();
+    x2=rNew.getX2();
+    y2=rNew.getY2();
+}
+
+void Rectangle::move(Vector v)
+{
+    x1+=rint(v.x);
+    y1+=rint(v.y);
+    x2+=rint(v.x);
+    y2+=rint(v.y);
+}
+
+
+///////////////////
+// CIRCLE
+///////////////////
+Circle::Circle(int x,int y, int r)
+{
+    x1=x;
+    y1=y;
+    r1=r;
+}
+
+Point Circle::getCenter()
+{
+    return(Point(x1, y1));
+}
+
+int Circle::getRadius()
+{
+    return(r1);
+}
+
+int Circle::getX()
+{
+    return(x1);
+}
+
+int Circle::getY()
+{
+    return(y1);
+}
+
+void Circle::setX(int x)
+{
+    x1=x;
+}
+
+void Circle::setY(int y)
+{
+    y1=y;
+}
+
+void Circle::setXY(int x, int y)
+{
+    x1=x;
+    y1=y;
+}
+
+void Circle::move(int x, int y)
+{
+    x1+=x;
+    y1+=y;
+}
+
+void Circle::move(Vector v)
+{
+    x1+=rint(v.x);
+    y1+=rint(v.y);
+}
+
+
+Rectangle Circle::getBoundingRectangle()
+{
+    return(Rectangle(x1-r1, y1-r1, x1+r1, y1+r1));
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shapes.h	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,64 @@
+#pragma once
+#include "mbed.h"
+#include "Vector.h"
+
+class Point
+{ 
+protected :
+    int x1, y1;
+
+public :
+    Point();
+    Point(int x, int y);
+    int getX();
+    int getY();
+    void set(int x, int y);
+};
+
+class Rectangle
+{
+protected :
+    int x1, x2, y1, y2;
+ 
+public :
+    Rectangle(int x,int y, int x2, int y2);
+    Rectangle(Point pt1, Point pt2);
+    bool collides(Point pt);
+    bool collides(Rectangle r);
+
+    void set(Rectangle rNew);
+    
+    Point get1();
+    Point get2();
+    Point get3();
+    Point get4();
+    Point getCenter();
+
+    int getX1();
+    int getX2();
+    int getY1();
+    int getY2();
+    int getCenterX();
+    int getCenterY();
+    void move(Vector v);
+};
+
+class Circle
+{ 
+protected :
+    int x1, y1, r1;
+
+public :
+    Circle(int x,int y, int r);
+    Point getCenter();
+    int getRadius();
+    int getX();
+    int getY();
+    void setX(int x);
+    void setY(int y);
+    void setXY(int x, int y);
+    void move(int x, int y);
+    void move(Vector v);
+    Rectangle getBoundingRectangle();
+};
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Vector.cpp	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,60 @@
+#include "Vector.h"
+
+Vector::Vector()
+{   // constructor
+    this->set((float)0,(float)0);
+}
+
+Vector::Vector(float fX, float fY)
+{
+    this->set(fX, fY);
+}
+
+void Vector::set(float fX, float fY)
+{
+    x=fX;
+    y=fY;
+}
+void Vector::set(int nX, int nY)
+{
+    this->set((float)nX, (float)nY);
+}
+
+float Vector::getSize()
+{   // get the size of the vector
+    return(sqrt(x*x+y*y));
+}
+
+bool Vector::isLeft()  { return(x<0); }
+bool Vector::isRight() { return(x>0); }
+bool Vector::isUp()    { return(y<0); }
+bool Vector::isDown()  { return(y>0); }
+
+
+void Vector::add(float fAdd)
+{   // add the size of the vector by adding to its size
+    float fSize=getSize();
+    float fSizeNew=fSize+fAdd;
+    if(fSize!=0)
+    {
+        x=x * (fSizeNew/fSize);
+        y=y * (fSizeNew/fSize);
+    }
+    else
+    {   // in case of zero lenght, default to addition in first quadrant.
+        x=sqrt(0.5 * fAdd * fAdd);
+        y=x;
+    }
+}
+
+void Vector::add(Vector vAdd)
+{
+    x+=vAdd.x;
+    y+=vAdd.y;
+}
+
+void Vector::multiply(Vector vMult)
+{   // multiply the vector by means of the other vector
+    x*=vMult.x;
+    y*=vMult.y;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Vector.h	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,22 @@
+#pragma once
+#include "mbed.h"
+
+class Vector
+{
+    public:
+        float x;
+        float y;
+        
+        Vector();
+        Vector(float fX, float fY);
+        void set(float dX, float fY);
+        void set(int nX, int nY);
+        float getSize();
+        bool isLeft();
+        bool isRight();
+        bool isUp();
+        bool isDown();
+        void add(float fAdd);
+        void add(Vector vAdd);
+        void multiply(Vector vMult);
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file