How do I let reflection angles change depending on the part of the paddle that is hit?
angle of entrance = angle of reflection becomes boring pretty quickly...
public void bounce()
{
if (isTouching(Players.class))
{
BALL_SPEED = BALL_SPEED * -1;
Actor PlayerRight = getOneIntersectingObject(PlayerRight.class);
int PlayerRightY;
int PlayerRightX;
PlayerRightX = PlayerRight.getX();
PlayerRightY = PlayerRight.getY();
Actor PlayerLeft = getOneIntersectingObject(PlayerLeft.class);
int PlayerLeftY;
int PlayerLeftX;
PlayerLeftY = PlayerLeft.getY();
PlayerLeftX = PlayerLeft.getX();
if (getY() - PlayerRightY >= 0 && getX() - PlayerRightX <= 1)
{
setRotation(360 - getRotation() - 20);
}
if (getY() - PlayerRightY <= 0 && getX() - PlayerRightX <= 1)
{
setRotation(360 - getRotation() + 20);
}
if (getY() - PlayerLeftY >= 0 && PlayerLeftX - getX() <= 1)
{
setRotation(360 - getRotation() + 20);
}
if (getY() - PlayerLeftY <= 0 && PlayerLeftX - getX() <= 1)
{
setRotation(360 - getRotation() - 20);
}
}
if (isAtUpperEdge() || isAtLowerEdge())
{
BALL_SPEED = BALL_SPEED * -1;
setRotation(360 - (getRotation() - 180));
}
} public void bounce()
{
if (isTouching(Players.class))
{
BALL_SPEED = BALL_SPEED * -1;
/*Actor PlayerRight = getOneIntersectingObject(PlayerRight.class);
int PlayerRightY;
int PlayerRightX;
PlayerRightX = PlayerRight.getX();
PlayerRightY = PlayerRight.getY();*/
Actor PlayerLeft = getOneIntersectingObject(PlayerLeft.class);
int PlayerLeftY;
int PlayerLeftX;
PlayerLeftY = PlayerLeft.getY();
PlayerLeftX = PlayerLeft.getX();
/*if (getY() - PlayerRightY >= 0 && getX() - PlayerRightX <= 1)
{
setRotation(360 - getRotation() - 20);
}
if (getY() - PlayerRightY <= 0 && getX() - PlayerRightX <= 1)
{
setRotation(360 - getRotation() + 20);
}*/
if (getY() - PlayerLeftY >= 0 && PlayerLeftX - getX() <= 1)
{
setRotation(360 - getRotation() + 20);
}
if (getY() - PlayerLeftY <= 0 && PlayerLeftX - getX() <= 1)
{
setRotation(360 - getRotation() - 20);
}
}
if (isAtUpperEdge() || isAtLowerEdge())
{
BALL_SPEED = BALL_SPEED * -1;
setRotation(360 - (getRotation() - 180));
}
}if (isTouching(Player.class))
{
Actor player = getOneIntersectingObject(Player.class);
int height = player.getImage().getHeight();
int yOffset = player.getY()-getY();
setRotation(20*yOffset/height-getRotation());
}int yOffset = getY()-player.getY();
int yOffset = (getY()-player.getY())*(int)Math.signum(getX()-player.getX());