I need help: I'm crafting a project with some friends and I'm having difficulty with the random move of the pong ball, I've moved it using the width and length of the world, so the turn and the turn can not be used, whoever can help of a touch there that I share the code for better understanding.
Note: Initial random motion only, after the score changes the behavior of the ball.
public void changeDirection(){
Pong pong = (Pong)getOneIntersectingObject(Pong.class);
Pong2 pong2 = (Pong2)getOneIntersectingObject(Pong2.class);
if(getX()>=getWorld().getWidth() - 5){
hDirection*=-1;
}
if(getY()>=getWorld().getHeight() - 5){
vDirection*=-1;
}
if(getX() <= 5){
hDirection*=-1;
}
if(getY() <= 5){
vDirection*=-1;
}
if(getY() <= 30 && isTouching(BarraLateral.class)){
vDirection*=-1;
}
if(getY() <= 367 && isTouching(BarraLateral2.class)){
vDirection*=-1;
}
if((getX() <= 60) && pong != null){
hDirection*= -1;
}
if((getY() <= 650) && pong2 != null){
hDirection*= - 1;
}
}

