![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Two player imu pong
Dependencies: 4DGL-uLCD-SE IMUfilter LSM9DS0 PinDetect mbed
ball.cpp
- Committer:
- rrr93
- Date:
- 2015-10-22
- Revision:
- 0:941225f01ccc
File content as of revision 0:941225f01ccc:
#include "ball.h" //#include "tempModule.h" Ball::Ball(PinName pin) { //tempSensor = new TempModule(pin); setBaseVx(2.0); setBaseVy(2.0); setVySign(1); setVxSign(1); radius = 5; setX(50); setY(21); } Ball::Ball(PinName pin, float Vx, float Vy, int rad,int xp, int yp) { //tempSensor = new TempModule(pin , Vx, Vy); setBaseVx(Vx); setBaseVy(Vy); setVxSign(1); setVySign(1); radius = rad; setX(xp); setY(yp); } // set functions void Ball::setX(int xp) { x = xp; } void Ball::setY(int yp) { y = yp; } void Ball::setRand(int seed) { srand(seed); int random = (rand() % (118 - 2*radius)) + radius; setX(random); int random2 = (rand() % (127 - 2*radius)) + radius; setY(random2); } void Ball::setBaseVx(float Vx) { basevx = Vx; //tempSensor->setBaseVx(vxSign*Vx); } void Ball::setBaseVy(float Vy) { basevy = Vy; //tempSensor->setBaseVy(Vy); } void Ball::setVxSign(int s) { vxSign = s; } void Ball::setVySign(int s) { vySign = s; } //get functions int Ball::getVx() { return basevx; } int Ball::getVy() { return basevy; } int Ball::getFutureX() { return vxSign * getVx() + x ; //return vxSign * tempSensor->getVx() + x ; } int Ball::getFutureY() { return vySign * getVy() + y; //return vySign * tempSensor->getVy() + y; } int Ball::getRadius() { return radius; } //Member Functions void Ball::reverseXDirection() { vxSign = - vxSign; } void Ball::reverseYDirection() { vySign = -vySign; } /* void Ball::reset( int x, int y, int vx, int vy, uLCD_4DGL*) { setBaseVx(vx); setBaseVy(vy); uLCD.circle(x,y,radius,WHITE); } */ void Ball::update(uLCD_4DGL *uLCD) { uLCD->circle(x,y,radius,BLACK); x = (int) getFutureX(); y = (int) getFutureY(); uLCD->circle(x,y,radius,WHITE); } /* void Ball::dispTemp(uLCD_4DGL *uLCD) { float garbage = tempSensor->getVx(uLCD); } */ bool Ball::CheckHit() { bool hit = false; /* if ((getFutureX()<=radius+1)) { reverseXDirection(); hit = true; } */ if ((getFutureY()<=radius+1) || (getFutureY()>=126-radius)) { reverseYDirection(); hit = true; } return hit; } bool Ball::CheckLose() { if ((getFutureX()>=126-radius)) { //vx = 0; //vy = 0; return true; } if ((getFutureX() <= radius)) { return true; } else {return false;} }