visual basic sebagai software untuk membuat program windows bisa juga dipergunakan untuk pembuatan game, walaupun dengan fungsi yang terbatas.
kali ini saya akan mejelaskan pembuatan game shooter sejenis duck hunt pada konsol game nintendo tetapi dengan menggunakan visual basic.prinsip pemrograman ini cukup sederhana yaitu jika gambar background yang terklik, maka akan mengurangi nyawa kita sedangkan jika gambar bebek yang di klik maka akan menambah jumlah score. game akan berakhir jika nyawa kita adalah 0.
penempatan komponen gamenya adalah sebagai berikut:
kondisi awal ketika program dijalankan gambar bebek dalam kondisi tidak terlihat, visible = false
untuk memunculkannya digunakan timer.
jika nyawa kita habis caption = 0 maka fungsi selanjutnya akan menghiden form1 atau halaman permainan utama, serta menampilkan form2 yang berisi pemberitahuian jika permainan telah berakhir. pada form2 ini terdapat 2 tombol.
tombol 1 untuk meresetb permainan, dan tombol 2 untuk menutup aplikasi.
form1
Private Sub Form_Load()
Form2.Visible = False
End Sub
Private Sub Image1_Click()
Label4.Caption = Label4.Caption - 1
If Label4.Caption = 0 Then
Form1.Visible = False
Form2.Visible = True
Label4.Caption = 10
Label2.Caption = 0
End If
End Sub
Private Sub Image3_Click()
Label4.Caption = Label4.Caption - 1
If Label4.Caption = 0 Then
Form1.Visible = False
Form2.Visible = True
Label4.Caption = 10
Label2.Caption = 0
End If
End Sub
Private Sub Image2_Click()
Label4.Caption = Label4.Caption - 1
If Label4.Caption = 0 Then
Form1.Visible = False
Form2.Visible = True
Label4.Caption = 10
Label2.Caption = 0
End If
End Sub
Private Sub Image4_Click()
Label4.Caption = Label4.Caption - 1
If Label4.Caption = 0 Then
Form1.Visible = False
Form2.Visible = True
Label4.Caption = 10
Label2.Caption = 0
End If
End Sub
Private Sub Image10_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image11_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image12_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image13_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image14_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image15_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image16_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image17_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image18_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image19_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image20_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image5_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image6_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image7_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image8_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Image9_Click()
Label2.Caption = Label2 + 1
End Sub
Private Sub Timer1_Timer()
Timer2.Enabled = True
Timer1.Enabled = False
Image2.Visible = False
Image3.Visible = False
Image4.Visible = False
End Sub
Private Sub Timer2_Timer()
Timer3.Enabled = True
Timer2.Enabled = False
Image2.Visible = True
Image3.Visible = False
Image4.Visible = False
End Sub
Private Sub Timer3_Timer()
Timer4.Enabled = True
Timer3.Enabled = False
Image3.Visible = True
Image4.Visible = False
End Sub
Private Sub Timer4_Timer()
Timer1.Enabled = True
Timer4.Enabled = False
Image4.Visible = True
End Sub
Private Sub Timer5_Timer()
Image5.Visible = True
Image6.Visible = False
Image7.Visible = False
Timer6.Enabled = True
Timer5.Enabled = False
End Sub
Private Sub Timer6_Timer()
Image5.Visible = False
Image6.Visible = True
Image7.Visible = False
Timer7.Enabled = True
Timer6.Enabled = False
End Sub
Private Sub Timer7_Timer()
Image5.Visible = False
Image6.Visible = False
Image7.Visible = True
Timer7.Enabled = False
Timer8.Enabled = True
End Sub
Private Sub Timer8_Timer()
Image7.Visible = False
Timer8.Enabled = False
Timer5.Enabled = True
Timer5.Interval = Rnd * 10000
End Sub
Private Sub Timer9_Timer()
Image8.Visible = True
Timer9.Enabled = False
Timer10.Enabled = True
End Sub
Private Sub Timer10_Timer()
Image8.Visible = False
Timer9.Enabled = True
Timer10.Enabled = False
Timer9.Interval = Rnd * 10000
End Sub
Private Sub Timer11_Timer()
Image19.Visible = True
Timer11.Enabled = False
Timer12.Enabled = True
End Sub
Private Sub Timer12_Timer()
Image19.Visible = False
Timer11.Enabled = True
Timer12.Enabled = False
Timer11.Interval = Rnd * 10000
End Sub
Private Sub Timer13_Timer()
Image20.Visible = True
Timer13.Enabled = False
Timer14.Enabled = True
End Sub
Private Sub Timer14_Timer()
Image20.Visible = False
Timer13.Enabled = True
Timer14.Enabled = False
Timer13.Interval = Rnd * 10000
End Sub
Private Sub Timer15_Timer()
Image9.Visible = True
Image10.Visible = False
Image11.Visible = False
Image12.Visible = False
Timer16.Enabled = True
Timer15.Enabled = False
End Sub
Private Sub Timer16_Timer()
Image9.Visible = False
Image10.Visible = True
Image11.Visible = False
Image12.Visible = False
Timer17.Enabled = True
Timer16.Enabled = False
End Sub
Private Sub Timer17_Timer()
Image9.Visible = False
Image10.Visible = False
Image11.Visible = True
Image12.Visible = False
Timer17.Enabled = False
Timer18.Enabled = True
End Sub
Private Sub Timer18_Timer()
Image9.Visible = False
Image10.Visible = False
Image11.Visible = False
Image12.Visible = True
Timer18.Enabled = False
Timer19.Enabled = True
End Sub
Private Sub Timer19_Timer()
Image12.Visible = False
Timer19.Enabled = False
Timer15.Enabled = True
Timer15.Interval = Rnd * 10000
End Sub
Private Sub Timer20_Timer()
Image13.Visible = True
Image14.Visible = False
Image15.Visible = False
Image16.Visible = False
Image17.Visible = False
Image18.Visible = False
Timer21.Enabled = True
Timer20.Enabled = False
End Sub
Private Sub Timer21_Timer()
Image13.Visible = False
Image14.Visible = True
Image15.Visible = False
Image16.Visible = False
Image17.Visible = False
Image18.Visible = False
Timer22.Enabled = True
Timer21.Enabled = False
End Sub
Private Sub Timer22_Timer()
Image13.Visible = False
Image14.Visible = False
Image15.Visible = True
Image16.Visible = False
Image17.Visible = False
Image18.Visible = False
Timer22.Enabled = False
Timer23.Enabled = True
End Sub
Private Sub Timer23_Timer()
Image13.Visible = False
Image14.Visible = False
Image15.Visible = False
Image16.Visible = True
Image17.Visible = False
Image18.Visible = False
Timer23.Enabled = False
Timer24.Enabled = True
End Sub
Private Sub Timer24_Timer()
Image13.Visible = False
Image14.Visible = False
Image15.Visible = False
Image16.Visible = False
Image17.Visible = True
Image18.Visible = False
Timer24.Enabled = False
Timer25.Enabled = True
End Sub
Private Sub Timer25_Timer()
Image13.Visible = False
Image14.Visible = False
Image15.Visible = False
Image16.Visible = False
Image17.Visible = False
Image18.Visible = True
Timer25.Enabled = False
Timer26.Enabled = True
End Sub
Private Sub Timer26_Timer()
Image18.Visible = False
Timer26.Enabled = False
Timer20.Enabled = True
Timer20.Interval = Rnd * 10000
End Sub
form2
Private Sub Command1_Click()
Form1.Visible = True
Form2.Visible = False
End Sub
Private Sub Command2_Click()
Unload Me
End Sub