When I add pause(5) to the while loop, pause function makes the ball not zip around, it also seems to slow down the paddle responsiveness. What do I have to do to get around that? I do understand why this happens, but still, can not solve this
while (lives >= 0 && bricks > 0) { GEvent event = getNextEvent(MOUSE_EVENT);
if (event != NULL)
{
if (getEventType(event) == MOUSE_MOVED)
{
double x = getX(event);
if (x + paddle_width >= WIDTH)
x = WIDTH - paddle_width;
setLocation(paddle, x, height_position);
}
}
move(ball, velocityX, velocityY);
if (getX(ball) + getWidth(ball) >= getWidth(window))
{
velocityX = -velocityX;
}
else if (getX(ball) <= 0)
{
velocityX = -velocityX;
}
else if (getY(ball) <= 0)
{
velocityY = -velocityY;
}
else if (getY(ball) + getWidth(ball) >= getHeight(window))
{
lives--;
setLocation(ball, (WIDTH / 2) - (RADIUS / 2), (HEIGHT / 2) - (RADIUS / 2));
waitForClick();
}
GObject object = detectCollision(window, ball);
if (object != NULL)
{
if (object == paddle)
{
velocityY = -velocityY;
}
else if (strcmp(getType(object), "GRect") == 0)
{
removeGWindow(window, object);
bricks = bricks - 1;
points++;
updateScoreboard(window, label, points);
velocityY = -velocityY;
}
}
pause(5);
}
waitForClick();
closeGWindow(window);
printf ("Your score is %d\n", score);
return 0;
}
Has someone faced with this trouble?
Any advice will be helpful ;)