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
Game.h@3:a68d4d515c20, 2015-02-25 (annotated)
- Committer:
- maxint
- Date:
- Wed Feb 25 10:43:41 2015 +0000
- Revision:
- 3:a68d4d515c20
- Parent:
- 1:bf46edcd6b4f
- Child:
- 5:8441b390a15f
experimenting with better bouncing
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:a68d4d515c20 | 29 | static const int PADDLE_WIDTH = 39; |
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 initialize(); |
maxint | 0:7e989d0083ff | 68 | |
maxint | 1:bf46edcd6b4f | 69 | void printDouble(double value, int x, int y); |
maxint | 0:7e989d0083ff | 70 | void drawString(const char* str, int y); |
maxint | 1:bf46edcd6b4f | 71 | void printf(int x, int y, const char *szFormat, ...); |
maxint | 1:bf46edcd6b4f | 72 | int checkTiltLeftRight(); |
maxint | 0:7e989d0083ff | 73 | |
maxint | 0:7e989d0083ff | 74 | void initializePaddle(); |
maxint | 0:7e989d0083ff | 75 | void updatePaddle(); |
maxint | 0:7e989d0083ff | 76 | void redrawPaddle(); |
maxint | 1:bf46edcd6b4f | 77 | void checkPaddle(); |
maxint | 1:bf46edcd6b4f | 78 | |
maxint | 0:7e989d0083ff | 79 | void setNoBalls(); |
maxint | 0:7e989d0083ff | 80 | void newBall(); |
maxint | 0:7e989d0083ff | 81 | void updateBalls(); |
maxint | 0:7e989d0083ff | 82 | void redrawBalls(); |
maxint | 0:7e989d0083ff | 83 | int countBalls(); |
maxint | 1:bf46edcd6b4f | 84 | void checkNumBalls(); |
maxint | 0:7e989d0083ff | 85 | void checkBallsCollision(); |
maxint | 1:bf46edcd6b4f | 86 | |
maxint | 0:7e989d0083ff | 87 | void redrawTopWall(); |
maxint | 0:7e989d0083ff | 88 | void checkButtons(); |
maxint | 0:7e989d0083ff | 89 | |
maxint | 0:7e989d0083ff | 90 | //void checkCollision(); |
maxint | 0:7e989d0083ff | 91 | |
maxint | 0:7e989d0083ff | 92 | public: |
maxint | 0:7e989d0083ff | 93 | Game(); |
maxint | 0:7e989d0083ff | 94 | |
maxint | 0:7e989d0083ff | 95 | void showSplashScreen(); |
maxint | 0:7e989d0083ff | 96 | void tick(); |
maxint | 0:7e989d0083ff | 97 | }; |