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
Separated elements as objects, added gravity and bouncespeed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maxint 0:87ab172a74b4 1 #include "mbed.h"
maxint 0:87ab172a74b4 2 #include "Shapes.h"
maxint 0:87ab172a74b4 3
maxint 0:87ab172a74b4 4
maxint 0:87ab172a74b4 5
maxint 0:87ab172a74b4 6 ///////////////////
maxint 0:87ab172a74b4 7 // POINT
maxint 0:87ab172a74b4 8 ///////////////////
maxint 0:87ab172a74b4 9 Point::Point()
maxint 0:87ab172a74b4 10 { // constructor
maxint 0:87ab172a74b4 11 x1=0;
maxint 0:87ab172a74b4 12 y1=0;
maxint 0:87ab172a74b4 13 }
maxint 0:87ab172a74b4 14
maxint 0:87ab172a74b4 15 Point::Point(int x, int y)
maxint 0:87ab172a74b4 16 { // constructor
maxint 0:87ab172a74b4 17 x1=x;
maxint 0:87ab172a74b4 18 y1=y;
maxint 0:87ab172a74b4 19 }
maxint 0:87ab172a74b4 20
maxint 0:87ab172a74b4 21 int Point::getX()
maxint 0:87ab172a74b4 22 {
maxint 0:87ab172a74b4 23 return x1;
maxint 0:87ab172a74b4 24 }
maxint 0:87ab172a74b4 25
maxint 0:87ab172a74b4 26 int Point::getY()
maxint 0:87ab172a74b4 27 {
maxint 0:87ab172a74b4 28 return y1;
maxint 0:87ab172a74b4 29 }
maxint 0:87ab172a74b4 30
maxint 0:87ab172a74b4 31 void Point::set(int x, int y)
maxint 0:87ab172a74b4 32 {
maxint 0:87ab172a74b4 33 x1=x;
maxint 0:87ab172a74b4 34 y1=y;
maxint 0:87ab172a74b4 35 }
maxint 0:87ab172a74b4 36
maxint 0:87ab172a74b4 37
maxint 0:87ab172a74b4 38 ///////////////////
maxint 0:87ab172a74b4 39 // RECTANGLE
maxint 0:87ab172a74b4 40 ///////////////////
maxint 0:87ab172a74b4 41
maxint 0:87ab172a74b4 42 Rectangle::Rectangle(int x,int y, int xx, int yy)
maxint 0:87ab172a74b4 43 {
maxint 0:87ab172a74b4 44 x1 = x;
maxint 0:87ab172a74b4 45 x2 = xx;
maxint 0:87ab172a74b4 46 y1 = y;
maxint 0:87ab172a74b4 47 y2 = yy;
maxint 0:87ab172a74b4 48 }
maxint 0:87ab172a74b4 49
maxint 0:87ab172a74b4 50 Rectangle::Rectangle(Point pt1, Point pt2)
maxint 0:87ab172a74b4 51 {
maxint 0:87ab172a74b4 52 x1 = pt1.getX();
maxint 0:87ab172a74b4 53 x2 = pt2.getX();
maxint 0:87ab172a74b4 54 y1 = pt1.getY();
maxint 0:87ab172a74b4 55 y2 = pt2.getY();
maxint 0:87ab172a74b4 56 }
maxint 0:87ab172a74b4 57
maxint 0:87ab172a74b4 58
maxint 0:87ab172a74b4 59 bool Rectangle::collides(Point pt)
maxint 0:87ab172a74b4 60 {
maxint 0:87ab172a74b4 61 if(pt.getX() >= x1 && pt.getX() <= x2) {
maxint 0:87ab172a74b4 62 if(pt.getY() >= y1 && pt.getY() <= y2) {
maxint 0:87ab172a74b4 63 return true;
maxint 0:87ab172a74b4 64 }
maxint 0:87ab172a74b4 65 }
maxint 0:87ab172a74b4 66 return false;
maxint 0:87ab172a74b4 67 }
maxint 0:87ab172a74b4 68
maxint 0:87ab172a74b4 69 /*
maxint 0:87ab172a74b4 70 Rectangle Rectangle::intersection(Rectangle r)
maxint 0:87ab172a74b4 71 { // return the intersection of two rectangles or null
maxint 0:87ab172a74b4 72 Rectangle rResult;
maxint 0:87ab172a74b4 73 rResult=Rectangle()
maxint 0:87ab172a74b4 74 if(this->x2 >=
maxint 0:87ab172a74b4 75 }
maxint 0:87ab172a74b4 76 */
maxint 0:87ab172a74b4 77
maxint 0:87ab172a74b4 78 bool Rectangle::collides(Rectangle r)
maxint 0:87ab172a74b4 79 { // check if two rectangles collide
maxint 0:87ab172a74b4 80 // method 1: check if corners of eithter rectangle collide
maxint 0:87ab172a74b4 81 // method 2: compare sides
maxint 0:87ab172a74b4 82 if(this->collides(r.get1()) || this->collides(r.get2())) return(true);
maxint 0:87ab172a74b4 83 if(this->collides(r.get3()) || this->collides(r.get4())) return(true);
maxint 0:87ab172a74b4 84 if(r.collides(this->get1()) || r.collides(this->get2())) return(true);
maxint 0:87ab172a74b4 85 if(r.collides(this->get3()) || r.collides(this->get4())) return(true);
maxint 0:87ab172a74b4 86 // TODO: check other corners
maxint 0:87ab172a74b4 87 return(false);
maxint 0:87ab172a74b4 88 }
maxint 0:87ab172a74b4 89
maxint 0:87ab172a74b4 90
maxint 0:87ab172a74b4 91 Point Rectangle::get1()
maxint 0:87ab172a74b4 92 {
maxint 0:87ab172a74b4 93 return(Point(x1, y1));
maxint 0:87ab172a74b4 94 }
maxint 0:87ab172a74b4 95
maxint 0:87ab172a74b4 96 Point Rectangle::get2()
maxint 0:87ab172a74b4 97 {
maxint 0:87ab172a74b4 98 return(Point(x2, y2));
maxint 0:87ab172a74b4 99 }
maxint 0:87ab172a74b4 100
maxint 0:87ab172a74b4 101 Point Rectangle::get3()
maxint 0:87ab172a74b4 102 {
maxint 0:87ab172a74b4 103 return(Point(x2, y1));
maxint 0:87ab172a74b4 104 }
maxint 0:87ab172a74b4 105
maxint 0:87ab172a74b4 106 Point Rectangle::get4()
maxint 0:87ab172a74b4 107 {
maxint 0:87ab172a74b4 108 return(Point(x1, y2));
maxint 0:87ab172a74b4 109 }
maxint 0:87ab172a74b4 110
maxint 0:87ab172a74b4 111
maxint 0:87ab172a74b4 112
maxint 0:87ab172a74b4 113 int Rectangle::getX1()
maxint 0:87ab172a74b4 114 {
maxint 0:87ab172a74b4 115 return x1;
maxint 0:87ab172a74b4 116 }
maxint 0:87ab172a74b4 117
maxint 0:87ab172a74b4 118 int Rectangle::getX2()
maxint 0:87ab172a74b4 119 {
maxint 0:87ab172a74b4 120 return x2;
maxint 0:87ab172a74b4 121 }
maxint 0:87ab172a74b4 122
maxint 0:87ab172a74b4 123 int Rectangle::getY1()
maxint 0:87ab172a74b4 124 {
maxint 0:87ab172a74b4 125 return y1;
maxint 0:87ab172a74b4 126 }
maxint 0:87ab172a74b4 127
maxint 0:87ab172a74b4 128 int Rectangle::getY2()
maxint 0:87ab172a74b4 129 {
maxint 0:87ab172a74b4 130 return y2;
maxint 0:87ab172a74b4 131 }
maxint 0:87ab172a74b4 132
maxint 0:87ab172a74b4 133 int Rectangle::getCenterX()
maxint 0:87ab172a74b4 134 {
maxint 0:87ab172a74b4 135 return x1 + (x2-x1)/2;
maxint 0:87ab172a74b4 136 }
maxint 0:87ab172a74b4 137
maxint 0:87ab172a74b4 138 int Rectangle::getCenterY()
maxint 0:87ab172a74b4 139 {
maxint 0:87ab172a74b4 140 return y1 + (y2-y1)/2;
maxint 0:87ab172a74b4 141 }
maxint 0:87ab172a74b4 142
maxint 0:87ab172a74b4 143 Point Rectangle::getCenter()
maxint 0:87ab172a74b4 144 {
maxint 0:87ab172a74b4 145 return(Point(x1 + (x2-x1)/2, y1 + (y2-y1)/2));
maxint 0:87ab172a74b4 146 }
maxint 0:87ab172a74b4 147
maxint 0:87ab172a74b4 148 void Rectangle::set(Rectangle rNew)
maxint 0:87ab172a74b4 149 {
maxint 0:87ab172a74b4 150 x1=rNew.getX1();
maxint 0:87ab172a74b4 151 y1=rNew.getY1();
maxint 0:87ab172a74b4 152 x2=rNew.getX2();
maxint 0:87ab172a74b4 153 y2=rNew.getY2();
maxint 0:87ab172a74b4 154 }
maxint 0:87ab172a74b4 155
maxint 0:87ab172a74b4 156 void Rectangle::move(Vector v)
maxint 0:87ab172a74b4 157 {
maxint 0:87ab172a74b4 158 x1+=rint(v.x);
maxint 0:87ab172a74b4 159 y1+=rint(v.y);
maxint 0:87ab172a74b4 160 x2+=rint(v.x);
maxint 0:87ab172a74b4 161 y2+=rint(v.y);
maxint 0:87ab172a74b4 162 }
maxint 0:87ab172a74b4 163
maxint 0:87ab172a74b4 164
maxint 0:87ab172a74b4 165 ///////////////////
maxint 0:87ab172a74b4 166 // CIRCLE
maxint 0:87ab172a74b4 167 ///////////////////
maxint 0:87ab172a74b4 168 Circle::Circle(int x,int y, int r)
maxint 0:87ab172a74b4 169 {
maxint 0:87ab172a74b4 170 x1=x;
maxint 0:87ab172a74b4 171 y1=y;
maxint 0:87ab172a74b4 172 r1=r;
maxint 0:87ab172a74b4 173 }
maxint 0:87ab172a74b4 174
maxint 0:87ab172a74b4 175 Point Circle::getCenter()
maxint 0:87ab172a74b4 176 {
maxint 0:87ab172a74b4 177 return(Point(x1, y1));
maxint 0:87ab172a74b4 178 }
maxint 0:87ab172a74b4 179
maxint 0:87ab172a74b4 180 int Circle::getRadius()
maxint 0:87ab172a74b4 181 {
maxint 0:87ab172a74b4 182 return(r1);
maxint 0:87ab172a74b4 183 }
maxint 0:87ab172a74b4 184
maxint 0:87ab172a74b4 185 int Circle::getX()
maxint 0:87ab172a74b4 186 {
maxint 0:87ab172a74b4 187 return(x1);
maxint 0:87ab172a74b4 188 }
maxint 0:87ab172a74b4 189
maxint 0:87ab172a74b4 190 int Circle::getY()
maxint 0:87ab172a74b4 191 {
maxint 0:87ab172a74b4 192 return(y1);
maxint 0:87ab172a74b4 193 }
maxint 0:87ab172a74b4 194
maxint 0:87ab172a74b4 195 void Circle::setX(int x)
maxint 0:87ab172a74b4 196 {
maxint 0:87ab172a74b4 197 x1=x;
maxint 0:87ab172a74b4 198 }
maxint 0:87ab172a74b4 199
maxint 0:87ab172a74b4 200 void Circle::setY(int y)
maxint 0:87ab172a74b4 201 {
maxint 0:87ab172a74b4 202 y1=y;
maxint 0:87ab172a74b4 203 }
maxint 0:87ab172a74b4 204
maxint 0:87ab172a74b4 205 void Circle::setXY(int x, int y)
maxint 0:87ab172a74b4 206 {
maxint 0:87ab172a74b4 207 x1=x;
maxint 0:87ab172a74b4 208 y1=y;
maxint 0:87ab172a74b4 209 }
maxint 0:87ab172a74b4 210
maxint 0:87ab172a74b4 211 void Circle::move(int x, int y)
maxint 0:87ab172a74b4 212 {
maxint 0:87ab172a74b4 213 x1+=x;
maxint 0:87ab172a74b4 214 y1+=y;
maxint 0:87ab172a74b4 215 }
maxint 0:87ab172a74b4 216
maxint 0:87ab172a74b4 217 void Circle::move(Vector v)
maxint 0:87ab172a74b4 218 {
maxint 0:87ab172a74b4 219 x1+=rint(v.x);
maxint 0:87ab172a74b4 220 y1+=rint(v.y);
maxint 0:87ab172a74b4 221 }
maxint 0:87ab172a74b4 222
maxint 0:87ab172a74b4 223
maxint 0:87ab172a74b4 224 Rectangle Circle::getBoundingRectangle()
maxint 0:87ab172a74b4 225 {
maxint 0:87ab172a74b4 226 return(Rectangle(x1-r1, y1-r1, x1+r1, y1+r1));
maxint 0:87ab172a74b4 227 }