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

Committer:
maxint
Date:
2015-02-06
Revision:
0:7e989d0083ff
Child:
1:bf46edcd6b4f

File content as of revision 0:7e989d0083ff:

#pragma once
#include <stdarg.h>
#include <algorithm>        // required for min() and max(), see http://www.cplusplus.com/reference/algorithm/
#include "mbed.h"

#include "Color565.h"
#include "font_OEM.h"
#include "LCD_ST7735.h"
#include "SoundFX.h"
#include "Accelerometer.h"
#include "Shapes.h"
#include "Ball.h"
#include "Paddle.h"


#define NUM_BALLS 3

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 char I2C_ADDR = 0x1C << 1;

    DigitalIn left;
    DigitalIn right;
    DigitalIn down;
    DigitalIn up;
    DigitalIn square;
    DigitalIn circle; 
    DigitalOut led1;
    DigitalOut led2;
    AnalogIn ain;
    I2C i2c;
    LCD_ST7735 disp;

    SoundFX snd;
    Accelerometer accel;
//    Timer tWait;    // timer used for tickcounts

    Vector vGravity;
    Ball ball;
    Paddle paddle;
    Ball aBalls[NUM_BALLS];

    bool mode;
    int nBalls;
    int nScore;
    bool fDrawPaddle;
    bool fDrawTopWall;
    
    int nTopWall;

    bool lastUp;
    bool lastDown;
    int nGameTickDelay;     // delay during game-tick

    void printDouble(double value, int x, int y);
    
    void initialize();
    
    void drawString(const char* str, int y);
    

    void initializePaddle();
    void updatePaddle();
    void redrawPaddle();
/*
    void clearPaddle();
    void drawPaddle();
*/
    //void initializeBall();
    //void initializeBalls();
    void setNoBalls();
    void newBall();
    void updateBalls();
    void redrawBalls();
    int countBalls();
    void checkBallsCollision();
    void redrawTopWall();
    
    int checkTilt();
    void checkButtons();

    void checkPaddle();
    //void checkCollision();
    void printf(int x, int y, const char *szFormat, ...);
    void checkBalls();
    
    public:
        Game();
        
        void showSplashScreen();
        void tick();
};