Public Class Form1 Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown If e.KeyCode = Keys.D Then box.Location = New Point(box.Location.X + 5, box.Location.Y) box.Tag = "right" End If If e.KeyCode = Keys.A Then box.Location = New Point(box.Location.X - 5, box.Location.Y) box.Tag = "left" End If If e.KeyCode = Keys.W Then box.Location = New Point(box.Location.X, box.Location.Y - 5) box.Tag = "up" End If If e.KeyCode = Keys.S Then box.Location = New Point(box.Location.X, box.Location.Y + 5) box.Tag = "down" End If checkCollisions() End Sub Private Sub moveBoxBack() If box.Tag = "right" Then box.Location = New Point(box.Location.X - 5, box.Location.Y) End If If box.Tag = "left" Then box.Location = New Point(box.Location.X + 5, box.Location.Y) End If If box.Tag = "up" Then box.Location = New Point(box.Location.X, box.Location.Y + 5) End If If box.Tag = "down" Then box.Location = New Point(box.Location.X, box.Location.Y - 5) End If End Sub Private Sub checkCollisions() If box.Bounds.IntersectsWith(topWall.Bounds) Then moveBoxBack() End If If box.Bounds.IntersectsWith(rightWall.Bounds) Then moveBoxBack() End If If box.Bounds.IntersectsWith(bottomWall.Bounds) Then moveBoxBack() End If End Sub End Class