Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RETRO_BallsAndPaddle RETRO_BallAndHoles
Revision 5:065f19e08dcb, committed 2015-02-28
- Comitter:
- maxint
- Date:
- Sat Feb 28 16:32:03 2015 +0000
- Parent:
- 4:f421e34313d3
- Child:
- 6:860b82c19ecf
- Commit message:
- added holes
Changed in this revision
--- a/Ball.cpp Sat Feb 28 11:40:24 2015 +0000
+++ b/Ball.cpp Sat Feb 28 16:32:03 2015 +0000
@@ -86,6 +86,16 @@
return(rBall.collides(r));
}
+bool Ball::collides(Circle cObject)
+{
+ Circle cBall=this->getBoundingCircle();
+ Rectangle rBall=cBall.getBoundingRectangle();
+ Rectangle rObject=cObject.getBoundingRectangle();
+
+ return(rBall.collides(rObject));
+}
+
+
bool Ball::collides(Line ln)
{
Circle cBall=this->getBoundingCircle();
--- a/Ball.h Sat Feb 28 11:40:24 2015 +0000
+++ b/Ball.h Sat Feb 28 16:32:03 2015 +0000
@@ -33,6 +33,7 @@
Circle getBoundingCircle();
bool collides(Rectangle r);
+ bool collides(Circle cObject);
bool collides(Line ln);
void Bounce(Vector vBounce);
void BounceAgainst(Vector vBounce);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Hole.cpp Sat Feb 28 16:32:03 2015 +0000
@@ -0,0 +1,86 @@
+#include "Hole.h"
+
+Hole::Hole() : cHole(0,0,0)
+{ // constructor
+}
+
+Hole::Hole(LCD_ST7735* pDisp) : cHole(0,0,0)
+{ // constructor
+ this->pDisp=pDisp;
+ setColor(Color565::Gray);
+ this->fActive=false;
+}
+
+Hole::Hole(LCD_ST7735* pDisp, uint16_t uClr) : cHole(0,0,0)
+{ // constructor
+ this->pDisp=pDisp;
+ setColor(uClr);
+ this->fActive=false;
+}
+
+uint16_t Hole::dimmedColor(uint16_t uColor)
+{
+ uint16_t r, g, b;
+
+ r=(uColor >> 11) <<3;
+ g=((uColor >> 5) & 0x3F) <<2;
+ b=(uColor & 0x1F) << 3;
+ r=r*2/3;
+ g=g*2/3;
+ b=b*2/3;
+
+ return(Color565::fromRGB((uint16_t)r,(uint16_t)g,(uint16_t)b));
+}
+
+void Hole::setColor(uint16_t uClr)
+{
+ uColor=uClr;
+ this->uColorHigh=uColor;
+ this->uColorMid=dimmedColor(uColorHigh);
+ this->uColorLow=dimmedColor(uColorMid);
+}
+
+
+
+void Hole::setCirc(Circle cNew)
+{
+ cHole=cNew;
+}
+
+
+Circle Hole::getCirc()
+{
+ return(cHole);
+}
+
+bool Hole::collides(Circle cObject)
+{
+ // TODO: could be more precise
+ Rectangle rHole=cHole.getBoundingRectangle();
+ Rectangle rObject=cObject.getBoundingRectangle();
+
+ return(rHole.collides(rObject));
+}
+
+bool Hole::hasGoneIn(Circle cObject)
+{ // check if circular object has entered the hole
+ if(abs(cHole.getX()-cObject.getX())<=2 && abs(cHole.getY()-cObject.getY())<=2)
+ return(true);
+ return(false);
+}
+
+void Hole::draw()
+{
+ int x=cHole.getX();
+ int y=cHole.getY();
+ int r=cHole.getRadius();
+ pDisp->fillCircle(x, y, r, this->uColorMid, this->uColorLow);
+ pDisp->fillCircle(x+r/2-r/3, y+r/2-r/3, r-2, Color565::Black, Color565::Black);
+
+/*
+char szBuffer[256];
+sprintf(szBuffer, "h:%d,%d - %d ", cHole.getX(), cHole.getY(), cHole.getRadius());
+pDisp->drawString(font_oem, 0, 0, szBuffer);
+*/
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Hole.h Sat Feb 28 16:32:03 2015 +0000
@@ -0,0 +1,35 @@
+#pragma once
+#include "mbed.h"
+
+#include "Color565.h"
+#include "font_OEM.h"
+#include "LCD_ST7735.h"
+
+#include "Shapes.h"
+
+class Hole
+{
+ public:
+ Hole();
+ Hole(LCD_ST7735* pDisp);
+ Hole(LCD_ST7735* pDisp, uint16_t uClr);
+ void setColor(uint16_t uClr);
+ void draw();
+ void setCirc(Circle cNew);
+ Circle getCirc();
+ bool collides(Circle cObject);
+ bool hasGoneIn(Circle cObject);
+
+ bool fActive;
+
+ protected:
+ uint16_t dimmedColor(uint16_t uColor);
+
+ private:
+ uint16_t uColor;
+ uint16_t uColorHigh;
+ uint16_t uColorMid;
+ uint16_t uColorLow;
+ LCD_ST7735* pDisp;
+ Circle cHole;
+};
\ No newline at end of file
--- a/Wall.cpp Sat Feb 28 11:40:24 2015 +0000
+++ b/Wall.cpp Sat Feb 28 16:32:03 2015 +0000
@@ -11,6 +11,14 @@
this->fActive=false;
}
+Wall::Wall(LCD_ST7735* pDisp, uint16_t uClr) : rWall(0,0,0,0)
+{ // constructor
+ this->pDisp=pDisp;
+ uColor=uClr;
+ this->fActive=false;
+}
+
+
void Wall::setRect(Rectangle rNew)
{
rWall=rNew;
--- a/Wall.h Sat Feb 28 11:40:24 2015 +0000
+++ b/Wall.h Sat Feb 28 16:32:03 2015 +0000
@@ -12,6 +12,7 @@
public:
Wall();
Wall(LCD_ST7735* pDisp);
+ Wall(LCD_ST7735* pDisp, uint16_t uClr);
void draw();
bool fActive;
void setRect(Rectangle rNew);