|
-
Oct 16th, 2003, 11:22 AM
#1
Thread Starter
Junior Member
Collision Detection.
Anyone have any idea how to do collision detection? I sort of have one right now, but it takes MANY lines of code and is pretty burdensome. Not to mention I can only have PictureBox1 not be able to walk through PictureBox2, yet can still walk through PictureBox3. I don't know any DirectX yet so I'm just trying to make a simple RPG using PictureBoxes and things like that.
I'd likje to be able to make it so that PictureBox1 can't walk through any other pictureboxes, but I don't know how hard that would be. Any help would be highly appreciated.
-
Oct 16th, 2003, 02:39 PM
#2
Fanatic Member
i'm afraid i can't answer your question yet as i haven't read the book but i would suggest it!!!
http://www.amazon.co.uk/exec/obidos/...806050-2959007
-
Oct 17th, 2003, 08:18 PM
#3
Lively Member
I can think of one way off the top of my head, which is not likely the best way (probably slow) - as you move a particular picturebox, you could loop through each of the other pictureboxes in whatever container (say a panel), examine their top/left/height/width and see if there is any overlap:
VB Code:
Dim pb As Control
Dim bAllowMove As Boolean
bAllowMove = True
For Each pb In Panel1.Controls
If GetType(pb).ToString = "System.Windows.Forms.PictureBox" Then
bAllowMove = CheckOverlap(pb) ' a function elsewhere...
End If
Next
If bAllowMove = True Then
' Allow move...
End If
As I try to figure out how to say exactly how to check for overlap in VB I realize my skills are inadequate (it's harder than I gave it credit for). Here are a couple of discussions on the topic though:
http://www.gamedev.net/reference/art...article754.asp
http://www.gamedev.net/reference/lis...tegoryid=45#99
http://www.gamedev.net/reference/art...article735.asp
^^ this actually has the code to do it in C, although it shouldn't be terribly hard to translate - object1->width in C corresponds to PictureBox.Width in VB.NET. For rectangular objects this seems to be the most accurate way, although as I said it isn't likely to be the fastest.
-
Oct 18th, 2003, 05:53 AM
#4
Lively Member
ps: the above loop has a small flaw - there's no check to see if you're looking at the character picturebox (you will of course be in collision with yourself). You could put some check like ... AND pb.Name <> "Foo".
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|