Balls & Paddle game for RETRO Pong inspired game featuring multi-directional tilt-sensitive paddle, multiple balls, shrinking ceiling and a bit of gravity.

Dependencies:   LCD_ST7735 MusicEngine RETRO_BallsAndThings mbed

Balls and Paddle

After doing some work on the Pong mod I decided to put my efforts into making my version object oriented and try to make a generic object-library that could be use for other ball-and-things games. To add some challenges to the gameplay, the following features were added:

  • extra-free additional balls to please the juglers
  • gravity for pulling the ball down to create some dynamic movement
  • directional power-paddle that counters the ball with a bit more speed
  • lowering ceiling to make endless gameplay impossible

Files at this revision

API Documentation at this revision

Comitter:
maxint
Date:
Mon Mar 02 09:24:22 2015 +0000
Parent:
5:8441b390a15f
Commit message:
cleanup

Changed in this revision

Game.cpp 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
RETRO_BallsAndThings.lib Show annotated file Show diff for this revision Revisions of this file
--- a/Game.cpp	Sun Mar 01 13:58:47 2015 +0000
+++ b/Game.cpp	Mon Mar 02 09:24:22 2015 +0000
@@ -22,11 +22,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), 
-    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), 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), paddle(&disp)
 {
     this->disp.setOrientation(LCD_ST7735::Rotate270, false);
     this->disp.setForegroundColor(WHITE);
@@ -169,9 +165,6 @@
         else
         {
             this->aBalls[i].initialize(WIDTH / 2 - Game::BALL_RADIUS, this->nTopWall + (HEIGHT-this->nTopWall) / 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;
-            //this->aBalls[i].setSpeed(ftRandX, ftRandY);
             float ftRandX=((rand() % 20) - 10)/5.0;     // left/right at random speed
             float ftRandY=((rand() % 10) - 10)/5.0;     // up at random speed
             this->aBalls[i].vSpeed.set(ftRandX, ftRandY);
@@ -291,28 +284,7 @@
                 if(pBall->collides(lPaddleLeft))   pBall->vSpeed.add(Vector(-1.3,0));      // left side of paddle has bias to the left
                 if(pBall->collides(lPaddleRight))  pBall->vSpeed.add(Vector(1.3,0));       // right side of paddle has bias to the right
                 pBall->Bounce(Vector(1,-1));
-    /*
-                if(pBall->collides(rPaddleMiddle))
-                {
-                    pBall->Bounce(Vector(1,-1));
-    //                printf(10, 10, "Mid: %0.2f, %0.2f  ", pBall->vSpeed.x, pBall->vSpeed.y);
-                }
-                else if(pBall->collides(rPaddleLeft))
-                {
-                    Vector vDirection(-1,-2);
-                    pBall->Bounce(vDirection.getNormalized());
-                    //pBall->BounceAgainst(Vector(12,-4));      // left side of paddle has bias to the left
-    //                printf(10, 10, "Left: %0.2f, %0.2f  ", pBall->vSpeed.x, pBall->vSpeed.y);
-                }
-                else if(pBall->collides(rPaddleRight))
-                {
-                    Vector vDirection(1,-2);
-                    pBall->Bounce(vDirection.getNormalized());
-                    //pBall->BounceAgainst(Vector(12,4));       // right side of paddle has bias to the right
-    //                printf(10, 10, "Right: %0.2f, %0.2f  ", pBall->vSpeed.x, pBall->vSpeed.y);
-                }
-    */
-                
+              
                 {
                     // increase the speed of the ball when hitting the paddle to increase difficulty
                     float ftSpeedMax=3.0;
@@ -326,7 +298,6 @@
                         pBall->vSpeed.multiply(Vector(1,1.02));        // bounce up from paddle at higher speed
                 }
                 //printf(10, 10, "Bounce: %0.2f, %0.2f  ", pBall->vSpeed.x, pBall->vSpeed.y);
-    
         
                 // force drawing the paddle after redrawing the bounced ball
                 this->fDrawPaddle=true;
--- a/LCD_ST7735.lib	Sun Mar 01 13:58:47 2015 +0000
+++ b/LCD_ST7735.lib	Mon Mar 02 09:24:22 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/taylorza/code/LCD_ST7735/#c94d0a2c2ba0
+http://mbed.org/users/taylorza/code/LCD_ST7735/#516f15979b53
--- a/RETRO_BallsAndThings.lib	Sun Mar 01 13:58:47 2015 +0000
+++ b/RETRO_BallsAndThings.lib	Mon Mar 02 09:24:22 2015 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/maxint/code/RETRO_BallsAndThings/#860b82c19ecf
+http://developer.mbed.org/users/maxint/code/RETRO_BallsAndThings/#4fa3edaa1201