Thread: Check collision

  1. #16
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    >> Why?

    I was just going by past experiences mixed with exaggeration.

  2. #17
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    Ok, but now back to topic!

  3. #18
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    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 );
    }

  4. #19
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 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.

  5. #20
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    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() % (max - min + 1) + min);
      
      return (rc);
    }
    Sorry

  6. #21
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You posted that already in an earlier thread.

    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?
    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.

  7. #22
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    Outside the if i got int n = sXl; you can see that earlier in my post. 2 post before this!

  8. #23
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    Hmmmm... This is no bump!
    Last edited by Livijn; 05-13-2007 at 08:51 AM.

  9. #24
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    That is you'r 6th time!
    Last edited by Queatrix; 05-13-2007 at 09:01 AM.

  10. #25
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-05-2010, 11:42 PM
  2. MFC check box question
    By MyglyMP2 in forum Windows Programming
    Replies: 2
    Last Post: 03-09-2009, 05:47 PM
  3. Collision Detection
    By Grantyt3 in forum C++ Programming
    Replies: 3
    Last Post: 09-30-2005, 03:21 PM
  4. bounding box collision detection
    By DavidP in forum Game Programming
    Replies: 7
    Last Post: 07-07-2002, 11:43 PM
  5. Collision with quads?
    By SyntaxBubble in forum Game Programming
    Replies: 6
    Last Post: 01-18-2002, 06:17 PM