0

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 ;)

1 Answer 1

0

Simply put, the pause is slowing the entire program down. It's like you're hitting the pause button every time that line of code executes. If you want to slow the ball down without affecting anything else, you need to alter the ball's velocity. It's that simple.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .