Results 1 to 5 of 5

Thread: Collision Detection ref: kedamans solution

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    England
    Posts
    5

    Exclamation

    To my question

    Hi, if I have 2 bouncing squares, bouncing around inside a larger square how do I detect when the squares hit each other? I can get some level of detection using an IF on the top and left properties of the objects but not the whole square can anyone help? I hope this makes sense!

    The follwing solution was offered
    --------------------------------------------------------------------------------
    a=x1t<x2t'top borders
    b=x1b>x2b'bottom borders
    c=x1l<x2l'left borders
    d=x1r>x2r'right borders
    if not((a xor b) or (c xor d) or (a xor c)) then 'collision

    again this works to some degree but it would appear that the borders of the sqaures need to match exactltly for collision to be detected. I wonder if my problem is that I am using picture boxes and properties thereof for my squares - any comments greatfully appreciated
    -------------
    F*R*A*G*O*F*F
    -------------

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    try this:

    Code:
    If pic1.Left + pic1.Width > pic2.Left And pic1.Top + pic1.Height > pic2.Top Then
       If pic1.Left < pic2.Left + pic2.Width And pic1.Top < pic2.Top + pic2.Height Then
          Collision
       End If
    End If

  3. #3
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Code:
    If Abs(Image1.Left - Image2.Left) < Image1.Width And Abs(Image1.Top - Image2.Top) < Image1.Height Then Collision

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2000
    Location
    England
    Posts
    5

    Smile

    Thanks alot for your help. Thanks to you guys I have now cracked the prob and have just about finished a rough pong game! as a novice programmer I cant tell you how much help this has been! At this moment no one in the world is happier than me! Cheers.
    -------------
    F*R*A*G*O*F*F
    -------------

  5. #5
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    I made a pong game using bitblt...I'll send you the source if you want.

    exe : http://www.geocities.com/stephenmack23/pong.zip

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width