Results 1 to 11 of 11

Thread: Collision Detection?

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2002
    Location
    washington state
    Posts
    12

    Angry Collision Detection?

    Hi, I'm pretty new to programming games in visual basic, I'm primarly used to internet and misc. programming. My question is simple enough, How do u detect when to images hit? Like imgLion and imgTiger? Some help here would greatly appreciated, thanx!!

  2. #2
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    VB Code:
    1. If (imgLion.left+imgLion.width>imgTiger.left) And (imgLion.top+imgLion.height>imgTiger.top) Then
    2.     If (imgLion.left<imgTiger.left+imgTiger.width) And (imgLion.top<imgTiger.top+imgTiger.height) Then
    3.         'Collision!
    4.     End if
    5. End If

  3. #3
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    As in fox's code there, you basically just check when the dimensions of one box overlap the dimensions of another
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  4. #4
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Once you get more serious into game programming you can use the IntersectRect API to check if two RECT structs are colliding
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  5. #5
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    Once you get more serious into game programming you might want to use a map to do the collisions or (depending on the game) collision circles...

  6. #6
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Or fun pixel (mask) collision
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  7. #7
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    yay ^^ or the method I mentioned months ago.. each object has collision points AND a collision rect. and you check collision by intersecting the points of object1 with the rect (or a mask) of object2. This would allow nearly pixel-based collision but you only have to check 5-6 points per object.

  8. #8
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    Yes, that is a good idea
    There are some tricks to increase the speed.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  9. #9
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    I'm well-known for my good ideas

  10. #10
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    I'm well known for my bad ones, hehe
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  11. #11
    Frenzied Member Zaei's Avatar
    Join Date
    Jul 2002
    Location
    My own little world...
    Posts
    1,710
    Originally posted by Sastraxi
    I'm well known for my bad ones, hehe
    I wouldnt say that =).

    Z.

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