1

Well when I coded for the creation of paddle and the movement of the paddle in initpaddle(), it was moving fine but now after step 6 of the problem set. With the ball too moving the paddle is lagging, though the paddle comes to where the mouse is but it seems I am playing a heavy game on an outdated system, the movement of the paddle is slow.

Plus I wanna know how would I use drand48()? Right now I have initialised the horizontal and vertical velocities with a double outside the while loop.

Do I initialize it like this?

double velocityX = drand48();

and sorry I haven't pasted the code for movement of paddle and ball because I am not sure if it's against academic honesty or not.

1 Answer 1

0
  1. Most probably you see this "lagging" because you have a high value inside pause() in your while loop that controls the game. Try something somewhere around 5. You will also have to adjust the speed of the ball through to find a good balance between pause() and the speed that will make your game playable.
  2. You use drand() like you have shown:

    double velocityX = drand48();
    

    but there are some things you should take care of.

    First of all, drand48() return a value in [0, 1), which may be too slow for your game, so you will have to add and/or multiply that value by another value to make it just right. You have to experiment with those values to find the one that is good for your game.

    You should also make sure you use srand48() to give a new seed to drand48() at the beginning of each of your games, so that it doesn't always use the same values for your velocities.

Those should improve the UX of your game. It all boils down to experimenting with the values really.


If this answers your question please accept it by clicking the gray check-mark to the left, so that it becomes green. You can also vote it up by pressing the up arrow above the check-mark. And don't forget to keep coding!

You must log in to answer this question.

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