message
This commit is contained in:
parent
1a18e469ca
commit
af40f082d6
@ -142,8 +142,27 @@ public class Ball implements IBall {
|
|||||||
* @param paddle hitbox mechanism of paddle
|
* @param paddle hitbox mechanism of paddle
|
||||||
* @todo implementation
|
* @todo implementation
|
||||||
*/
|
*/
|
||||||
public void reflectOnPaddle(Paddle paddle) {
|
public void reflectOnPaddle(Paddle p) {
|
||||||
return;
|
// get the Position of the middle of the paddle
|
||||||
|
Position newOffset = new Position(
|
||||||
|
p.getPosition().getX() + p.getWidth() / 2.0,//the middle of the x coordinates
|
||||||
|
p.getPosition().getY() + p.getHeight() / 2.0);//the middle of the y coordinates
|
||||||
|
//deciding if the paddle is at the top or bottom to adjust if its +or- y direction
|
||||||
|
if (p.getPosition().getY() == 0) {
|
||||||
|
newOffset.setY(newOffset.getY() - Constants.REFLECTION_OFFSET);// paddle at the top with negative direction
|
||||||
|
} else {
|
||||||
|
newOffset.setY(newOffset.getY() + Constants.REFLECTION_OFFSET); // the paddle at the bottom with positive direction
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculating the center of the ball by dividing by zero
|
||||||
|
Position ballCenter = new Position(
|
||||||
|
position.getX() + Constants.BALL_DIAMETER/2.0, //the middle of the x coordinates
|
||||||
|
position.getY() + Constants.BALL_DIAMETER/2.0); //the middle of the y coordinates
|
||||||
|
|
||||||
|
// The direction is set to the middle of the offset point and the ball
|
||||||
|
direction = new Vector2D(newOffset, ballCenter);
|
||||||
|
// rescaling to adjust the balls speed
|
||||||
|
direction.rescale();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user