I am trying to create the while lives > 0 && bricks > 0 loop but either the ball doesn't bounce off the right wall or the paddle doesn't follow the mouse. My code is below. Please help been stuck on this for hours and any other tips on my code are always appreciated.
// keep playing until game over
while (lives > 0 && bricks > 0)
{
// check for mouse event
GEvent event = getNextEvent(MOUSE_EVENT);
// if we heard one
if (event != NULL)
{
// if the event was movement
if (getEventType(event) == MOUSE_MOVED)
{
// ensure circle follows top cursor
double x = getX(event);
setLocation(paddle, x, 535);
}
}
// initial velocity
double velocity = 2.0;
// bounce forever
// move circle along x-axis
move(ball, velocity, 0);
// bounce off right edge of window
if (getX(ball) + getWidth(ball) >= WIDTH)
{
velocity = -velocity;
}
// bounce off left edge of window
else if (getX(ball) <= 0)
{
velocity = -velocity;
}
// linger before moving again
pause(10);
}