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:
Wed Jan 28 17:32:54 2015 +0000
Revision:
0:87ab172a74b4
Child:
1:c1ee4c699517
Separated elements as objects, added gravity and bouncespeed.

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 0:87ab172a74b4 3 #include "mbed.h"
maxint 0:87ab172a74b4 4
maxint 0:87ab172a74b4 5 #include "Color565.h"
maxint 0:87ab172a74b4 6 #include "font_IBM.h"
maxint 0:87ab172a74b4 7 #include "LCD_ST7735.h"
maxint 0:87ab172a74b4 8 #include "Accelerometer.h"
maxint 0:87ab172a74b4 9 #include "Shapes.h"
maxint 0:87ab172a74b4 10 #include "Ball.h"
maxint 0:87ab172a74b4 11 #include "Paddle.h"
maxint 0:87ab172a74b4 12
maxint 0:87ab172a74b4 13 //#include "DisplayN18.h"
maxint 0:87ab172a74b4 14
maxint 0:87ab172a74b4 15
maxint 0:87ab172a74b4 16
maxint 0:87ab172a74b4 17
maxint 0:87ab172a74b4 18 class Game {
maxint 0:87ab172a74b4 19 static const char* LOSE_1;
maxint 0:87ab172a74b4 20 static const char* LOSE_2;
maxint 0:87ab172a74b4 21 static const char* SPLASH_1;
maxint 0:87ab172a74b4 22 static const char* SPLASH_2;
maxint 0:87ab172a74b4 23 static const char* SPLASH_3;
maxint 0:87ab172a74b4 24 //char buf[256];
maxint 0:87ab172a74b4 25
maxint 0:87ab172a74b4 26 //static const int BALL_RADIUS = 3;
maxint 0:87ab172a74b4 27 static const int BALL_RADIUS = 6;
maxint 0:87ab172a74b4 28 static const int PADDLE_WIDTH = 38;
maxint 0:87ab172a74b4 29 static const int PADDLE_HEIGHT = 4;
maxint 0:87ab172a74b4 30 static const int PADDLE_SPEED = 4;
maxint 0:87ab172a74b4 31 static const int BOUNCE1_SOUND_TICKS = 1;
maxint 0:87ab172a74b4 32 static const int BOUNCE2_SOUND_TICKS = 2;
maxint 0:87ab172a74b4 33 static const int GRAPH_HEIGHT = 40;
maxint 0:87ab172a74b4 34 static const int GRAPH_SPACING = 2;
maxint 0:87ab172a74b4 35 static const char I2C_ADDR = 0x1C << 1;
maxint 0:87ab172a74b4 36
maxint 0:87ab172a74b4 37
maxint 0:87ab172a74b4 38 DigitalIn left;
maxint 0:87ab172a74b4 39 DigitalIn right;
maxint 0:87ab172a74b4 40 DigitalIn down;
maxint 0:87ab172a74b4 41 DigitalIn up;
maxint 0:87ab172a74b4 42 DigitalIn square;
maxint 0:87ab172a74b4 43 DigitalIn circle;
maxint 0:87ab172a74b4 44 DigitalOut led1;
maxint 0:87ab172a74b4 45 DigitalOut led2;
maxint 0:87ab172a74b4 46 PwmOut pwm;
maxint 0:87ab172a74b4 47 AnalogIn ain;
maxint 0:87ab172a74b4 48 I2C i2c;
maxint 0:87ab172a74b4 49 // DisplayN18 disp;
maxint 0:87ab172a74b4 50 LCD_ST7735 disp;
maxint 0:87ab172a74b4 51
maxint 0:87ab172a74b4 52 Accelerometer accel;
maxint 0:87ab172a74b4 53 Timer tWait; // timer used for tickcounts
maxint 0:87ab172a74b4 54
maxint 0:87ab172a74b4 55 Vector vGravity;
maxint 0:87ab172a74b4 56 Ball ball;
maxint 0:87ab172a74b4 57 Paddle paddle;
maxint 0:87ab172a74b4 58
maxint 0:87ab172a74b4 59 int paddleX;
maxint 0:87ab172a74b4 60 int pwmTicksLeft;
maxint 0:87ab172a74b4 61 int lives;
maxint 0:87ab172a74b4 62 int graphX;
maxint 0:87ab172a74b4 63 bool mode;
maxint 0:87ab172a74b4 64 bool lastUp;
maxint 0:87ab172a74b4 65 bool lastDown;
maxint 0:87ab172a74b4 66 unsigned short colors[3];
maxint 0:87ab172a74b4 67
maxint 0:87ab172a74b4 68
maxint 0:87ab172a74b4 69 /*
maxint 0:87ab172a74b4 70 void readRegisters(char address, char* buffer, int len);
maxint 0:87ab172a74b4 71 int writeRegister(char address, char value);
maxint 0:87ab172a74b4 72 double convert(char* buffer);
maxint 0:87ab172a74b4 73 void getXYZ(double& x, double& y, double& z);
maxint 0:87ab172a74b4 74 */
maxint 0:87ab172a74b4 75 void printDouble(double value, int x, int y);
maxint 0:87ab172a74b4 76
maxint 0:87ab172a74b4 77 void drawAxes();
maxint 0:87ab172a74b4 78 void drawPoint(int axis, double value);
maxint 0:87ab172a74b4 79 void checkGraphReset();
maxint 0:87ab172a74b4 80
maxint 0:87ab172a74b4 81 void initialize();
maxint 0:87ab172a74b4 82 void initializeBall();
maxint 0:87ab172a74b4 83 void initializePaddle();
maxint 0:87ab172a74b4 84
maxint 0:87ab172a74b4 85 void drawString(const char* str, int y);
maxint 0:87ab172a74b4 86
maxint 0:87ab172a74b4 87 void clearPaddle();
maxint 0:87ab172a74b4 88 void drawPaddle();
maxint 0:87ab172a74b4 89 void updatePaddle();
maxint 0:87ab172a74b4 90
maxint 0:87ab172a74b4 91 int checkTilt();
maxint 0:87ab172a74b4 92 void checkButtons();
maxint 0:87ab172a74b4 93 void checkCollision();
maxint 0:87ab172a74b4 94 void checkPwm();
maxint 0:87ab172a74b4 95 void Printf(int x, int y, const char *szFormat, ...);
maxint 0:87ab172a74b4 96 void checkLives();
maxint 0:87ab172a74b4 97
maxint 0:87ab172a74b4 98 public:
maxint 0:87ab172a74b4 99 Game();
maxint 0:87ab172a74b4 100
maxint 0:87ab172a74b4 101 void showSplashScreen();
maxint 0:87ab172a74b4 102 void tick();
maxint 0:87ab172a74b4 103 };