Solved

VB5: Collision Detection

Posted on 2000-05-08
9
277 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

10 Experts available now in Live!

Get 1:1 Help Now