|
-
Jul 27th, 2001, 03:18 PM
#1
Thread Starter
Hyperactive Member
Collison!!!!!!?????!!!!?????????
Hello,
I have two picture boxes, one which i can move with the arrow keys(picbox1)
the other picture box(picbox2) is static and doesn't move. how can i make picbox1 stop in its tracks when it hits picbox2? is there a way to do this with the (x(0)), Ymin, etc. coords? Anyway is fine.
thanks for any help!
Visual Basic 6, HTML, JavaScript, learning C++
-
Jul 27th, 2001, 06:25 PM
#2
Addicted Member
Well It's late and I need sleep. I did make a start on it for you. You need to add the code for the left and right button but you should get the picture by looking at the up and down code. I think there's still something to do on the down code but try it and see.
Code:
Private Sub Form_Activate()
Me.KeyPreview = True
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then
If (Picture1.Top > 0 And Picture1.Top < (Me.Height + Picture1.Height)) Then
If ((Picture1.Left + Picture1.Width < Picture2.Left) Or (Picture1.Left > Picture2.Left + Picture2.Width)) Then
Picture1.Top = Picture1.Top - 100
ElseIf Picture1.Top > Picture2.Top + Picture2.Height Then
Picture1.Top = Picture1.Top - 100
End If
End If
End If
If KeyCode = vbKeyDown Then
If (Picture1.Top < 0 Or Picture1.Top < (Me.Height + Picture1.Height)) Then
If ((Picture1.Left + Picture1.Width < Picture2.Left) Or (Picture1.Left > Picture2.Left + Picture2.Width)) Then
Picture1.Top = Picture1.Top + 100
ElseIf Picture1.Top + Picture1.Height < Picture2.Top Then
Picture1.Top = Picture1.Top + 100
End If
End If
End If
End Sub
-
Jul 28th, 2001, 08:07 AM
#3
Addicted Member
Hi again,
That code I showed you before can be optimised to work but it's bulky. If you want to read about how to do collision detection and even download and example go here:
http://rookscape.com/vbgaming/tutAP.php
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
|