Estoy haciendo un Arkanoid en Visual Basic como forma de practicar. Por el momento el Form1 solo contiene una Label llamada "nave", y a través de un timer y eventos de teclado controlo su movimiento.
Hasta aquí todo funciona aparentemente bien, hasta que añado un RadioButton que va a hacer de "bola". A partir de este momento, la nave ya no se mueve.
Adjunto código por si alguien me puede ayudar.
Public Class Form1
Dim flechaIzq As Boolean = False
Dim flechaDer As Boolean = False
'Movimiento
Dim comenzar As Boolean = False
Dim izquierda As Boolean = True
Dim arriba As Boolean = True
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.Width = 800
Me.Height = 500
'bola.Location = New Point(nave.Left + (nave.Width / 2) - (bola.Width / 4), nave.Location.Y - bola.Height)
reloj.Enabled = True
reloj.Interval = 30
End Sub
Private Sub reloj_Tick(sender As Object, e As EventArgs) Handles reloj.Tick
If flechaDer Then
If nave.Left < ClientSize.Width - nave.Width Then
nave.Location = New Point(nave.Location.X + 10, nave.Location.Y)
End If
ElseIf flechaIzq Then
If nave.Left > 0 Then
nave.Location = New Point(nave.Location.X - 10, nave.Location.Y)
End If
End If
'If comenzar Then
'mover()
'End If
End Sub
Private Sub mover()
If arriba Then
'bola.Location = New Point(bola.Location.X, bola.Location.Y + 5)
Else
'bola.Location = New Point(bola.Location.X, bola.Location.Y - 5)
End If
If izquierda Then
'bola.Location = New Point(bola.Location.X + 5, bola.Location.Y)
Else
'bola.Location = New Point(bola.Location.X - 5, bola.Location.Y)
End If
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Left Then
flechaIzq = True
End If
If e.KeyCode = Keys.Right Then
flechaDer = True
End If
'If e.KeyCode = Keys.Space Then
'comenzar = True
'End If
End Sub
Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.Left Then
flechaIzq = False
ElseIf e.KeyCode = Keys.Right Then
flechaDer = False
End If
End Sub
End Class
Como se puede ver, en este momento, todo el código que de alguna manera hace referencia a la "bola" está comentado. Tan solo añadir el RadioButton al formulario hace que la "nave" no se mueva con las teclas Izq/Der
Un saludo!