Elements used in the Balls and Things games for the RETRO.

Dependents:   RETRO_BallsAndPaddle RETRO_BallAndHoles

Committer:
maxint
Date:
Mon Mar 02 09:58:53 2015 +0000
Revision:
8:19dd2a538cbe
Parent:
6:860b82c19ecf
more clean-up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
maxint 5:065f19e08dcb 1 #include "Hole.h"
maxint 5:065f19e08dcb 2
maxint 5:065f19e08dcb 3 Hole::Hole() : cHole(0,0,0)
maxint 5:065f19e08dcb 4 { // constructor
maxint 5:065f19e08dcb 5 }
maxint 5:065f19e08dcb 6
maxint 5:065f19e08dcb 7 Hole::Hole(LCD_ST7735* pDisp) : cHole(0,0,0)
maxint 5:065f19e08dcb 8 { // constructor
maxint 5:065f19e08dcb 9 this->pDisp=pDisp;
maxint 5:065f19e08dcb 10 setColor(Color565::Gray);
maxint 5:065f19e08dcb 11 this->fActive=false;
maxint 5:065f19e08dcb 12 }
maxint 5:065f19e08dcb 13
maxint 5:065f19e08dcb 14 Hole::Hole(LCD_ST7735* pDisp, uint16_t uClr) : cHole(0,0,0)
maxint 5:065f19e08dcb 15 { // constructor
maxint 5:065f19e08dcb 16 this->pDisp=pDisp;
maxint 5:065f19e08dcb 17 setColor(uClr);
maxint 5:065f19e08dcb 18 this->fActive=false;
maxint 5:065f19e08dcb 19 }
maxint 5:065f19e08dcb 20
maxint 5:065f19e08dcb 21 uint16_t Hole::dimmedColor(uint16_t uColor)
maxint 5:065f19e08dcb 22 {
maxint 5:065f19e08dcb 23 uint16_t r, g, b;
maxint 5:065f19e08dcb 24
maxint 5:065f19e08dcb 25 r=(uColor >> 11) <<3;
maxint 5:065f19e08dcb 26 g=((uColor >> 5) & 0x3F) <<2;
maxint 5:065f19e08dcb 27 b=(uColor & 0x1F) << 3;
maxint 5:065f19e08dcb 28 r=r*2/3;
maxint 5:065f19e08dcb 29 g=g*2/3;
maxint 5:065f19e08dcb 30 b=b*2/3;
maxint 5:065f19e08dcb 31
maxint 5:065f19e08dcb 32 return(Color565::fromRGB((uint16_t)r,(uint16_t)g,(uint16_t)b));
maxint 5:065f19e08dcb 33 }
maxint 5:065f19e08dcb 34
maxint 5:065f19e08dcb 35 void Hole::setColor(uint16_t uClr)
maxint 5:065f19e08dcb 36 {
maxint 5:065f19e08dcb 37 uColor=uClr;
maxint 5:065f19e08dcb 38 this->uColorHigh=uColor;
maxint 5:065f19e08dcb 39 this->uColorMid=dimmedColor(uColorHigh);
maxint 5:065f19e08dcb 40 this->uColorLow=dimmedColor(uColorMid);
maxint 5:065f19e08dcb 41 }
maxint 5:065f19e08dcb 42
maxint 5:065f19e08dcb 43
maxint 5:065f19e08dcb 44
maxint 5:065f19e08dcb 45 void Hole::setCirc(Circle cNew)
maxint 5:065f19e08dcb 46 {
maxint 5:065f19e08dcb 47 cHole=cNew;
maxint 5:065f19e08dcb 48 }
maxint 5:065f19e08dcb 49
maxint 5:065f19e08dcb 50
maxint 5:065f19e08dcb 51 Circle Hole::getCirc()
maxint 5:065f19e08dcb 52 {
maxint 5:065f19e08dcb 53 return(cHole);
maxint 5:065f19e08dcb 54 }
maxint 5:065f19e08dcb 55
maxint 5:065f19e08dcb 56 bool Hole::collides(Circle cObject)
maxint 5:065f19e08dcb 57 {
maxint 5:065f19e08dcb 58 // TODO: could be more precise
maxint 5:065f19e08dcb 59 Rectangle rHole=cHole.getBoundingRectangle();
maxint 5:065f19e08dcb 60 Rectangle rObject=cObject.getBoundingRectangle();
maxint 5:065f19e08dcb 61
maxint 5:065f19e08dcb 62 return(rHole.collides(rObject));
maxint 5:065f19e08dcb 63 }
maxint 5:065f19e08dcb 64
maxint 5:065f19e08dcb 65 bool Hole::hasGoneIn(Circle cObject)
maxint 5:065f19e08dcb 66 { // check if circular object has entered the hole
maxint 6:860b82c19ecf 67 Line l(cHole.getX(), cHole.getY(), cObject.getX(), cObject.getY());
maxint 6:860b82c19ecf 68
maxint 6:860b82c19ecf 69 if(l.getSize()<=cHole.getRadius())
maxint 5:065f19e08dcb 70 return(true);
maxint 5:065f19e08dcb 71 return(false);
maxint 5:065f19e08dcb 72 }
maxint 5:065f19e08dcb 73
maxint 5:065f19e08dcb 74 void Hole::draw()
maxint 5:065f19e08dcb 75 {
maxint 5:065f19e08dcb 76 int x=cHole.getX();
maxint 5:065f19e08dcb 77 int y=cHole.getY();
maxint 5:065f19e08dcb 78 int r=cHole.getRadius();
maxint 5:065f19e08dcb 79 pDisp->fillCircle(x, y, r, this->uColorMid, this->uColorLow);
maxint 5:065f19e08dcb 80 pDisp->fillCircle(x+r/2-r/3, y+r/2-r/3, r-2, Color565::Black, Color565::Black);
maxint 5:065f19e08dcb 81
maxint 5:065f19e08dcb 82 /*
maxint 5:065f19e08dcb 83 char szBuffer[256];
maxint 5:065f19e08dcb 84 sprintf(szBuffer, "h:%d,%d - %d ", cHole.getX(), cHole.getY(), cHole.getRadius());
maxint 5:065f19e08dcb 85 pDisp->drawString(font_oem, 0, 0, szBuffer);
maxint 5:065f19e08dcb 86 */
maxint 5:065f19e08dcb 87
maxint 5:065f19e08dcb 88 }