[Jogo] – Tiro ao Alvo no Excel

Fala galera, segue mais um jogo clássico feito 100% em Excel, usando os recursos do VBA.

Se você quiser aprender a desenvolver o jogo clique aqui

Download link abaixo

Curso de como desenvolver o jogo

Código VBA

Dim sh As Worksheet
Dim gamesh As Worksheet

Dim bala As Shape
Dim coco As Shape


Sub Reset()

    Set sh = ThisWorkbook.Sheets("Config")
    Set gamesh = ThisWorkbook.Sheets("Jogo")
    
    Set bala = gamesh.Shapes("Bala")
    Set coco = gamesh.Shapes("Coco")
    
    Dim sp As Shape
    Set sp = gamesh.Shapes("Bala e Coco")
    
    Dim sp1 As Shape
    Set sp1 = gamesh.Shapes("Coco2")
    
    Dim sp2 As Shape
    Set sp2 = gamesh.Shapes("Coco3")
    
    bala.Top = 228.75
    bala.Left = 159
    coco.Top = 94.5
    coco.Left = 532.5
    
    sp.Top = 471
    sp.Left = 564.75
    
    sp1.Top = 471
    sp1.Left = 564.75
    
    sp2.Top = 471
    sp2.Left = 564.75
    
    sh.Range("c2:C3").Value = "Stop"
    sh.Range("D2").Value = 0
    sh.Range("D3").Value = 10

End Sub

Sub Play_Game()
    
    Set sh = ThisWorkbook.Sheets("Config")
    Set gamesh = ThisWorkbook.Sheets("Jogo")
    
    Set bala = gamesh.Shapes("Bala")
    Set coco = gamesh.Shapes("Coco")
    
    Dim sp As Shape
    Set sp = gamesh.Shapes("Bala e Coco")
    
    sh.Range("c2").Value = "Move"
    
x:
    
    VBA.DoEvents
    
    If sh.Range("c2").Value = "Stop" Then Exit Sub
    
    coco.Top = coco.Top + sh.Range("B2").Value
    
    If coco.Top > 400 Then coco.Top = 94.5
    
    
    GoTo x


End Sub

Sub Pause_Game()

    Set sh = ThisWorkbook.Sheets("Config")
    
    sh.Range("c2:C3").Value = "Stop"

End Sub

Sub Shoot()

    Set sh = ThisWorkbook.Sheets("Config")
    Set gamesh = ThisWorkbook.Sheets("Jogo")
    
    If sh.Range("C2").Value = "Stop" Then
    
        MsgBox "Clique em inicar primeiro"
        Exit Sub
        
    End If
    
    If sh.Range("d3").Value = "0" Then
    
        MsgBox "Você não tem mais bala" & vbLf & vbLf & "Clique no botão reiniciar"
        Exit Sub
        
    End If
    
    
    Set bala = gamesh.Shapes("Bala")
    Set coco = gamesh.Shapes("Coco")
    
    Dim sp As Shape
    Set sp = gamesh.Shapes("Bala e Coco")
    
    sh.Range("c3").Value = "Move"
    sh.Range("c3").Value = "Move"
    
x:
    
    VBA.DoEvents
    
    If sh.Range("c2").Value = "Stop" Then Exit Sub
    
        coco.Top = coco.Top + sh.Range("B2").Value
    
    If coco.Top > 300 Then coco.Top = 94.5
    
    
    If sh.Range("c3").Value = "Stop" Then Exit Sub
    
        bala.Left = bala.Left + sh.Range("B3").Value
    
    If bala.Left > 530 And bala.Left < 540 Then
    
        If coco.Top > 201 And coco.Top < 223 Then
            
            Call Drop_coco
            
            Call Play_Game
        
        End If
    
    End If
    
    If bala.Left > 1000 Then
    
        sh.Range("c3").Value = "Stop"
        sh.Range("D3").Value = sh.Range("D3").Value - 1
        bala.Top = 228.75
        bala.Left = 159
     
    
    End If
    
    GoTo x


End Sub

Sub Drop_coco()

Set sh = ThisWorkbook.Sheets("Config")
Set gamesh = ThisWorkbook.Sheets("Jogo")

Set bala = gamesh.Shapes("Bala")
Set coco = gamesh.Shapes("Coco")

Dim sp As Shape
Set sp = gamesh.Shapes("Bala e Coco")

Dim sp1 As Shape
Set sp1 = gamesh.Shapes("Coco2")

Dim sp2 As Shape
Set sp2 = gamesh.Shapes("Coco3")

sh.Range("c2:c3").Value = "Stop"

bala.Top = 228.75
bala.Left = 159
coco.Top = 94
coco.Left = 532

'sp.Top = 213.85
'sp.Left = 555.1

sp1.Top = 238
sp1.Left = 546.75

sp2.Top = 206.12
sp2.Left = 543.9

x:

VBA.DoEvents

'sp.Top = sp.Top + sh.Range("b2").Value
'sp.Left = sp.Left + sh.Range("b3").Value

sp1.Top = sp1.Top + sh.Range("b2").Value
'sp1.Left = sp1.Left + sh.Range("b3").Value

sp2.Top = sp2.Top + sh.Range("b2").Value
sp2.Left = sp2.Left + sh.Range("b3").Value

If sp1.Top > 380 Then

    sh.Range("d2").Value = sh.Range("d2").Value + 1
    Exit Sub
End If

GoTo x

End Sub

Deixe uma resposta

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *