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.
Dependencies: 4DGL-uLCD-SE PinDetect mbed SparkfunAnalogJoystick mbed-rtos
Fork of ECE2036Lab2StarterCode by
paddle.cpp
00001 #include "paddle.h" 00002 00003 Paddle::Paddle(uint8_t initx, uint8_t inity, uint8_t olength, uint8_t owidth){ 00004 x = initx; 00005 y = inity; 00006 length = olength; 00007 width = owidth; 00008 if (y < 100) { 00009 bottom = false; 00010 } 00011 else { 00012 bottom = true; 00013 } 00014 } 00015 00016 void Paddle::setLimits(uint8_t left, uint8_t right){ 00017 leftLim = left; 00018 rightLim = right; 00019 } 00020 00021 void Paddle::setMaxMove(uint8_t amt){ 00022 maxMove = amt; 00023 } 00024 00025 uint8_t Paddle::getX(){ 00026 return x; 00027 } 00028 00029 void Paddle::setX(uint8_t newx){ 00030 x = newx; 00031 } 00032 00033 void Paddle::move(float amt){ 00034 if (x + amt*maxMove + length > rightLim) 00035 x = rightLim - length; 00036 else if (x + amt*maxMove < leftLim) 00037 x = leftLim; 00038 else 00039 x = x + amt*maxMove; 00040 } 00041 00042 bool Paddle::checkHit(uint8_t ballX, uint8_t ballY, uint8_t size){ 00043 if (ballX+size/2 >= x && ballX+size/2 <= x+length){ 00044 if (bottom && (ballY+size >= y-width && ballY <= y-width)){ 00045 return true; 00046 } 00047 else if (!bottom && (ballY+size >= y+width && ballY <= y+width)){ 00048 return true; 00049 } 00050 } 00051 return false; 00052 } 00053 00054 double Paddle::returnAngle(double ballX, double size){ 00055 return abs((ballX + size/2) - (x + length/2)) / 35.0 * sqrt(5.0); 00056 } 00057 00058 bool Paddle::returnDir(uint8_t ballX, uint8_t size){ 00059 if ((ballX+size/2) > (x+length/2)){ 00060 return true; 00061 } 00062 else { 00063 return false; 00064 } 00065 } 00066 00067 void Paddle::reset(uint8_t initx, uint8_t inity){ 00068 x = initx; 00069 y = inity; 00070 }
Generated on Fri Jul 15 2022 08:13:00 by
