Elements used in the Balls and Things games for the RETRO.
Dependents: RETRO_BallsAndPaddle RETRO_BallAndHoles
Paddle.cpp@8:19dd2a538cbe, 2015-03-02 (annotated)
- Committer:
- maxint
- Date:
- Mon Mar 02 09:58:53 2015 +0000
- Revision:
- 8:19dd2a538cbe
- Parent:
- 7:4fa3edaa1201
more clean-up
Who changed what in which revision?
User | Revision | Line number | New 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 | /* |
maxint | 0:3d0db4e183ee | 40 | char szBuffer[256]; |
maxint | 0:3d0db4e183ee | 41 | sprintf(szBuffer, "p:%d,%d ", pos.getX(), pos.getY()); |
maxint | 0:3d0db4e183ee | 42 | this->pDisp->drawString(font_oem, 0, 0, szBuffer); |
maxint | 0:3d0db4e183ee | 43 | */ |
maxint | 0:3d0db4e183ee | 44 | |
maxint | 0:3d0db4e183ee | 45 | } |
maxint | 0:3d0db4e183ee | 46 | |
maxint | 0:3d0db4e183ee | 47 | |
maxint | 0:3d0db4e183ee | 48 | void Paddle::clearPrev() |
maxint | 0:3d0db4e183ee | 49 | { |
maxint | 0:3d0db4e183ee | 50 | Point p=pos.getPrev(); |
maxint | 0:3d0db4e183ee | 51 | this->pDisp->fillRect(p.getX(), p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Black); |
maxint | 0:3d0db4e183ee | 52 | } |
maxint | 0:3d0db4e183ee | 53 | |
maxint | 0:3d0db4e183ee | 54 | void Paddle::clear() |
maxint | 0:3d0db4e183ee | 55 | { |
maxint | 0:3d0db4e183ee | 56 | Point p=pos.getCur(); |
maxint | 0:3d0db4e183ee | 57 | this->pDisp->fillRect(p.getX(), p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Black); |
maxint | 0:3d0db4e183ee | 58 | } |
maxint | 0:3d0db4e183ee | 59 | |
maxint | 0:3d0db4e183ee | 60 | void Paddle::draw() |
maxint | 0:3d0db4e183ee | 61 | { |
maxint | 0:3d0db4e183ee | 62 | Point p=pos.getCur(); |
maxint | 0:3d0db4e183ee | 63 | this->pDisp->drawLine(p.getX(), p.getY()+dim.nHeight, p.getX()+dim.nWidth/3, p.getY(), Color565::Blue); |
maxint | 0:3d0db4e183ee | 64 | 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 | 65 | 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 | 66 | } |
maxint | 0:3d0db4e183ee | 67 | |
maxint | 0:3d0db4e183ee | 68 | void Paddle::redraw(bool fForceDraw) // fForceDraw=false |
maxint | 0:3d0db4e183ee | 69 | { // redraw the paddle if its position has changed |
maxint | 0:3d0db4e183ee | 70 | |
maxint | 0:3d0db4e183ee | 71 | if(pos.hasChanged() || fForceDraw) |
maxint | 0:3d0db4e183ee | 72 | { |
maxint | 0:3d0db4e183ee | 73 | Point pPrev=pos.getPrev(); |
maxint | 0:3d0db4e183ee | 74 | Point pCur=pos.getCur(); |
maxint | 0:3d0db4e183ee | 75 | clearPrev(); |
maxint | 0:3d0db4e183ee | 76 | draw(); |
maxint | 0:3d0db4e183ee | 77 | } |
maxint | 0:3d0db4e183ee | 78 | } |