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 #include "Physics.h"
maxint 0:87ab172a74b4 2
maxint 0:87ab172a74b4 3 Position::Position() : vPos(), pPrev(), pCur()
maxint 0:87ab172a74b4 4 { // constructor
maxint 0:87ab172a74b4 5
maxint 0:87ab172a74b4 6 }
maxint 0:87ab172a74b4 7
maxint 0:87ab172a74b4 8 Point Position::getPrev()
maxint 0:87ab172a74b4 9 {
maxint 0:87ab172a74b4 10 return(pPrev);
maxint 0:87ab172a74b4 11 }
maxint 0:87ab172a74b4 12
maxint 0:87ab172a74b4 13 Point Position::getCur()
maxint 0:87ab172a74b4 14 {
maxint 0:87ab172a74b4 15 return(pCur);
maxint 0:87ab172a74b4 16 }
maxint 0:87ab172a74b4 17
maxint 0:87ab172a74b4 18 int Position::getX()
maxint 0:87ab172a74b4 19 {
maxint 0:87ab172a74b4 20 return(pCur.getX());
maxint 0:87ab172a74b4 21 }
maxint 0:87ab172a74b4 22 int Position::getY()
maxint 0:87ab172a74b4 23 {
maxint 0:87ab172a74b4 24 return(pCur.getY());
maxint 0:87ab172a74b4 25 }
maxint 0:87ab172a74b4 26
maxint 0:87ab172a74b4 27 void Position::set(float x, float y)
maxint 0:87ab172a74b4 28 {
maxint 0:87ab172a74b4 29 //nPrevX=nCurX;
maxint 0:87ab172a74b4 30 //nPrevY=nCurY;
maxint 0:87ab172a74b4 31 pPrev=pCur;
maxint 0:87ab172a74b4 32 vPos.x=x;
maxint 0:87ab172a74b4 33 vPos.y=y;
maxint 0:87ab172a74b4 34 pCur.set(rint(vPos.x), rint(vPos.y));
maxint 0:87ab172a74b4 35 //nCurX=rint(vPos.x);
maxint 0:87ab172a74b4 36 //nCurY=rint(vPos.y);
maxint 0:87ab172a74b4 37 }
maxint 0:87ab172a74b4 38
maxint 0:87ab172a74b4 39 void Position::set(int x, int y)
maxint 0:87ab172a74b4 40 {
maxint 0:87ab172a74b4 41 set((float)x, (float)y);
maxint 0:87ab172a74b4 42 }
maxint 0:87ab172a74b4 43
maxint 0:87ab172a74b4 44 void Position::setX(int x)
maxint 0:87ab172a74b4 45 {
maxint 0:87ab172a74b4 46 set((float)x, vPos.y);
maxint 0:87ab172a74b4 47 }
maxint 0:87ab172a74b4 48
maxint 0:87ab172a74b4 49 void Position::setY(int y)
maxint 0:87ab172a74b4 50 {
maxint 0:87ab172a74b4 51 set(vPos.x, (float)y);
maxint 0:87ab172a74b4 52 }
maxint 0:87ab172a74b4 53
maxint 0:87ab172a74b4 54
maxint 0:87ab172a74b4 55 void Position::set(Vector vNew)
maxint 0:87ab172a74b4 56 {
maxint 0:87ab172a74b4 57 move(vNew.x, vNew.y);
maxint 0:87ab172a74b4 58 }
maxint 0:87ab172a74b4 59
maxint 0:87ab172a74b4 60 void Position::move(float fDiffX, float fDiffY)
maxint 0:87ab172a74b4 61 {
maxint 0:87ab172a74b4 62 //nPrevX=nCurX;
maxint 0:87ab172a74b4 63 //nPrevY=nCurY;
maxint 0:87ab172a74b4 64 pPrev=pCur;
maxint 0:87ab172a74b4 65 vPos.x+=fDiffX;
maxint 0:87ab172a74b4 66 vPos.y+=fDiffY;
maxint 0:87ab172a74b4 67 pCur.set(rint(vPos.x), rint(vPos.y));
maxint 0:87ab172a74b4 68 //nCurX=rint(vPos.x);
maxint 0:87ab172a74b4 69 //nCurY=rint(vPos.y);
maxint 0:87ab172a74b4 70 }
maxint 0:87ab172a74b4 71
maxint 0:87ab172a74b4 72 void Position::move(int nDiffX, int nDiffY)
maxint 0:87ab172a74b4 73 {
maxint 0:87ab172a74b4 74 move((float)nDiffX, (float)nDiffY);
maxint 0:87ab172a74b4 75 }
maxint 0:87ab172a74b4 76
maxint 0:87ab172a74b4 77 void Position::move(Vector vDiff)
maxint 0:87ab172a74b4 78 {
maxint 0:87ab172a74b4 79 move(vDiff.x, vDiff.y);
maxint 0:87ab172a74b4 80 }
maxint 0:87ab172a74b4 81
maxint 0:87ab172a74b4 82 bool Position::hasChanged()
maxint 0:87ab172a74b4 83 {
maxint 0:87ab172a74b4 84 //return(nPrevX!=nCurX || nPrevy!=nCury);
maxint 0:87ab172a74b4 85 return(pPrev.getX()!=pCur.getX() || pPrev.getY()!=pCur.getY());
maxint 0:87ab172a74b4 86 }
maxint 0:87ab172a74b4 87
maxint 0:87ab172a74b4 88 Dimension::Dimension()
maxint 0:87ab172a74b4 89 {
maxint 0:87ab172a74b4 90 nWidth=0;
maxint 0:87ab172a74b4 91 nHeight=0;
maxint 0:87ab172a74b4 92 }