Elements used in the Balls and Things games for the RETRO.
Dependents: RETRO_BallsAndPaddle RETRO_BallAndHoles
Diff: Ball.cpp
- Revision:
- 2:74bc9b16fb88
- Parent:
- 0:3d0db4e183ee
- Child:
- 3:441dc90d10ce
--- a/Ball.cpp Fri Feb 06 10:18:02 2015 +0000 +++ b/Ball.cpp Wed Feb 25 10:43:15 2015 +0000 @@ -91,9 +91,37 @@ this->unmove(); // undo move to pre-bouncing position to avoid drawing on colliding position this->vSpeed.multiply(vBounce); + //this->vSpeed.bounce(vBounce); // check speed w/max if(this->vSpeed.y>5.0) this->vSpeed.y=5; + if(this->vSpeed.x>5.0) this->vSpeed.x=5; + if(this->vSpeed.y<-5.0) this->vSpeed.y=-5; + if(this->vSpeed.x<-5.0) this->vSpeed.x=-5; +} + +void Ball::BounceAgainst(Vector vBounce) +{ // change the direction in a certain direction + this->unmove(); // undo move to pre-bouncing position to avoid drawing on colliding position + + //this->vSpeed.multiply(vBounce); + this->vSpeed.bounce(vBounce); + + // check speed w/max + if(this->vSpeed.y>5.0) this->vSpeed.y=5; + if(this->vSpeed.x>5.0) this->vSpeed.x=5; + if(this->vSpeed.y<-5.0) this->vSpeed.y=-5; + if(this->vSpeed.x<-5.0) this->vSpeed.x=-5; + + if(abs(vSpeed.x)>abs(vSpeed.y)) + vSpeed.x=vSpeed.x/abs(vSpeed.x) * abs(vSpeed.y); + +/* + if(this->vSpeed.y>0 && this->vSpeed.y<1.0) this->vSpeed.y=1; + if(this->vSpeed.x>0 && this->vSpeed.x<1.0) this->vSpeed.x=1; + if(this->vSpeed.y<0 && this->vSpeed.y>-1.0) this->vSpeed.y=-1; + if(this->vSpeed.x<0 && this->vSpeed.x>-1.0) this->vSpeed.x=-1; +*/ }