I initially instantiated the ball in the center of the window using the initBall function. However after I implemented the code to move the ball randomly across the window, it doesn't begin its motion from the center of the window each time I begin the game like it does in the staff's solution. Could it be a problem my code for the ball's random motion?
double velocityX = drand48() * 5;
double velocityY = 2.0;
while(lives > 0 && bricks > 0)
{
move(ball, velocityX, velcityY)
if (ball touches left or right edge of window)
velocityX = -velocityX;
if (ball touches top or bottom edge of window)
velocityY = -velocityY;
pause(10)
}
GOval initBall (Gwindow window)
{
Goval ball = newGOval(0,0, 2*RADIUS, 2*RADIUS)
setColour (ball, "RED");
setFilled (ball, true);
add(window,ball);
double x = (getWidth(window) - getWidth(ball)) / 2;
double y = (getHeight(window) - getHeight(ball)) / 2;
setLocation(ball,x,y);
return ball;
}