Solved

VB5: Collision Detection

Posted on 2000-05-08
9
278 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
  • 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
 
LVL 9

Accepted Solution

by:
Ruchi earned 161 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

912 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now