Retro game that let's the player steer a ball through a hole filled maze. Has multiple levels of increasing difficulty.

Dependencies:   LCD_ST7735 MusicEngine RETRO_BallsAndThings mbed

Ball and Holes

In this game I attempted to create somewhat natural movement of the ball by implementing gravity and friction which combined over time determine the speed of the ball. Playing with the settings (aka. the magic numbers) that are spread out all over game.cpp, gives different effects, such as an icy, rough or liquid-like surface.

It took some time to figure out how to post my very first youtube video. Sorry for the shaky recording. Trying to record the video with my phone while playing the game in one hand was quite challenging, but here it is;

The left and right buttons are used to cheat: restart the current or go to the next level. Up and down control the game-tick. During game-play the robot-button shows the accelerator graph and the ship-button mutes the sound.

BTW. If your ball happens to get stuck, tilting the console in the opposite direction will set it free. For sake of argument: these magnetic wall-ends are in the words of Bob Ross "a happy accident". Since there is no specific code for it, others might call it a bug. As it results in more interesting game-play, I didn't attempt to fix it, but left a comment for those who dare to look at the mess I call code.

Game.h

Committer:
maxint
Date:
2015-03-02
Revision:
11:ef3cbc443f27
Parent:
8:b119501f4ef0

File content as of revision 11:ef3cbc443f27:

#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 "Wall.h"
#include "Hole.h"


#define NUM_WALLS 30
#define NUM_HOLES 20

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;
    
    static const int BALL_RADIUS = 5;
    static const int HOLE_RADIUS = 6;
    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;
    LCD_ST7735 disp;

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

    Vector vGravity;
    Vector vFriction;
    Ball ball;
    Wall aWalls[NUM_WALLS];
    Hole aHoles[NUM_HOLES];

    bool mode;
    int nTopWall;
    int nBalls;
    int nScore;

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

    void printDouble(double value, int x, int y);
    
    void initialize();
    void initLevel();
    Point getGridPos(char *sPos);
    void addWall(char *sWall);
    void addWalls(char *sWalls);
    void drawWalls();
    void addHole(char *sHole);
    void addHoles(char *sHoles);
    void drawHoles();
    
    void drawString(const char* str, int y);

    void newBall();
    void updateBall();
    void redrawBall();
    void checkBallCollision();
    
    void checkTilt();
    void checkButtons();

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