From another forum , I found code for bouncing off walls at an equal and opposite angle, however, the code is incomplete and I cannot work it out for the top and left walls. this is what I have:
Please help and thanks in advance.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | public void bounceoffwall() { if (isAtEdge()) { if (getY() == 0 || getY() == getWorld().getHeight()- 1 ) /**bottom*/ { setRotation( 360 -getRotation()); } if (getX()== 0 || getX() == getWorld().getWidth()- 1 ) /**right*/ { setRotation( 180 -getRotation()); } if (getY() == 0 ) /**top*/ { setRotation( int -getRotation()); } if (getX() == 0 ) /**left*/ { setRotation( int -getRotation()); } //left edge: getX() == 0 //right edge: getX() == getWorld().getWidth()-1 //top edge: getY() == 0 //bottom edge: getY() == getWorld().getHeight()-1 } } |