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
Committer:
maxint
Date:
Fri Feb 06 10:18:41 2015 +0000
Revision:
0:7e989d0083ff
Child:
1:bf46edcd6b4f
First game ready for competition

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maxint 0:7e989d0083ff 1 #pragma once
maxint 0:7e989d0083ff 2 #include <stdarg.h>
maxint 0:7e989d0083ff 3 #include <algorithm> // required for min() and max(), see http://www.cplusplus.com/reference/algorithm/
maxint 0:7e989d0083ff 4 #include "mbed.h"
maxint 0:7e989d0083ff 5
maxint 0:7e989d0083ff 6 #include "Color565.h"
maxint 0:7e989d0083ff 7 #include "font_OEM.h"
maxint 0:7e989d0083ff 8 #include "LCD_ST7735.h"
maxint 0:7e989d0083ff 9 #include "SoundFX.h"
maxint 0:7e989d0083ff 10 #include "Accelerometer.h"
maxint 0:7e989d0083ff 11 #include "Shapes.h"
maxint 0:7e989d0083ff 12 #include "Ball.h"
maxint 0:7e989d0083ff 13 #include "Paddle.h"
maxint 0:7e989d0083ff 14
maxint 0:7e989d0083ff 15
maxint 0:7e989d0083ff 16 #define NUM_BALLS 3
maxint 0:7e989d0083ff 17
maxint 0:7e989d0083ff 18 class Game
maxint 0:7e989d0083ff 19 {
maxint 0:7e989d0083ff 20 static const char* LOSE_1;
maxint 0:7e989d0083ff 21 static const char* LOSE_2;
maxint 0:7e989d0083ff 22 static const char* SPLASH_1;
maxint 0:7e989d0083ff 23 static const char* SPLASH_2;
maxint 0:7e989d0083ff 24 static const char* SPLASH_3;
maxint 0:7e989d0083ff 25 //char buf[256];
maxint 0:7e989d0083ff 26
maxint 0:7e989d0083ff 27 //static const int BALL_RADIUS = 3;
maxint 0:7e989d0083ff 28 static const int BALL_RADIUS = 6;
maxint 0:7e989d0083ff 29 static const int PADDLE_WIDTH = 38;
maxint 0:7e989d0083ff 30 static const int PADDLE_HEIGHT = 4;
maxint 0:7e989d0083ff 31 static const int PADDLE_SPEED = 4;
maxint 0:7e989d0083ff 32 static const char I2C_ADDR = 0x1C << 1;
maxint 0:7e989d0083ff 33
maxint 0:7e989d0083ff 34 DigitalIn left;
maxint 0:7e989d0083ff 35 DigitalIn right;
maxint 0:7e989d0083ff 36 DigitalIn down;
maxint 0:7e989d0083ff 37 DigitalIn up;
maxint 0:7e989d0083ff 38 DigitalIn square;
maxint 0:7e989d0083ff 39 DigitalIn circle;
maxint 0:7e989d0083ff 40 DigitalOut led1;
maxint 0:7e989d0083ff 41 DigitalOut led2;
maxint 0:7e989d0083ff 42 AnalogIn ain;
maxint 0:7e989d0083ff 43 I2C i2c;
maxint 0:7e989d0083ff 44 LCD_ST7735 disp;
maxint 0:7e989d0083ff 45
maxint 0:7e989d0083ff 46 SoundFX snd;
maxint 0:7e989d0083ff 47 Accelerometer accel;
maxint 0:7e989d0083ff 48 // Timer tWait; // timer used for tickcounts
maxint 0:7e989d0083ff 49
maxint 0:7e989d0083ff 50 Vector vGravity;
maxint 0:7e989d0083ff 51 Ball ball;
maxint 0:7e989d0083ff 52 Paddle paddle;
maxint 0:7e989d0083ff 53 Ball aBalls[NUM_BALLS];
maxint 0:7e989d0083ff 54
maxint 0:7e989d0083ff 55 bool mode;
maxint 0:7e989d0083ff 56 int nBalls;
maxint 0:7e989d0083ff 57 int nScore;
maxint 0:7e989d0083ff 58 bool fDrawPaddle;
maxint 0:7e989d0083ff 59 bool fDrawTopWall;
maxint 0:7e989d0083ff 60
maxint 0:7e989d0083ff 61 int nTopWall;
maxint 0:7e989d0083ff 62
maxint 0:7e989d0083ff 63 bool lastUp;
maxint 0:7e989d0083ff 64 bool lastDown;
maxint 0:7e989d0083ff 65 int nGameTickDelay; // delay during game-tick
maxint 0:7e989d0083ff 66
maxint 0:7e989d0083ff 67 void printDouble(double value, int x, int y);
maxint 0:7e989d0083ff 68
maxint 0:7e989d0083ff 69 void initialize();
maxint 0:7e989d0083ff 70
maxint 0:7e989d0083ff 71 void drawString(const char* str, int y);
maxint 0:7e989d0083ff 72
maxint 0:7e989d0083ff 73
maxint 0:7e989d0083ff 74 void initializePaddle();
maxint 0:7e989d0083ff 75 void updatePaddle();
maxint 0:7e989d0083ff 76 void redrawPaddle();
maxint 0:7e989d0083ff 77 /*
maxint 0:7e989d0083ff 78 void clearPaddle();
maxint 0:7e989d0083ff 79 void drawPaddle();
maxint 0:7e989d0083ff 80 */
maxint 0:7e989d0083ff 81 //void initializeBall();
maxint 0:7e989d0083ff 82 //void initializeBalls();
maxint 0:7e989d0083ff 83 void setNoBalls();
maxint 0:7e989d0083ff 84 void newBall();
maxint 0:7e989d0083ff 85 void updateBalls();
maxint 0:7e989d0083ff 86 void redrawBalls();
maxint 0:7e989d0083ff 87 int countBalls();
maxint 0:7e989d0083ff 88 void checkBallsCollision();
maxint 0:7e989d0083ff 89 void redrawTopWall();
maxint 0:7e989d0083ff 90
maxint 0:7e989d0083ff 91 int checkTilt();
maxint 0:7e989d0083ff 92 void checkButtons();
maxint 0:7e989d0083ff 93
maxint 0:7e989d0083ff 94 void checkPaddle();
maxint 0:7e989d0083ff 95 //void checkCollision();
maxint 0:7e989d0083ff 96 void printf(int x, int y, const char *szFormat, ...);
maxint 0:7e989d0083ff 97 void checkBalls();
maxint 0:7e989d0083ff 98
maxint 0:7e989d0083ff 99 public:
maxint 0:7e989d0083ff 100 Game();
maxint 0:7e989d0083ff 101
maxint 0:7e989d0083ff 102 void showSplashScreen();
maxint 0:7e989d0083ff 103 void tick();
maxint 0:7e989d0083ff 104 };