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

Dependents:   RETRO_BallsAndPaddle RETRO_BallAndHoles

Committer:
maxint
Date:
Fri Feb 06 09:51:06 2015 +0000
Revision:
0:3d0db4e183ee
Child:
7:4fa3edaa1201
Put Balls and Things objects into a library

Who changed what in which revision?

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