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.

Revision:
0:87ab172a74b4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Shapes.cpp	Wed Jan 28 17:32:54 2015 +0000
@@ -0,0 +1,227 @@
+#include "mbed.h"
+#include "Shapes.h"
+
+
+
+///////////////////
+// POINT
+///////////////////
+Point::Point()
+{   // constructor
+    x1=0;
+    y1=0;
+}
+
+Point::Point(int x, int y)
+{   // constructor
+    x1=x;
+    y1=y;
+}
+
+int Point::getX()
+{
+    return x1;
+}
+
+int Point::getY()
+{
+    return y1;
+}
+
+void Point::set(int x, int y)
+{
+    x1=x;
+    y1=y;
+}
+
+
+///////////////////
+// RECTANGLE
+///////////////////
+
+Rectangle::Rectangle(int x,int y, int xx, int yy)
+{
+    x1 = x;
+    x2 = xx;
+    y1 = y;
+    y2 = yy;
+}
+
+Rectangle::Rectangle(Point pt1, Point pt2)
+{
+    x1 = pt1.getX();
+    x2 = pt2.getX();
+    y1 = pt1.getY();
+    y2 = pt2.getY();
+}
+
+
+bool Rectangle::collides(Point pt)
+{
+    if(pt.getX() >= x1 && pt.getX() <= x2) {
+        if(pt.getY() >= y1 && pt.getY() <= y2) {
+            return true;
+        }
+    }
+    return false;
+}
+
+/*
+Rectangle Rectangle::intersection(Rectangle r)
+{   // return the intersection of two rectangles or null
+    Rectangle rResult;
+    rResult=Rectangle()
+    if(this->x2 >= 
+}
+*/
+
+bool Rectangle::collides(Rectangle r)
+{   // check if two rectangles collide
+    // method 1: check if corners of eithter rectangle collide
+    // method 2: compare sides
+    if(this->collides(r.get1()) || this->collides(r.get2())) return(true);
+    if(this->collides(r.get3()) || this->collides(r.get4())) return(true);
+    if(r.collides(this->get1()) || r.collides(this->get2())) return(true);
+    if(r.collides(this->get3()) || r.collides(this->get4())) return(true);
+    // TODO: check other corners
+    return(false);
+}
+
+
+Point Rectangle::get1()
+{
+    return(Point(x1, y1));
+}
+
+Point Rectangle::get2()
+{
+    return(Point(x2, y2));
+}
+
+Point Rectangle::get3()
+{
+    return(Point(x2, y1));
+}
+
+Point Rectangle::get4()
+{
+    return(Point(x1, y2));
+}
+ 
+
+ 
+int Rectangle::getX1()
+{
+    return x1;
+}
+ 
+int Rectangle::getX2()
+{
+    return x2;
+}
+ 
+int Rectangle::getY1()
+{
+    return y1;
+}
+ 
+int Rectangle::getY2()
+{
+    return y2;
+}
+ 
+int Rectangle::getCenterX()
+{
+    return x1 + (x2-x1)/2;
+}
+ 
+int Rectangle::getCenterY()
+{
+    return y1 + (y2-y1)/2;
+}
+
+Point Rectangle::getCenter()
+{
+    return(Point(x1 + (x2-x1)/2, y1 + (y2-y1)/2));
+}
+
+void Rectangle::set(Rectangle rNew)
+{
+    x1=rNew.getX1();
+    y1=rNew.getY1();
+    x2=rNew.getX2();
+    y2=rNew.getY2();
+}
+
+void Rectangle::move(Vector v)
+{
+    x1+=rint(v.x);
+    y1+=rint(v.y);
+    x2+=rint(v.x);
+    y2+=rint(v.y);
+}
+
+
+///////////////////
+// CIRCLE
+///////////////////
+Circle::Circle(int x,int y, int r)
+{
+    x1=x;
+    y1=y;
+    r1=r;
+}
+
+Point Circle::getCenter()
+{
+    return(Point(x1, y1));
+}
+
+int Circle::getRadius()
+{
+    return(r1);
+}
+
+int Circle::getX()
+{
+    return(x1);
+}
+
+int Circle::getY()
+{
+    return(y1);
+}
+
+void Circle::setX(int x)
+{
+    x1=x;
+}
+
+void Circle::setY(int y)
+{
+    y1=y;
+}
+
+void Circle::setXY(int x, int y)
+{
+    x1=x;
+    y1=y;
+}
+
+void Circle::move(int x, int y)
+{
+    x1+=x;
+    y1+=y;
+}
+
+void Circle::move(Vector v)
+{
+    x1+=rint(v.x);
+    y1+=rint(v.y);
+}
+
+
+Rectangle Circle::getBoundingRectangle()
+{
+    return(Rectangle(x1-r1, y1-r1, x1+r1, y1+r1));
+}