I've created the small program where the ball is moving all the time on the screen to random coordinates made like that:
[source lang="cpp"]srand(time(NULL));
do
{
ballX = randx;
ballY = randy;
}while(abs(oldx-ballX) > 300 && abs(oldy-ballY) > 300);
oldx = ballX;
oldy = ballY;[/source]
It's included in while(!gameover) function. That moves the ball:
[source lang="cpp"]void moveBall()
{
if(ballposition.x > ballX)
{
ballposition.x -= ballspeed;
}
if(ballposition.x < ballX)
{
ballposition.x += ballspeed;
}
if(ballposition.y > ballY)
{
ballposition.y -= ballspeed;
}
if(ballposition.y < ballY)
{
ballposition.y += ballspeed;
}
}[/source]
The only problem is that the ball is moving to the right coordinates X and Y, then sometimes stays for a moment and then another move and so on. When I try to delete the "srand(time(NULL));" it causes the ball to move really fast in each direction but no lag. How can I fix this?