VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Touch module, allows you to have pictures not go through other pictures. Good for a game.

by GAMEGUY (4 Submissions)
Category: Games
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Thu 17th June 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)

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.



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


Download this snippet    Add to My Saved Code

Touch module, allows you to have pictures not go through other pictures. Good for a game. Comments

No comments have been posted about Touch module, allows you to have pictures not go through other pictures. Good for a game.. Why not be the first to post a comment about Touch module, allows you to have pictures not go through other pictures. Good for a game..

Post your comment

Subject:
Message:
0/1000 characters