RE:como mover un objeto en visual basic 2008 keypr
Hace siglos que lo preguntaste pero le puede servir a otra persona, dejo el código de un intento de space invaders que comencé, digo intento porque ni los malos disparan, ni se suman puntos ni pasa nada cuando los malos llegan abajo de la pantalla, eso si, al menos la nave se mueve acia donde le dices, dispara y elimina a los enemigos, espero que sirva de ayuda a alguien:
Public Class Form1
Dim topi, lefi As Integer
Dim bad(4, 10) As PictureBox
Dim puntuacion As Integer
Private Sub Desplazamiento_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Left Then
If nave.Left > 3 Then
nave.Left = nave.Left - 7
End If
End If
If e.KeyCode = Keys.Right Then
If nave.Left < 660 Then
nave.Left = nave.Left + 7
End If
End If
If e.KeyCode = Keys.Space Then
If Proyectil.Visible = False Then
Proyectil.Left = nave.Left + 13
Proyectil.Visible = True
Proyectil.Top = nave.Top - 21
Timer1.Enabled = True
End If
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
nave.Top = 615
nave.Left = 332
Dim i, j As Byte
Dim filas As Byte
Dim columnas As Byte
filas = 4
columnas = 10
topi = 80
lefi = 40
For i = 1 To filas
lefi = 30
For j = 1 To columnas
bad(i, j) = New PictureBox
bad(i, j).SizeMode = PictureBoxSizeMode.StretchImage
bad(i, j).Height = 30
'Ruta de la imagen de los enemigos --------------------------------------------------------------------------------------
bad(i, j).Image = Image.FromFile("..\..\..\malos.jpg")
'------------------------------------------------------------------------------------------------------------------------
bad(i, j).Width = 30
bad(i, j).Top = topi
bad(i, j).Left = lefi
lefi = lefi + 50
Me.Controls.Add(bad(i, j))
Next j
topi = topi + 50
Next i
Timer2.Enabled = True
Timer4.Enabled = True
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim filas As Byte
Dim columnas As Byte
filas = 4
columnas = 10
For i = 1 To filas
For j = 1 To columnas
If Proyectil.Top >= bad(i, j).Top And Proyectil.Top <= bad(i, j).Top + 30 And Proyectil.Left + 6 >= bad(i, j).Left And Proyectil.Left + 6 <= bad(i, j).Left + 30 Then
If bad(i, j).Name <> "muerto" Then
bad(i, j).Image = Nothing
bad(i, j).Name = "muerto"
Timer1.Enabled = False
Proyectil.Visible = False
puntuacion = puntuacion + 50
Label2.Text = puntuacion
End If
End If
Next j
Next i
If Proyectil.Visible = True Then
Proyectil.Top = Proyectil.Top - 3
End If
If Proyectil.Top = 0 Then
Timer1.Enabled = False
Proyectil.Visible = False
End If
If puntuacion = 2000 Then
Label5.Visible = True
End If
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim i, j As Byte
Dim filas As Byte
Dim columnas As Byte
filas = 4
columnas = 10
If bad(1, 10).Left < 660 Then
For i = 1 To filas
For j = 1 To columnas
bad(i, j).Left = bad(i, j).Left + 4
Next j
Next i
Else
Timer2.Enabled = False
Timer3.Enabled = True
End If
End Sub
Private Sub Timer3_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Dim i, j As Byte
Dim filas As Byte
Dim columnas As Byte
filas = 4
columnas = 10
If bad(1, 1).Left > 3 Then
For i = 1 To filas
For j = 1 To columnas
bad(i, j).Left = bad(i, j).Left - 4
Next j
Next i
Else
Timer3.Enabled = False
Timer2.Enabled = True
End If
End Sub
Private Sub Timer4_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer4.Tick
Dim i, j As Byte
Dim filas As Byte
Dim columnas As Byte
filas = 4
columnas = 10
For i = 1 To filas
For j = 1 To columnas
bad(i, j).Top = bad(i, j).Top + 1
Next j
Next i
End Sub
End Class