Hi, I have a problem with my small projects. I'm trying to create a small breakout game, but I can't figure how to manage the direction of my ball.
My problem is, when the ball reach an Edge, I want it to keep going on with the correct angle. For example, if the ball reach the right edge of the world with an angle of 135° (coordinate system of Greenfoot), i want it to continue with an angle of 225°.
I tryied different ways, for example :
I think my way of defining the edges is wrong, and my calculus method is also wrong.
Thanks for the help guys !

if ( atWorldEdge() ) { if(getX() < (getWorld().getWidth() + 5)) //If ball is at left edge { if (getRotation() <= 90) { setRotation(270 + getRotation() ); } if (getRotation() >= 270) { setRotation(getRotation() - 270 ); } } if(getX() > (getWorld().getWidth() - 5)) //if ball is at right edge { if (getRotation() <= 180) { setRotation(90 + getRotation() ); } if (getRotation() >= 180) { setRotation(getRotation() - 90 ); } } if(getY() > (getWorld().getHeight() - 5)) //if ball is at top edge { if (getRotation() <= 90) { setRotation(90 + getRotation() ); } if (getRotation() >= 270) { setRotation(getRotation() + 90 ); } } if(getY() < (getWorld().getHeight() + 5)) // if ball is at bottom edge { Greenfoot.stop(); } }