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.

Committer:
maxint
Date:
Mon Mar 02 10:16:55 2015 +0000
Revision:
11:ef3cbc443f27
Parent:
8:b119501f4ef0
more clean-up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maxint 0:87ab172a74b4 1 #pragma once
maxint 0:87ab172a74b4 2 #include <stdarg.h>
maxint 5:67e75a4f0b52 3 #include <algorithm> // required for min() and max(), see http://www.cplusplus.com/reference/algorithm/
maxint 0:87ab172a74b4 4 #include "mbed.h"
maxint 0:87ab172a74b4 5
maxint 0:87ab172a74b4 6 #include "Color565.h"
maxint 1:c1ee4c699517 7 #include "font_OEM.h"
maxint 0:87ab172a74b4 8 #include "LCD_ST7735.h"
maxint 2:d4de5a5866fe 9 #include "SoundFX.h"
maxint 0:87ab172a74b4 10 #include "Accelerometer.h"
maxint 0:87ab172a74b4 11 #include "Shapes.h"
maxint 0:87ab172a74b4 12 #include "Ball.h"
maxint 6:e2eead4e53fb 13 #include "Wall.h"
maxint 7:6e7b789f4060 14 #include "Hole.h"
maxint 0:87ab172a74b4 15
maxint 0:87ab172a74b4 16
maxint 7:6e7b789f4060 17 #define NUM_WALLS 30
maxint 8:b119501f4ef0 18 #define NUM_HOLES 20
maxint 0:87ab172a74b4 19
maxint 2:d4de5a5866fe 20 class Game
maxint 2:d4de5a5866fe 21 {
maxint 0:87ab172a74b4 22 static const char* LOSE_1;
maxint 0:87ab172a74b4 23 static const char* LOSE_2;
maxint 0:87ab172a74b4 24 static const char* SPLASH_1;
maxint 0:87ab172a74b4 25 static const char* SPLASH_2;
maxint 0:87ab172a74b4 26 static const char* SPLASH_3;
maxint 0:87ab172a74b4 27
maxint 6:e2eead4e53fb 28 static const int BALL_RADIUS = 5;
maxint 7:6e7b789f4060 29 static const int HOLE_RADIUS = 6;
maxint 0:87ab172a74b4 30 static const char I2C_ADDR = 0x1C << 1;
maxint 0:87ab172a74b4 31
maxint 0:87ab172a74b4 32 DigitalIn left;
maxint 0:87ab172a74b4 33 DigitalIn right;
maxint 0:87ab172a74b4 34 DigitalIn down;
maxint 0:87ab172a74b4 35 DigitalIn up;
maxint 0:87ab172a74b4 36 DigitalIn square;
maxint 0:87ab172a74b4 37 DigitalIn circle;
maxint 0:87ab172a74b4 38 DigitalOut led1;
maxint 0:87ab172a74b4 39 DigitalOut led2;
maxint 0:87ab172a74b4 40 AnalogIn ain;
maxint 0:87ab172a74b4 41 LCD_ST7735 disp;
maxint 0:87ab172a74b4 42
maxint 2:d4de5a5866fe 43 SoundFX snd;
maxint 0:87ab172a74b4 44 Accelerometer accel;
maxint 7:6e7b789f4060 45 Timer tWait; // timer used for tickcounts
maxint 0:87ab172a74b4 46
maxint 0:87ab172a74b4 47 Vector vGravity;
maxint 6:e2eead4e53fb 48 Vector vFriction;
maxint 0:87ab172a74b4 49 Ball ball;
maxint 6:e2eead4e53fb 50 Wall aWalls[NUM_WALLS];
maxint 7:6e7b789f4060 51 Hole aHoles[NUM_HOLES];
maxint 0:87ab172a74b4 52
maxint 3:ca8b21da67dc 53 bool mode;
maxint 6:e2eead4e53fb 54 int nTopWall;
maxint 3:ca8b21da67dc 55 int nBalls;
maxint 1:c1ee4c699517 56 int nScore;
maxint 3:ca8b21da67dc 57
maxint 0:87ab172a74b4 58 bool lastUp;
maxint 0:87ab172a74b4 59 bool lastDown;
maxint 3:ca8b21da67dc 60 int nGameTickDelay; // delay during game-tick
maxint 0:87ab172a74b4 61
maxint 0:87ab172a74b4 62 void printDouble(double value, int x, int y);
maxint 0:87ab172a74b4 63
maxint 0:87ab172a74b4 64 void initialize();
maxint 8:b119501f4ef0 65 void initLevel();
maxint 6:e2eead4e53fb 66 Point getGridPos(char *sPos);
maxint 6:e2eead4e53fb 67 void addWall(char *sWall);
maxint 8:b119501f4ef0 68 void addWalls(char *sWalls);
maxint 6:e2eead4e53fb 69 void drawWalls();
maxint 7:6e7b789f4060 70 void addHole(char *sHole);
maxint 8:b119501f4ef0 71 void addHoles(char *sHoles);
maxint 7:6e7b789f4060 72 void drawHoles();
maxint 0:87ab172a74b4 73
maxint 0:87ab172a74b4 74 void drawString(const char* str, int y);
maxint 6:e2eead4e53fb 75
maxint 6:e2eead4e53fb 76 void newBall();
maxint 6:e2eead4e53fb 77 void updateBall();
maxint 6:e2eead4e53fb 78 void redrawBall();
maxint 6:e2eead4e53fb 79 void checkBallCollision();
maxint 0:87ab172a74b4 80
maxint 6:e2eead4e53fb 81 void checkTilt();
maxint 0:87ab172a74b4 82 void checkButtons();
maxint 2:d4de5a5866fe 83
maxint 1:c1ee4c699517 84 void printf(int x, int y, const char *szFormat, ...);
maxint 7:6e7b789f4060 85 void checkNumBalls();
maxint 0:87ab172a74b4 86
maxint 0:87ab172a74b4 87 public:
maxint 0:87ab172a74b4 88 Game();
maxint 0:87ab172a74b4 89
maxint 0:87ab172a74b4 90 void showSplashScreen();
maxint 0:87ab172a74b4 91 void tick();
maxint 0:87ab172a74b4 92 };