>> Why?
I was just going by past experiences mixed with exaggeration.
>> Why?
I was just going by past experiences mixed with exaggeration.
Ok, but now back to topic!
Grrrrrr! Im getting angry! Why aint this working... I only won't 1 random number...
Code://Check if there is a collision int check_coll( int sX, int sY, int pX, int pY ) { //Square's position int sXl = sX; int sXr = sX + 29; int sYl = sY; int sYr = sY + 29; //Piece's position int pXl = pX; int pXr = pX + 75; int pYl = pY; int pYr = pY + 148; //Check if you hit the square int n = sXl; if (sXl == pXr || sXr == pXl) { //New position for the square n = GetRand(0, 640); SDL_FillRect( screen, NULL, SDL_MapRGB(screen->format, 0x00, 0x00, 0x00) ); apply_surface( 0, 0, background, screen ); piece = load_image( "piece.png" ); apply_surface( pXl, pYl, piece, screen ); } //Apply the square apply_surface( n, sYl, square, screen ); }
> n = GetRand(0, 640);
If the condition is not met to set the value of n here
> apply_surface( n, sYl, square, screen );
What value of n gets used here?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
SorryCode://Random number int GetRand(int min, int max) { static int Init = 0; int rc; if (Init == 0) { srand(time(NULL)); Init = 1; } rc = (rand() % (max - min + 1) + min); return (rc); }
You posted that already in an earlier thread.
But that wasn't the question.
Sometimes you get the old value, sometimes the new one.Code:/* what value is 'n' here? */ if (sXl == pXr || sXr == pXl) { //New position for the square n = GetRand(0, 640); SDL_FillRect( screen, NULL, SDL_MapRGB(screen->format, 0x00, 0x00, 0x00) ); apply_surface( 0, 0, background, screen ); piece = load_image( "piece.png" ); apply_surface( pXl, pYl, piece, screen ); } //Apply the square apply_surface( n, sYl, square, screen );
Now where does the old value come from?
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Outside the if i got int n = sXl; you can see that earlier in my post. 2 post before this!
Hmmmm... This is no bump!
Last edited by Livijn; 05-13-2007 at 08:51 AM.
That is you'r 6th time!
Last edited by Queatrix; 05-13-2007 at 09:01 AM.
Well I've had enough of this bumping.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.