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
Paddle.cpp
00001 #include "Paddle.h" 00002 00003 Paddle::Paddle(LCD_ST7735* pDisp) 00004 { // constructor 00005 this->pDisp=pDisp; 00006 } 00007 00008 Paddle::Paddle(LCD_ST7735* pDisp, int nX, int nY, int nWidth, int nHeight) 00009 { // constructor 00010 this->pos.set(nX, nY); 00011 this->dim.nWidth=nWidth; 00012 this->dim.nHeight=nHeight; 00013 this->pDisp=pDisp; 00014 } 00015 00016 void Paddle::initialize(int nX, int nY, int nWidth, int nHeight) 00017 { 00018 this->pos.set(nX, nY); 00019 this->dim.nWidth=nWidth; 00020 this->dim.nHeight=nHeight; 00021 } 00022 00023 void Paddle::checkBoundary(Rectangle rBoundary) 00024 { 00025 if(pos.getX()<rBoundary.getX1()) 00026 pos.setX(rBoundary.getX1()); 00027 if(pos.getX()+dim.nWidth>rBoundary.getX2()) 00028 pos.setX(rBoundary.getX2()-dim.nWidth); 00029 } 00030 00031 bool Paddle::hasChanged() 00032 { 00033 return(pos.hasChanged()); 00034 } 00035 00036 void Paddle::move(Vector vDiff) 00037 { 00038 this->pos.move(vDiff); 00039 /* 00040 char szBuffer[256]; 00041 sprintf(szBuffer, "p:%d,%d ", pos.getX(), pos.getY()); 00042 this->pDisp->drawString(font_oem, 0, 0, szBuffer); 00043 */ 00044 00045 } 00046 00047 00048 void Paddle::clearPrev() 00049 { 00050 Point p=pos.getPrev(); 00051 this->pDisp->fillRect(p.getX(), p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Black); 00052 } 00053 00054 void Paddle::clear() 00055 { 00056 Point p=pos.getCur(); 00057 this->pDisp->fillRect(p.getX(), p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Black); 00058 } 00059 00060 void Paddle::draw() 00061 { 00062 Point p=pos.getCur(); 00063 this->pDisp->drawLine(p.getX(), p.getY()+dim.nHeight, p.getX()+dim.nWidth/3, p.getY(), Color565::Blue); 00064 this->pDisp->fillRect(p.getX()+dim.nWidth/3, p.getY(), p.getX()+dim.nWidth/3+dim.nWidth/3, p.getY()+dim.nHeight, Color565::Blue); 00065 this->pDisp->drawLine(p.getX()+dim.nWidth/3+dim.nWidth/3, p.getY(), p.getX()+dim.nWidth, p.getY()+dim.nHeight, Color565::Blue); 00066 } 00067 00068 void Paddle::redraw(bool fForceDraw) // fForceDraw=false 00069 { // redraw the paddle if its position has changed 00070 00071 if(pos.hasChanged() || fForceDraw) 00072 { 00073 Point pPrev=pos.getPrev(); 00074 Point pCur=pos.getCur(); 00075 clearPrev(); 00076 draw(); 00077 } 00078 }
Generated on Thu Jul 14 2022 10:55:45 by
1.7.2