Maxint R&D / RETRO_BallsAndThings

Dependents:   RETRO_BallsAndPaddle RETRO_BallAndHoles

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Hole.cpp Source File

Hole.cpp

00001 #include "Hole.h"
00002 
00003 Hole::Hole() : cHole(0,0,0)
00004 {   // constructor
00005 }
00006 
00007 Hole::Hole(LCD_ST7735* pDisp) : cHole(0,0,0)
00008 {   // constructor
00009     this->pDisp=pDisp;
00010     setColor(Color565::Gray);
00011     this->fActive=false;
00012 }
00013 
00014 Hole::Hole(LCD_ST7735* pDisp, uint16_t uClr) : cHole(0,0,0)
00015 {   // constructor
00016     this->pDisp=pDisp;
00017     setColor(uClr);
00018     this->fActive=false;
00019 }
00020 
00021 uint16_t Hole::dimmedColor(uint16_t uColor)
00022 {
00023     uint16_t r, g, b;
00024    
00025     r=(uColor >> 11) <<3;
00026     g=((uColor >> 5) & 0x3F) <<2;
00027     b=(uColor & 0x1F) << 3;
00028     r=r*2/3;
00029     g=g*2/3;
00030     b=b*2/3;
00031 
00032     return(Color565::fromRGB((uint16_t)r,(uint16_t)g,(uint16_t)b));
00033 }
00034 
00035 void Hole::setColor(uint16_t uClr)
00036 {
00037     uColor=uClr;
00038     this->uColorHigh=uColor;
00039     this->uColorMid=dimmedColor(uColorHigh);
00040     this->uColorLow=dimmedColor(uColorMid);
00041 }
00042 
00043 
00044 
00045 void Hole::setCirc(Circle cNew)
00046 {
00047     cHole=cNew;
00048 }
00049 
00050 
00051 Circle Hole::getCirc()
00052 {
00053     return(cHole);
00054 }
00055 
00056 bool Hole::collides(Circle cObject)
00057 {
00058     // TODO: could be more precise
00059     Rectangle rHole=cHole.getBoundingRectangle();
00060     Rectangle rObject=cObject.getBoundingRectangle();
00061 
00062     return(rHole.collides(rObject));
00063 }
00064 
00065 bool Hole::hasGoneIn(Circle cObject)
00066 {   // check if circular object has entered the hole
00067     Line l(cHole.getX(), cHole.getY(), cObject.getX(), cObject.getY());
00068 
00069     if(l.getSize()<=cHole.getRadius())
00070         return(true);
00071     return(false);
00072 }
00073 
00074 void Hole::draw()
00075 {
00076     int x=cHole.getX();
00077     int y=cHole.getY();
00078     int r=cHole.getRadius();
00079     pDisp->fillCircle(x, y, r, this->uColorMid, this->uColorLow);
00080     pDisp->fillCircle(x+r/2-r/3, y+r/2-r/3, r-2, Color565::Black, Color565::Black);
00081 
00082 /*
00083 char szBuffer[256];
00084 sprintf(szBuffer, "h:%d,%d - %d     ", cHole.getX(), cHole.getY(), cHole.getRadius());
00085 pDisp->drawString(font_oem, 0, 0, szBuffer);
00086 */
00087 
00088 }