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 SparkfunAnalogJoystick mbed-rtos mbed SDFileSystem
Fork of 4180FinalLab by
Diff: paddle.cpp
- Revision:
- 3:591086e44bf9
- Child:
- 4:7da18e3c590b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/paddle.cpp Sun Apr 24 01:23:28 2016 +0000
@@ -0,0 +1,69 @@
+#include "paddle.h"
+
+Paddle::Paddle(uint8_t initx, uint8_t inity, uint8_t olength, uint8_t owidth){
+ x = initx;
+ y = inity;
+ length = length;
+ width = width;
+ if (y < 100){
+ bottom = false;
+ }
+ else {
+ bottom = true;
+ }
+}
+
+void Paddle::setLimits(uint8_t left, uint8_t right){
+ leftLim = left;
+ rightLim = right;
+}
+
+void Paddle::setMaxMove(uint8_t amt){
+ maxMove = amt;
+}
+
+uint8_t Paddle::getX(){
+ return x;
+}
+
+void Paddle::setX(uint8_t newx){
+ x = newx;
+}
+
+void Paddle::move(float amt){
+ if (x + amt*maxMove + length > rightLim)
+ x = rightLim - length;
+ else if (x + amt*maxMove < leftLim)
+ x = leftLim;
+ else
+ x = x + amt*maxMove;
+}
+
+bool Paddle::checkHit(uint8_t ballX, uint8_t ballY, uint8_t size){
+ if (ballX+size/2 >= x && ballX+size/2 <= x+length){
+ if (bottom && (ballY+size >= y && ballY <= y+width)){
+ return true;
+ }
+ else if (!bottom && (ballY <= y+width && ballY+size >= y)){
+ return true;
+ }
+ }
+ return false;
+}
+
+uint8_t Paddle::returnAngle(uint8_t ballX, uint8_t size){
+ return abs((ballX+size/2 - (x + length/2)));
+}
+
+bool Paddle::returnDir(uint8_t ballX, uint8_t size){
+ if (ballX+size/2 > (x+length/2)){
+ return true;
+ }
+ else
+ return false;
+}
+
+void Paddle::reset(uint8_t initx, uint8_t inity){
+ x = initx;
+ y = inity;
+}
\ No newline at end of file
