Dim x As Variant
Dim a As Variant
Dim t As Variant
Dim y As Variant
Dim w As Variant
Dim i As Variant
Dim score As Integer
Dim left1, left2, left3, top1, top2, top3 As Variant
Dim backgr As Integer
Sub showfire()
Timer2.Enabled = True
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
w = 0
Image1.Visible = True
Timer1.Enabled = False
Label4(0).Visible = False
Label4(1).Visible = False
Label4(2).Visible = False
Label3.Caption = ""
Image1.Move 360, 6360
t = 0
End Sub
Private Sub Form_Click()
Label5.Visible = False
End Sub
Private Sub Form_Load()
Randomize Timer
left1 = Int(Rnd * 7000) + 1000
left2 = Int(Rnd * 7000) + 1000
left3 = Int(Rnd * 7000) + 1000
top1 = Int(Rnd * 5000) + 100
top2 = Int(Rnd * 5000) + 100
top3 = Int(Rnd * 5000) + 100
'To set the initial positions of the objects
Image2.Left = left1
Image3.Left = left2
Image4.Left = left3
Image2.Top = top1
Image3.Top = top2
Image4.Top = top3
w = 0
score = 0
Label7.Caption = Str$(score)
End Sub
Private Sub Image7_Click()
Label5.Visible = False
End Sub
Private Sub Instruct_Click()
Label5.Visible = True
Label5.Caption = "To play the game, you need to key in the velocity and the angle. The range of angle should be between 0 and 90 degree. After entering the above values, click launch to play. After every trial, you have to reset the game. After striking all the objects, press File menu and select new game to play again."
End Sub
Private Sub mnuExit_Click()
End
End Sub
Private Sub mnunew_Click()
w = 0
Randomize Timer
'To display all the objects again
left1 = Int(Rnd * 7000) + 1000
left2 = Int(Rnd * 7000) + 1000
left3 = Int(Rnd * 7000) + 1000
top1 = Int(Rnd * 5000) + 100
top2 = Int(Rnd * 5000) + 100
top3 = Int(Rnd * 5000) + 100
Image2.Left = left1
Image3.Left = left2
Image4.Left = left3
Image2.Top = top1
Image3.Top = top2
Image4.Top = top3
Image2.Visible = True
Image3.Visible = True
Image4.Visible = True
Image1.Visible = True
Timer1.Enabled = False
Label4(0).Visible = False
Label4(1).Visible = False
Label4(0).Visible = False
Label3.Caption = ""
Image1.Move 360, 6360
t = 0
End Sub
'To simulate rocket flight using projectile equation
Private Sub Timer1_Timer()
MMControl1.Command = "close"
If Image1.Left < 15000 And Image1.Top < 9000 Then
v = Val(Text1.Text)
a = Val(Text2.Text)
t = t + 1
y = v * Sin(a * 3.141592654 / 180) * t - 4.9 * (t ^ 2)
x = v * Cos(a * 3.141592654 / 180) * t
Image1.Move Image1.Left + x, Image1.Top - y
If Image4.Visible = True And (Image1.Left < left3 + 240 And Image1.Left > left3 - 240) And (Image1.Top < top3 + 240 And Image1.Top > top3 - 240) Then
i = 2
Timer1.Enabled = False
showfire
Image4.Visible = False
Image1.Visible = False
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.FileName = "D:\Liew Folder\VB program\audio\explosion.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
Label3.Caption = "You strike the satellite!"
Label4(2).Left = left3 + 240
Label4(2).Top = top3 + 240
Label4(2).Visible = True
Image5(2).Left = left3 + 240
Image5(2).Top = top3 + 240
score = score + 50
ElseIf Image3.Visible = True And (Image1.Left < left2 + 240 And Image1.Left > left2 - 240) And (Image1.Top < top2 + 240 And Image1.Top > top2 - 240) Then
Timer1.Enabled = False
i = 1
showfire
Image3.Visible = False
Image1.Visible = False
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.FileName = "D:\Liew Folder\VB program\audio\explosion.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
Label3.Caption = "You strike the rocket!"
Label4(1).Left = left2 + 240
Label4(1).Top = top2 + 240
Label4(1).Visible = True
Image5(1).Left = left2 + 240
Image5(1).Top = top2 + 240
score = score + 100
ElseIf Image2.Visible = True And (Image1.Left < left1 + 240 And Image1.Left > left1 - 240) And (Image1.Top < top1 + 240 And Image1.Top > top1 - 240) Then
Timer1.Enabled = False
i = 0
showfire
Image2.Visible = False
Image1.Visible = False
MMControl1.Notify = False
MMControl1.Wait = True
MMControl1.Shareable = False
MMControl1.DeviceType = "WaveAudio"
MMControl1.FileName = "D:\Liew Folder\VB program\audio\explosion.wav"
MMControl1.Command = "Open"
MMControl1.Command = "Play"
Label3.Caption = "You strike the Saturn!"
Label4(0).Left = left1 + 240
Label4(0).Top = top1 + 240
Label4(0).Visible = True
Image5(0).Left = left1 + 240
Image5(0).Top = top1 + 240
score = score + 200
End If
Else
Label3.Caption = "You miss the target!"
Timer1.Enabled = False
End If
Label7.Caption = Str$(score)
End Sub
Private Sub Timer2_Timer()
w = w + 1
If w < 30 Then
Image5(i).Visible = True
Label4(i).Visible = True
Else
Image5(i).Visible = False
Label4(i).Visible = False
Timer2.Enabled = False
End If
End Sub
Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy