player 1
Dependencies: 4DGL-uLCD-SE PinDetect SparkfunAnalogJoystick mbed-rtos mbed SDFileSystem
Fork of 4180FinalLab by
Wireless 2 Player Pong game
paddle.cpp
- Committer:
- Mpmart08
- Date:
- 2016-04-26
- Revision:
- 4:7da18e3c590b
- Parent:
- 3:591086e44bf9
- Child:
- 8:8cc2aa78348c
File content as of revision 4:7da18e3c590b:
#include "paddle.h" Paddle::Paddle(uint8_t initx, uint8_t inity, uint8_t olength, uint8_t owidth){ x = initx; y = inity; length = olength; width = owidth; 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-width && ballY <= y-width)){ return true; } else if (!bottom && (ballY+size >= y+width && ballY <= y+width)){ return true; } } return false; } double Paddle::returnAngle(double ballX, double size){ return abs((ballX + size/2) - (x + length/2)) / 35.0 * sqrt(5.0); } 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; }