Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
Label1.Text = e.KeyCode
Select Case (e.KeyCode)
Case Keys.Up
n = 0
Picmove.Image = ImageList1.Images(0)
Picmove.Top -= 5
Case Keys.Down
n = 1
Picmove.Image = ImageList1.Images(1)
Picmove.Top += 5
Case Keys.Left
n = 2
Picmove.Image = ImageList1.Images(2)
Picmove.Left -= 5
Case Keys.Right
n = 3
Picmove.Image = ImageList1.Images(3)
Picmove.Left += 5
Case Keys.Space
Picb.Visible = True
If Timer1.Enabled = False Then
Picb.Left = Picmove.Left
Picb.Top = Picmove.Top
Timer1.Enabled = True
nok = n
End If
End Select
If Picmove.Top > Me.Height - 40 Then
Picmove.Top = 0
ElseIf Picmove.Top < -20 Then
Picmove.Top = Me.Height - 40
ElseIf Picmove.Left > Me.Width - 20 Then
Picmove.Left = 0
ElseIf Picmove.Left < -20 Then
Picmove.Left = Me.Width - 20
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Picb.Visible = True
If Picb.Left < 0 Or Picb.Top < 0 Or Picb.Top > Me.Height Or Picb.Left > Me.Width Then
Timer1.Enabled = False
Picb.Visible = False
Else
Select Case (nok)
Case 0
Picb.Top -= 5
Case 1
Picb.Top += 5
Case 2
Picb.Left -= 5
Case 3
Picb.Left += 5
End Select
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
n = 1
Picmove.Image = ImageList1.Images(1)
Picb.Image = ImageList1.Images(4)
End Sub
End Class
'這是一個物然後發射子彈的程式,如果要讓怪物跑出來,子彈可以發很多顆射擊到怪物,怪物會消失,要加什麼