Check collision (REAL THREAD)

This is a discussion on Check collision (REAL THREAD) within the C++ Programming forums, part of the General Programming Boards category; Still same problem.. Code: Code: //Check if there is a collision bool check_coll( int sX, int sY, int pX, int ...

  1. #31
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    Still same problem..

    Code:
    Code:
    //Check if there is a collision
    bool 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
        if ((pXr >= sXl && pXr < sXr) || (pXl <= sXr && pXl > sXl) || (sXl >= pXl && sXl <= pXr) || (sXr <= pXr && sXr >= pXl)) 
        {
                 return true;
        }
        else
        {
            return false;
        }
    }
    
    //Move square if there is a collision
    void move_and_show_square( int sX, int sY, int pX, int pY )
    {
         //Variables
         int sXl;
         sXl = 400;
         
         //If there is a collision
         if (check_coll( sX, sY, pX, pY ) == true)
         {
                         //New position for the square
                         sXl = 50;
                         
                         //Make the square move
                         SDL_FillRect( screen, NULL, SDL_MapRGB(screen->format, 0x00, 0x00, 0x00) );
                         apply_surface( 0, 0, background, screen );
                         piece = load_image( "piece.png" ); 
                         apply_surface( pX, pY, piece, screen ); 
         }
         
         //Apply the square
         apply_surface( sXl, 300, square, screen );
    }

  2. #32
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    Only 2 weeks left to my girlfriends anniversary. Please help me out with this one and i'll help you so much i can. PLEASE! I BEG YOU! Actually, i don't wanna do this bump, but i must! I can't dissapoint here, seriously i can't.

  3. #33
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Oh dear

    Code:
    //Move square if there is a collision
    void move_and_show_square( int & sX, int sY, int pX, int pY )
    {
         //Variables
         /*int sXl;
         sXl = 400;*/ //What is that for? Want to change sX to either 400 or 50?
        sX = 400;
         
         //If there is a collision
         if (check_coll( sX, sY, pX, pY ) == true)
         {
                         //New position for the square
                         sX = 50;
                         
                         //Make the square move
                         SDL_FillRect( screen, NULL, SDL_MapRGB(screen->format, 0x00, 0x00, 0x00) );
                         apply_surface( 0, 0, background, screen );
                         piece = load_image( "piece.png" ); //do you remember to unload this? or why you keep loading it
                         apply_surface( pX, pY, piece, screen ); 
         }
         
         //Apply the square
         apply_surface( sX, 300, square, screen );
    }
    These are just guesses. There are global stuff around and magical values, so I can really only guess what this function is meant to achieve.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #34
    Registered User
    Join Date
    Jan 2007
    Posts
    188
    If there aint a collision, i want the square to stay at it's position.

  5. #35
    The larch
    Join Date
    May 2006
    Posts
    3,573
    In that case don't change sX to 400. That's what your original code does.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Messaging Between Threads, Exiting Thread On Demand, Etc.
    By HyperShadow in forum C++ Programming
    Replies: 10
    Last Post: 06-09-2007, 01:04 PM
  2. Collision Detection Problems
    By Dark_Phoenix in forum Game Programming
    Replies: 1
    Last Post: 12-17-2006, 02:25 PM
  3. Thread Synchronization in Win32
    By passionate_guy in forum C Programming
    Replies: 0
    Last Post: 02-06-2006, 04:34 AM
  4. C++ Threading?
    By draggy in forum C++ Programming
    Replies: 5
    Last Post: 08-16-2005, 12:16 PM
  5. collision detection
    By DavidP in forum Game Programming
    Replies: 2
    Last Post: 05-11-2002, 01:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21