This is my code to create a 2d mouse in the maze. Now i would like to check for collisions, if the mouse hit the walls.Can someone please tell me where i can add the codes.I know what to write but dont know where to put it.Can someone help me please.
Private Type Mouse
X1 As Integer 'bounding box values
X2 As Integer
Y1 As Integer
Y2 As Integer
End Type
Dim Leftwall As Mouse
Dim Rightwall As Mouse
Dim Topwall As Mouse
Dim Bottomwall As Mouse
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyUp Then Call Mouseup_Click
If KeyCode = vbKeyDown Then Call Mousedown_Click
If KeyCode = vbKeyLeft Then Call Mouseleft_Click
If KeyCode = vbKeyRight Then Call Mouseright_Click
End Sub
Private Sub Render()
'This draws the proper shape
'for squares we just draw the four lines to make the outline
frmMaze.Line (Bottomwall.X1, Bottomwall.Y1)-(Bottomwall.X2, Bottomwall.Y1)
frmMaze.Line (Leftwall.X1, Leftwall.Y1)-(Leftwall.X1, Leftwall.Y2)
frmMaze.Line (Rightwall.X2, Rightwall.Y1)-(Rightwall.X2, Rightwall.Y2)
frmMaze.Line (Topwall.X1, Topwall.Y2)-(Topwall.X2, Topwall.Y2)
End Sub
Private Sub Form_Load()
'This initializes the properties of our shapes.
Bottomwall.X1 = 120
Bottomwall.X2 = 840
Bottomwall.Y1 = 240
Bottomwall.Y2 = 720
Leftwall.X1 = 120
Leftwall.X2 = 840
Leftwall.Y1 = 240
Leftwall.Y2 = 720
Rightwall.X1 = 120
Rightwall.X2 = 840
Rightwall.Y1 = 240
Rightwall.Y2 = 720
Topwall.X1 = 120
Topwall.X2 = 840
Topwall.Y1 = 240
Topwall.Y2 = 720
End Sub
Private Sub Mouseup_Click()
Bottomwall.X1 = Bottomwall.X1
Bottomwall.X2 = Bottomwall.X2
Bottomwall.Y1 = Bottomwall.Y1 - 100
Bottomwall.Y2 = Bottomwall.Y2 - 100
Leftwall.X1 = Leftwall.X1
Leftwall.X2 = Leftwall.X2
Leftwall.Y1 = Leftwall.Y1 - 100
Leftwall.Y2 = Leftwall.Y2 - 100
Rightwall.X1 = Rightwall.X1
Rightwall.X2 = Rightwall.X2
Rightwall.Y1 = Rightwall.Y1 - 100
Rightwall.Y2 = Rightwall.Y2 - 100
Topwall.X1 = Topwall.X1
Topwall.X2 = Topwall.X2
Topwall.Y1 = Topwall.Y1 - 100
Topwall.Y2 = Topwall.Y2 - 100
frmMaze.Cls
Render
End Sub
Private Sub Mousedown_Click()
Bottomwall.X1 = Bottomwall.X1
Bottomwall.X2 = Bottomwall.X2
Bottomwall.Y1 = Bottomwall.Y1 + 100
'Bottomwall.Y2 = Bottomwall.Y2 + 100
Leftwall.X1 = Leftwall.X1
Leftwall.X2 = Leftwall.X2
Leftwall.Y1 = Leftwall.Y1 + 100
Leftwall.Y2 = Leftwall.Y2 + 100
Rightwall.X1 = Rightwall.X1
Rightwall.X2 = Rightwall.X2
Rightwall.Y1 = Rightwall.Y1 + 100
Rightwall.Y2 = Rightwall.Y2 + 100
Topwall.X1 = Topwall.X1
Topwall.X2 = Topwall.X2
Topwall.Y1 = Topwall.Y1 + 100
Topwall.Y2 = Topwall.Y2 + 100
frmMaze.Cls
Render
End Sub
Private Sub Mouseleft_Click()
Bottomwall.X1 = Bottomwall.X1 - 100
Bottomwall.X2 = Bottomwall.X2 - 100
Bottomwall.Y1 = Bottomwall.Y1
Bottomwall.Y2 = Bottomwall.Y2
Leftwall.X1 = Leftwall.X1 - 100
Leftwall.X2 = Leftwall.X2 - 100
Leftwall.Y1 = Leftwall.Y1
Leftwall.Y2 = Leftwall.Y2
Rightwall.X1 = Rightwall.X1 - 100
Rightwall.X2 = Rightwall.X2 - 100
Rightwall.Y1 = Rightwall.Y1
Rightwall.Y2 = Rightwall.Y2
Topwall.X1 = Topwall.X1 - 100
Topwall.X2 = Topwall.X2 - 100
Topwall.Y1 = Topwall.Y1
Topwall.Y2 = Topwall.Y2
frmMaze.Cls
Render
End Sub
Private Sub Mouseright_Click()
Bottomwall.X1 = Bottomwall.X1 + 100
Bottomwall.X2 = Bottomwall.X2 + 100
Bottomwall.Y1 = Bottomwall.Y1
'Bottomwall.Y2 = Bottomwall.Y2
Leftwall.X1 = Leftwall.X1 + 100
Leftwall.X2 = Leftwall.X2 + 100
Leftwall.Y1 = Leftwall.Y1
Leftwall.Y2 = Leftwall.Y2
Rightwall.X1 = Rightwall.X1 + 100
Rightwall.X2 = Rightwall.X2 + 100
Rightwall.Y1 = Rightwall.Y1
Rightwall.Y2 = Rightwall.Y2
Topwall.X1 = Topwall.X1 + 100
Topwall.X2 = Topwall.X2 + 100
Topwall.Y1 = Topwall.Y1
Topwall.Y2 = Topwall.Y2
frmMaze.Cls
Render
End Sub
|