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
Diff: Game.cpp
- Revision:
- 3:a68d4d515c20
- Parent:
- 2:0caa0607f7bf
- Child:
- 4:8643d2d93a5f
--- a/Game.cpp Mon Feb 09 08:40:03 2015 +0000 +++ b/Game.cpp Wed Feb 25 10:43:41 2015 +0000 @@ -83,7 +83,7 @@ } void Game::printf(int x, int y, const char *szFormat, ...) -{ +{ // formats: %s, %d, %0.2f char szBuffer[256]; va_list args; @@ -248,8 +248,11 @@ Rectangle rRight=Rectangle(WIDTH, 0, WIDTH+10, HEIGHT); // right wall Rectangle rPaddle=Rectangle(paddle.pos.getX(), paddle.pos.getY(), paddle.pos.getX() + Game::PADDLE_WIDTH, HEIGHT+10); // paddle Rectangle rPaddleLeft=Rectangle(paddle.pos.getX(), paddle.pos.getY(), paddle.pos.getX() + Game::PADDLE_WIDTH/3, HEIGHT+10); // paddle left part + Rectangle rPaddleMiddle=Rectangle(paddle.pos.getX() + Game::PADDLE_WIDTH/3, paddle.pos.getY(), paddle.pos.getX() + Game::PADDLE_WIDTH/3 + Game::PADDLE_WIDTH/3, HEIGHT+10); // paddle middle 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 + //printf(0, 20, "Paddle: %d-%d %d-%d ", rPaddleLeft.getX1(), rPaddleLeft.getX2(), rPaddleRight.getX1(), rPaddleRight.getX2()); + Ball* pBall; for(int i=0; i<NUM_BALLS; i++) { @@ -278,20 +281,43 @@ { if(pBall->collides(rPaddleLeft)) pBall->vSpeed.add(Vector(-1.3,0)); // left side of paddle has bias to the left if(pBall->collides(rPaddleRight)) pBall->vSpeed.add(Vector(1.3,0)); // right side of paddle has bias to the right - - // bounce the ball - // increase the speed of the ball when hitting the paddle to increase difficulty - 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) - pBall->Bounce(Vector(1,-1.02)); // bounce from paddle at higher speed - else - pBall->Bounce(Vector(1,-1)); // bounce vertical at same speed + 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; + 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) + 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;