Solved

VB5: Collision Detection

Posted on 2000-05-08
9
280 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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
 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 …
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…

772 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