- Home
·
- Games
·
- Touch module, allows you to have pictures not go through other pictures. Good for a game.
Touch module, allows you to have pictures not go through other pictures. Good for a game.
Touch module, allows you to have pictures not go through other pictures. Good for a game.
Rate Touch module, allows you to have pictures not go through other pictures. Good for a game.
(1(1 Vote))
Function touch(Picture1 As PictureBox, Picture2 As PictureBox) As String
Step = 50
touch = "False"
If ((Picture1.Top + Picture1.Height >= Picture2.Top) _
And (Picture1.Top <= Picture2.Top + Picture2.Height) _
And (Picture1.Left + Picture1.Width >= Picture2.Left) _
And (Picture1.Left + Picture1.Width - Step < Picture2.Left)) _
Then
touch = "Right"
Picture1.Left = Picture1.Left - Step
End If
If ((Picture1.Top + Picture1.Height >= Picture2.Top) _
And (Picture1.Top <= Picture2.Top + Picture2.Height) _
And (Picture1.Left <= Picture2.Left + Picture2.Width) _
And (Picture1.Left + Step > Picture2.Left + Picture2.Width)) _
Then
touch = "Left"
Picture1.Left = Picture1.Left + Step
End If
If ((Picture1.Left + Picture1.Width >= Picture2.Left) _
And (Picture1.Left <= Picture2.Left + Picture2.Width) _
And (Picture1.Top <= Picture2.Top + Picture2.Height) _
And (Picture1.Top + Step > Picture2.Top + Picture2.Height)) _
Then
touch = "Top"
Picture1.Top = Picture1.Top + Step
End If
If ((Picture1.Left + Picture1.Width >= Picture2.Left) _
And (Picture1.Left <= Picture2.Left + Picture2.Width) _
And (Picture1.Top + Picture1.Height >= Picture2.Top) _
And (Picture1.Top + Picture1.Height - Step < Picture2.Top)) _
Then
touch = "Bottom"
Picture1.Top = Picture1.Top - Step
End If
End Function
'Under picture1_keydown(Private Sub Picture1_KeyDown(KeyCode As Integer, Shift As Integer), put the following code...
'code to move character
Select Case KeyCode
Case Is = vbKeyUp
Picture1.Top = Picture1.Top - 50
Case Is = vbKeyDown
Picture1.Top = Picture1.Top + 50
Case Is = vbKeyRight
Picture1.Left = Picture1.Left + 50
Case Is = vbKeyLeft
Picture1.Left = Picture1.Left - 50
'Code to not allow picture1 pass through other pictures
Print touch(picture1,picture2)
Print touch (picture1, picture3)
'etc. for each picture
'if you want to run an event when picture1 hits another,
If touch(picture1,Picture2) = "Left" then 'Substitute "Left" for whatever side
'your code
end if
Touch module, allows you to have pictures not go through other pictures. Good for a game. Comments
No comments yet — be the first to post one!
Post a Comment