# Check collision

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 05-12-2007
Queatrix
>> Why?

I was just going by past experiences mixed with exaggeration.
• 05-12-2007
Livijn
• 05-12-2007
Livijn
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 ); }```
• 05-12-2007
Salem
> 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?
• 05-13-2007
Livijn
Code:

```//Random number int GetRand(int min, int max) {   static int Init = 0;   int rc;     if (Init == 0)   {     srand(time(NULL));     Init = 1;   }     rc = (rand() &#37; (max - min + 1) + min);     return (rc); }```
Sorry ;)
• 05-13-2007
Salem

But that wasn't the question.

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 );```
Sometimes you get the old value, sometimes the new one.
Now where does the old value come from?
• 05-13-2007
Livijn
Outside the if i got int n = sXl; you can see that earlier in my post. 2 post before this!
• 05-13-2007
Livijn
Hmmmm... This is no bump!
• 05-13-2007
Queatrix
That is you'r 6th time!
• 05-13-2007
Salem
Well I've had enough of this bumping.
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12