| samqweqwe (18) | |
|
hello, I am currently making pong using visual C++ with the SDL libary. I find that the ball moves too fast for the players and needs to slow down. The code for the movement is in a while loop and vairies speeds 1 - 2 (X and Y). CODE: //ball movement{ ballX += speedX; ballY += speedY; //} ballX and ballY is the position of the bsll. speedX and speedY are the speeds. these change from 1 - 2 i am wondering if anyone could say how to make the ball move less than one pixel or something along those lines. ask if u need more code to help thanks in advance :) | |
|
Last edited on
|
|
| pogrady (525) | |
|
There are a coupe of ways to do this. One is to change the speed from an int value to a float value and use a smaller increment value. the other is to slow the speed of the game down, since the ball moves at the speed of the loop. its usually a good idea to never change the speed of the game. | |
|
|
|
| maeriden (341) | |
| Using floats for speed and position is the way to go. Then use a rounding function whenever you need to get the position as an int, e.g. when blitting | |
|
|
|
| samqweqwe (18) | |
| thanks | |
|
Last edited on
|
|
| samqweqwe (18) | |
|
does any1 no how to set up the SDL_ttf libary. im trying to add scores and text onto the game but i cant seem to set up the libary. | |
|
|
|
| Peter87 (3917) | |
|
Have you tried follow the instructions in the lazyfoo tutorials? http://www.lazyfoo.net/SDL_tutorials/lesson07/index.php | |
|
|
|
| samqweqwe (18) | |
|
thanks | |
|
|
|
| samqweqwe (18) | |
|
here yet anouther problem, turning everything into float means that i cannot use the random function. i tried changing all the integers to floats on the random function but it didnt work is there a way to make a random float? CODE: float random (float max, float min) { if (max + min == 0) { return 0; } float randomNumber = rand() % max + min; return randomNumber; } on the value max it says it must be an integer or enum type | |
|
Last edited on
|
|
| samqweqwe (18) | |
|
done it float randomNumber = min + (float)rand()/((float)RAND_MAX/(max-min)); | |
|
|
|