hello everyone,I am new here as I am new to VB.
Also it looks like I have very similar problem like the guy above.
i found this code after doing simple google search and it is simple enough for me (I want to keep it this way until my skills in VB improve ).
The problem is - I want to have walls in my game. It looks like it is very simple thing to do - replace beep with something that would prevent two images overlapping, but I have no idea how to do it. (And believe me I tried)
Thanks to those who can help out.
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim pic1Left As Integer, pic1Top As Integer, pic1Right As Integer
Dim pic1Bottom As Integer'Declare parameter variables for image 1
Dim pic2Left As Integer, pic2Top As Integer
Dim pic2Right As Integer, pic2Bottom As Integer 'Declare parameter variables for image 2
Dim topBetween As Boolean, bottomBetween As Boolean
Dim leftBetween As Boolean, rightBetween As Boolean
Select Case KeyCode
Case vbKeyDown
Image1.Top = Image1.Top + 50
Case vbKeyUp
Image1.Top = Image1.Top - 50
Case vbKeyLeft
Image1.Left = Image1.Left - 50
Case vbKeyRight
Image1.Left = Image1.Left + 50
End Select
'Assign image1 variables
pic1Left = Image1.Left
pic1Right = Image1.Left + Image1.Width
pic1Top = Image1.Top
pic1Bottom = Image1.Top + Image1.Height
'Assign image2 variables
pic2Left = Image2.Left
pic2Right = Image2.Left + Image2.Width
pic2Top = Image2.Top
pic2Bottom = Image2.Top + Image2.Height
'Crash code
If pic1Left >= pic2Left And pic1Left <= pic2Right Then
leftBetween = True
End If
If pic1Right >= pic2Left And pic1Right <= pic2Right Then
rightBetween = True
End If
If pic1Top >= pic2Top And pic1Top <= pic2Bottom Then
topBetween = True
End If
If pic1Bottom >= pic2Top And pic1Bottom <= pic2Bottom Then
bottomBetween = True
End If
If leftBetween = True Or rightBetween = True Then
If topBetween = True Or bottomBetween = True Then
Beep
End If
End If
End Sub