Ir para conteúdo
Fórum Script Brasil
  • 0

Montar um joguinho simples


Cristiano Apolonio

Pergunta

Ola galera,

To começando agora com um curso de programação mas quando cheguei em Visual Basic minha aula travou em um jogo simples onde não consigo identificar o erro.

O jogo se chama invasores do espaço e na apostila pede pra inserir um Shape, uma imagem, copiar as imagesn e teal...

Depois manda digitar o código abaixo e executar, só que aparecem alguns erros.

Veja em negrito...

Option Explicit
Declare Function SndPlaySound Lib "MMSystem" (ByVal Ipsound As String, ByVal Flag As Integer) As Integer
(1° Erro) Global Const SND_ASYNC = &H1
Private Sub form_Load()
Dim Lugar As Boolean
Dim Posicao As Integer
Dim Matou As Byte
Dim I As Integer
(2° Erro) 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
Inicia Jogo
ElseIf KeyCode = vbKeyF3 Then
Timer1.Enabled = False
Timer1.Enabled = False
MsgBox "Pausa", vcExclamation, "Jogo"
Timer1.Enabled = True
Timer1.Enabled = True
ElseIf KeyCode = vbKeySpace And Line2.Visible = False Then
rc = SndPlaySound(App.Path & "\Tiro.WAV", SND_ASYNC)
Line2.Visible = True
Line2.X1 = Image1.Left + 230
Line2.X2 = Image1.Left + 230
Line2.Y1 = Image1.Tpo - 360
Line2.Y2 = Image1.Top
Timer2.Enabled = True
ElseIf KeyCode = vcKeyRight 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()
Inicia Jogo
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 = Alien(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 = SndPlaySound(App.Path & "\Perdeu.WAV", SND_ASYNC)
Image1.Picture = Image2.Picture
Timer1.Enabled = False
Timer2.Enabled = False
If MsgBox("Você Perdeu", vbYesNo, "Jogo") = vbYes Then
Inicia Jogo
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
Line2.Enabled = False
End If
For X = 0 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
Time2.Enabled = False
Inicia Jogo
Else
Timer1.Enabled = False
Time2.Enabled = False
End If
End If
End Sub
Private Sub IniciaJogo()
For I = 0 To 5
Alien(X).Visible = True
Alien(X).Picture = LoadPicture("C:Arquivos de programas\PREPARA\VB6MOD1\face04.ico")
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
Image1.Picture = LoadPicture("C:Arquivos de programas\PREPARA\VB6MOD1\arw03.ico")
Timer1.Enabled = True
Timer2.Enabled = True
Matou = 0
End Sub

1° Erro >> Compile error: Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules.

Ai eu removo o global e executo dinovo e aparece outro erro...

2° Erro >> Compile error: only comments may appear after end sub and function or end property

Se alguém puder me ajudar e também explicar o porque dos erros, eu ficaria muito agradecido. To precisando passar logo pro Java pra concluir...

Editado por Cristiano Apolonio
Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...