I'm making a pong game for an assignment in class and what I'm trying to do is when my ball starts, i want it's direction of my ball to be change randomly every time i press space-bar. some reason its keeps generating the same value over and over.
here's my code:
if ((BallXspeed == 0) && (BallYspeed == 0))
{
//restarts ball
if(IsKeyDown(' '))
{
srand ( time(NULL) );
iRandX = (((rand() % 200) / 200 ) * 2) - 1;
iRandY = (((rand() % 200) / 200 ) * 2) - 1;
BallXspeed = 3 * iRandX;
BallYspeed = 3 * iRandY;
}
}
hope i can get some help soon.
thanks.
here's my code:
if ((BallXspeed == 0) && (BallYspeed == 0))
{
//restarts ball
if(IsKeyDown(' '))
{
srand ( time(NULL) );
iRandX = (((rand() % 200) / 200 ) * 2) - 1;
iRandY = (((rand() % 200) / 200 ) * 2) - 1;
BallXspeed = 3 * iRandX;
BallYspeed = 3 * iRandY;
}
}
hope i can get some help soon.
thanks.