Inquiridor
Erro Invasores do Espaço

Pergunta
-
Bom dia, estou fazendo um curso de Visual Basic e fiz todo o código que foi proposto em aula, coloquei um shape com a propriedade FillStyle como 0, Shape como 0, ai pede para inserir uma imagem com a propriedade Index como 0 e pede para inserir dois Timer, Timer1 = 100 e Timer2 = 50. Mas quando vou executar o jogo dá erro nas seguintes partes em negrito:
Dim Lugar As Boolean
Dim Posicao As Integer
Dim Matou As Byte
Dim I As Integer
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal IpszSoundName As String, ByVal uFlags As Long) As Long
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal IpstrCommand As String, ByVal IpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Dim rc As Integer
If KeyCode = vbKeyF2 Then
IniciaJogo
ElseIf KeyCode = vbKeuF3 Then
Timer1.Enabled = False
Timer1.Enabled = False
MsgBox "Pausa", vbExclamation, "Jogo"
Timer1.Enabled = True
Timer1.Enabled = True
ElseIf KeyCode = vbKeySpace And Line2.Visible = False Then
rc = sndPlaySound(App.Path & "\Tiro.WAV", SND_ASYNC)
Line2.Visile = True
Line2.X1 = Image1.Left + 230
Line2.X2 = Image1.Left + 230
Line2.Y1 = Image1.Top - 360
Line2.Y2 = Image1.Top
Timer2.Enabled = True
ElseIf KeyCode = vbKeyRight Then
If Image1.Left < 6600 Then
Image1.Left = Image1.Left + 200
End If
ElseIf KeyCode = vbKeyLeft Then
If Image1.Left > 0 Then
Image1.Left = Image1.Left - 200
End If
End If
End Sub
Private Sub Form_Load()
IniciaJogo
End Sub
Private Sub Timer1_Timer()
For I = 0 To 5
Posicao = Int(Rnd * 100)
If Alien(I).Top < 6360 Then
Alien(I).Top = Alien(I).Top + 100
If Lugar = False Then
If Alien(I).Left < 4200 Then
Alien(I).Left = Alien(I).Left + Posicao
Lugar = True
Else
Alien(I).Left = Alien(I).Left - 2000
Lugar = True
End If
Else
If Alien(I).Left > 120 Then
Alien(I).Left = Alien(I).Left - Posicao
Lugar = False
Else
Alien(I).Left = Alient(I).Left + 2000
Lugar = False
End If
End If
Else
Alien(I).Top = -30
End If
If Alien(I).Left >= Image1.Left And Alien(I).Left <= Image1.Left + 480 Then
If Alien(I).Top + 480 >= 5280 And Alien(I).Top + 480 <= 5760 Then
rc = sndPlaySounf(App.Path & "\Perdeu.WAV", SND_ASYNC)
Image1.Picture = Image2.Picture
Timer1.Enabled = False
Timer2.Enabled = False
If MsgBox("Você perdeu", vbYesNo, "Jogo") = vbYes Then
IniciaJogo
Else
Exit Sub
End If
End If
End If
Next I
End Sub
Private Sub Timer2_Timer()
Line2.Y1 = Line2.Y1 - 250
Line2.Y2 = Line2.Y2 - 250
conta = conta + 1
If Line2.Y1 < 0 Then
Line2.Visible = False
Timer2.Enabled = False
End If
For x = O To 5
pega = Alien(x).Left
If Line2.X1 >= Alien(x).Left And Line2.X2 <= Alien(x).Left + 480 Then
If Line2.Y1 >= Alien(x).Top And Line2.Y2 <= Alien(x).Top + 680 Then
If Alien(x).Visible = True Then
Line2.Visible = False
Matou = Matou + 1
End If
Alien(x).Visible = False
End If
End If
Next x
If Matou = 6 Then
If MsgBox("Você venceu", vbYesNo, "Jogo") = vbYes Then
Timer1.Enabled = False
Timer2.Enabled = False
IniciaJogo
Else
Timer1.Enabled = False
Timer2.Enabled = False
End If
End If
End Sub
Private Sub IniciaJogo()
For I = 0 To 5
Alien(I).Visible = True
Alien(I).Picture = LoadPicture("C:\Users\user\Desktop\Vb\4.jpg")
Next I
Alien(0).Left = 3120
Alien(0).Top = 120
Alien(1).Left = 1800
Alien(1).Top = 120
Alien(2).Left = 840
Alien(2).Top = 1440
Alien(3).Left = 2160
Alien(3).Top = 1560
Alien(4).Left = 3480
Alien(4).Top = 480
Alien(5).Left = 600
Alien(5).Top = 720
Image.Picture = LoadPicture("C:\Users\user\Desktop\Vb\3.jpg")
Timer1.Enabled = True
Timer2.Enabled = True
Matou = 0
End SubAlguém poderia me ajudar?
Todas as Respostas
-
Em quais linhas exatamente aparece o erro?
A variável I em nível de formulário.
Faça um teste colocando-a como variável local, em nível de sub rotina.
MARIANO1776
- Editado Mariano1776 segunda-feira, 2 de setembro de 2019 00:02
- Sugerido como Resposta Mariano1776 domingo, 8 de setembro de 2019 23:03
-