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:
Tue Feb 03 19:02:27 2015 +0000
Revision:
2:d4de5a5866fe
Parent:
1:c1ee4c699517
Child:
3:ca8b21da67dc
Added more balls

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maxint 0:87ab172a74b4 1 #include "Paddle.h"
maxint 0:87ab172a74b4 2
maxint 1:c1ee4c699517 3 Paddle::Paddle(LCD_ST7735* pDisp)
maxint 0:87ab172a74b4 4 { // constructor
maxint 1:c1ee4c699517 5 this->pDisp=pDisp;
maxint 0:87ab172a74b4 6 }
maxint 0:87ab172a74b4 7
maxint 0:87ab172a74b4 8 Paddle::Paddle(LCD_ST7735* pDisp, int nX, int nY, int nWidth, int nHeight)
maxint 0:87ab172a74b4 9 { // constructor
maxint 0:87ab172a74b4 10 this->pos.set(nX, nY);
maxint 0:87ab172a74b4 11 this->dim.nWidth=nWidth;
maxint 0:87ab172a74b4 12 this->dim.nHeight=nHeight;
maxint 1:c1ee4c699517 13 this->pDisp=pDisp;
maxint 0:87ab172a74b4 14 }
maxint 0:87ab172a74b4 15
maxint 1:c1ee4c699517 16 void Paddle::initialize(int nX, int nY, int nWidth, int nHeight)
maxint 0:87ab172a74b4 17 {
maxint 0:87ab172a74b4 18 this->pos.set(nX, nY);
maxint 0:87ab172a74b4 19 this->dim.nWidth=nWidth;
maxint 0:87ab172a74b4 20 this->dim.nHeight=nHeight;
maxint 0:87ab172a74b4 21 }
maxint 0:87ab172a74b4 22
maxint 0:87ab172a74b4 23 void Paddle::checkBoundary(Rectangle rBoundary)
maxint 0:87ab172a74b4 24 {
maxint 0:87ab172a74b4 25 if(pos.getX()<rBoundary.getX1())
maxint 0:87ab172a74b4 26 pos.setX(rBoundary.getX1());
maxint 0:87ab172a74b4 27 if(pos.getX()+dim.nWidth>rBoundary.getX2())
maxint 0:87ab172a74b4 28 pos.setX(rBoundary.getX2()-dim.nWidth);
maxint 0:87ab172a74b4 29 }
maxint 0:87ab172a74b4 30
maxint 2:d4de5a5866fe 31 bool Paddle::hasChanged()
maxint 2:d4de5a5866fe 32 {
maxint 2:d4de5a5866fe 33 return(pos.hasChanged());
maxint 2:d4de5a5866fe 34 }
maxint 0:87ab172a74b4 35
maxint 0:87ab172a74b4 36 void Paddle::move(Vector vDiff)
maxint 0:87ab172a74b4 37 {
maxint 0:87ab172a74b4 38 this->pos.move(vDiff);
maxint 0:87ab172a74b4 39 // this->rPaddle.move(vDiff);
maxint 0:87ab172a74b4 40
maxint 1:c1ee4c699517 41 /*
maxint 0:87ab172a74b4 42 char szBuffer[256];
maxint 0:87ab172a74b4 43 sprintf(szBuffer, "p:%d,%d ", pos.getX(), pos.getY());
maxint 1:c1ee4c699517 44 this->pDisp->drawString(font_oem, 0, 0, szBuffer);
maxint 1:c1ee4c699517 45 */
maxint 0:87ab172a74b4 46
maxint 0:87ab172a74b4 47 }
maxint 0:87ab172a74b4 48
maxint 0:87ab172a74b4 49
maxint 0:87ab172a74b4 50 void Paddle::clearPrev()
maxint 0:87ab172a74b4 51 {
maxint 0:87ab172a74b4 52 Point p=pos.getPrev();
maxint 0:87ab172a74b4 53 this->pDisp->fillRect(p.getX(), p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Black);
maxint 0:87ab172a74b4 54 }
maxint 0:87ab172a74b4 55
maxint 0:87ab172a74b4 56 void Paddle::clear()
maxint 0:87ab172a74b4 57 {
maxint 0:87ab172a74b4 58 Point p=pos.getCur();
maxint 0:87ab172a74b4 59 this->pDisp->fillRect(p.getX(), p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Black);
maxint 0:87ab172a74b4 60 }
maxint 0:87ab172a74b4 61
maxint 0:87ab172a74b4 62 void Paddle::draw()
maxint 0:87ab172a74b4 63 {
maxint 0:87ab172a74b4 64 Point p=pos.getCur();
maxint 1:c1ee4c699517 65 this->pDisp->drawLine(p.getX(), p.getY()+dim.nHeight, p.getX()+dim.nWidth/3, p.getY(), Color565::Blue);
maxint 2:d4de5a5866fe 66 this->pDisp->fillRect(p.getX()+dim.nWidth/3, p.getY(), p.getX()+dim.nWidth/3+dim.nWidth/3, p.getY()+dim.nHeight, Color565::Blue);
maxint 1:c1ee4c699517 67 this->pDisp->drawLine(p.getX()+dim.nWidth/3+dim.nWidth/3, p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Blue);
maxint 0:87ab172a74b4 68 }
maxint 0:87ab172a74b4 69
maxint 0:87ab172a74b4 70 void Paddle::redraw()
maxint 0:87ab172a74b4 71 { // redraw the paddle if its position has changed
maxint 2:d4de5a5866fe 72 //static int n=0;
maxint 2:d4de5a5866fe 73 char szBuffer[256];
maxint 2:d4de5a5866fe 74
maxint 0:87ab172a74b4 75 if(pos.hasChanged())
maxint 0:87ab172a74b4 76 {
maxint 2:d4de5a5866fe 77 Point pPrev=pos.getPrev();
maxint 2:d4de5a5866fe 78 Point pCur=pos.getCur();
maxint 2:d4de5a5866fe 79 /*
maxint 2:d4de5a5866fe 80 n++;
maxint 2:d4de5a5866fe 81 sprintf(szBuffer, "%d %d,%d - %d,%d", n, pPrev.getX(), pPrev.getY(), pCur.getX(), pCur.getY());
maxint 2:d4de5a5866fe 82 this->pDisp->drawString(font_oem, 20, 0, szBuffer);
maxint 2:d4de5a5866fe 83 */
maxint 0:87ab172a74b4 84 clearPrev();
maxint 0:87ab172a74b4 85 draw();
maxint 0:87ab172a74b4 86 }
maxint 0:87ab172a74b4 87 }