player 1
Dependencies: 4DGL-uLCD-SE PinDetect SparkfunAnalogJoystick mbed-rtos mbed SDFileSystem
Fork of 4180FinalLab by
Wireless 2 Player Pong game
Diff: ball.cpp
- Revision:
- 3:591086e44bf9
- Child:
- 4:7da18e3c590b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ball.cpp Sun Apr 24 01:23:28 2016 +0000 @@ -0,0 +1,76 @@ +#include "ball.h" + +Ball::Ball(uint8_t initx, uint8_t inity, uint8_t size){ + x = initx; + y = inity; + diameter = size; +} + +void Ball::setVx(uint8_t newvx){ + vx = newvx; +} + +void Ball::setVxDir(bool dir){ + vxDir = dir; +} + +void Ball::setBaseVy(uint8_t baseVy){ + vy = baseVy; +} + +void Ball::setVyDir(bool dir){ + vyDir = dir; +} + +uint8_t Ball::getSize(){ + return diameter; +} + +uint8_t Ball::getX(){ + return x; +} + +uint8_t Ball::getY(){ + return y; +} + +uint8_t Ball::getFutureX(){ + if (vxDir) + return x+vx; + else + return x-vx; +} + +uint8_t Ball::getFutureY(){ + if (vyDir) + return y+vy; + else + return y-vy; +} + +void Ball::reverseXDirection(){ + vxDir = !vxDir; +} + +void Ball::reverseYDirection(){ + vyDir = !vyDir; +} + +void Ball::reset(uint8_t newx, uint8_t newy, int newvx, int newvy){ + x = newx; + y = newy; + vx = newvx; + vy = newvy; +} + +void Ball::update(){ + if (vxDir) + x = x+vx; + else + x = x-vx; + + if (vyDir) + y = y+vy; + else + y = y-vy; +} \ No newline at end of file