?
Solved

VB5: Collision Detection

Posted on 2000-05-08
9
Medium Priority
?
290 Views
Last Modified: 2010-05-02
I'm running into problems with my collision detection in a game I'm working on.  Basically I need some good example source showing how to do collision detection between 2 complex objects by the pixel.  No generic boxes or circles...by the pixel using images.  Simple example, 2 guys swinging swords at each other.  You need collision detection down to the pixel to know when the swords hit each other, when they hit the guy, and when they miss.
So advanced input and some source code would be helpfull.
0
Comment
Question by:ChrisK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 2788254
Maybe you need to create a table in advanced based on the X-Y displacement of one figure relative to another.  e.g. (10,5) might be a hit (10,6) a miss.  Values outside the range of the table would be a miss.  

It could also hold info about what picture to display to depict the hit, e.g hit on head or body.
0
 
LVL 32

Expert Comment

by:Erick37
ID: 2788438
Here's a thought.  Create regions which are the outlines of your pictures, then you can determine if they intersect by calling the CombineRgn API call:

If NULLREGION = CombineRgn(hrgnDst, hRgn1, hRgn2, RGN_AND) Then
    'They do not intersect
End If

This site shows how to create regions from bitmaps:

"Creating Window Shapes from Bitmaps"
http://vbaccelerator.com/codelib/winstyle/bmpwinsh.htm
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2788758
example here towards the bottom of the page:

http://www.coderoom.com/pages/graphics/graphics17.htm


same site, dont know if its a different sample or not:

http://www.coderoom.com/pages/graphics/graphics2.htm
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Accepted Solution

by:
Ruchi earned 644 total points
ID: 2789337
"If you want to write any games that require collision detection, this excellent sample shows you how to do pixel collision detection in VB5 or greater."
http://www.zarr.net/vb/download/download.asp?id=47

"This example demonstrates how to performs accurate pixel collision detection. "
http://www.extreme-vb.net/upload/Collision.zip
0
 
LVL 2

Author Comment

by:ChrisK
ID: 2790457
All of these are excellent examples.  But there's still 1 problem with them all.  Ruchi's for example shows pixel collision but requires masks of both objects to do it.  I may be able to structure the game code to make this work...but here's the catch.  Take my sword fighting example.  How could I tell the difference between the pixels of the swords colliding, and the pixels of the sword hitting the guy?  If the sword was a seperate object from the guy, it wouldn't be too tough, but they are all the same image...any suggestions?
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 2790466
is there a distinct color difference such that you can use the rgb value of the pixel to distinguish between the two?
0
 
LVL 2

Author Comment

by:ChrisK
ID: 2790490
Nope...that wouldn't work because there will be a large variety of weapons and such which would have the same color values.  I think I solved my own problem really...I just need to make the weapons a seperate object that gets drawn either before or after the character, depending on the angle.  Then I could map the characters body coordinates to 1 variable, and the coordinates of the weapon image to another.
0
 
LVL 9

Expert Comment

by:Ruchi
ID: 2790971
Go to
http://www.planetsourcecode.com/vb
Type collision detection in the text box for searching.
You should be able to get 8 entries. Hope they are helpful to you.
0
 
LVL 2

Author Comment

by:ChrisK
ID: 2794939
Several of you had good examples, but ruchi's seems to be the best for what I need.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month8 days, 22 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question