hello,
been a while. hope your all doing well.
i have some code in java, i have to make some balls bounce around a room. i can get them to bounce from the bottom and right hand sides but not the top and left hand sides.
I am a little unsure about how this works. I have studied python and got on well with it but java is not clicking with me.
any help or advice would be great!
thanks
simon
been a while. hope your all doing well.
i have some code in java, i have to make some balls bounce around a room. i can get them to bounce from the bottom and right hand sides but not the top and left hand sides.
Java:
/**
* Move this object according to its position and speed and redraw.
**/
public void move()
{
// compute new position
yPosition += ySpeed;
xPosition += xSpeed;
// check if it has hit the ground
if(yPosition >= (groundPosition - diameter) && ySpeed > 0) {
yPosition = groundPosition - diameter;
ySpeed = -ySpeed;
}
if(xPosition >= (universe.getRightEdge() - diameter) && xSpeed > 0) {
xPosition = universe.getRightEdge() - diameter;
xSpeed = -xSpeed;
}
// draw again at new position
universe.draw(this);
}
any help or advice would be great!
thanks
simon
Last edited by a moderator: