- Private Declare Function GetTickCount Lib "kernel32" () As Long
- Const PI! = 3.1416
- Dim Ve As Boolean, Power%, Goc%, vitriX&, vitriY&, Shotting As Boolean
- Dim LanBan%, Trung As Boolean, Tông%
- Private Sub Command1_Click() 'Start
- Command1.Visible = False
- LanBan = 0: Tông = 0
- Picture1.Cls
- GioiThieu
- VeDonVi
- Label1.Visible = False: Label2.Visible = False
- End Sub
- Private Sub Form_Activate()
- Command1.SetFocus
- End Sub
- Private Sub Form_Load() ''''''''''''
- GioiThieu
- Randomize
- Picture1.AutoRedraw = True
- Picture1.Scale (0, 200)-(400, -12)
- Picture2.Picture = LoadPicture("bbb.jpg")
- VeDonVi
- End Sub
- Private Sub VeDonVi()
- Picture1.Line (10, 0)-(390, 0), vbBlack
- Dim i&
- For i = 20 To 380 Step 20
- Picture1.Line (i, -10)-(i, -5)
- Picture1.Print i
- Next
- Picture1.DrawStyle = 2
- Picture1.Circle (10, 10), 60, 0, -Rads(0), -Rads(80)
- End Sub
- Sub GioiThieu()
- Picture1.CurrentX = 2: Picture1.CurrentY = 196
- Picture1.Print " X = Vcos(ø)t, Y = Vsin(ø)t - 1/2gt2"
- Picture1.Print " maÌ V = Power, ø = Goìc"
- Picture1.Print " Written by truongphu on VB6"
- Picture1.Print ""
- Picture1.Print " DuÌng chuôòt, nhâìn (click) vaÌ rê (move) ðêÒ ngãìm (take aim), nhâìn lâÌn 2 ðêÒ bãìn (shoot)"
- End Sub
- Sub Goc_Power()
- Picture1.Line (10, 10)-(X, Y)
- Picture1.CurrentX = vitriX - 5: Picture1.CurrentY = vitriY + 5
- Picture1.Print "power: " & Power
- Picture1.CurrentX = vitriX + 5: Picture1.CurrentY = vitriY - 5
- Picture1.Print "goìc: " & Goc
- End Sub
- Private Sub Fire()
- Const Gravity! = 10
- Shotting = True
- Picture1.Cls
- GioiThieu
- Goc_Power
- VeDonVi
- Dim i&: i = sMau(Int(Rnd * 7))
- Picture1.ForeColor = i
- Picture1.CurrentX = 10
- Picture1.CurrentY = 10
- Dim dTime#, X!, Y!, Get_Time!, Z!
- X = 10 'Xo
- Y = 10 'Yo
- Get_Time = GetTickCount
- Do While Y
- If Y <= 0 Then
- Picture1.CurrentX = 250
- Picture1.CurrentY = 170
- Picture1.Print "ThõÌi gian ðaòn bay: " & Format(dTime / 4, "0.#") & " giây"
- Picture1.CurrentX = 250
- i = Power * Sin(Rads(Goc)) * (dTime / 2) - 0.5 * Gravity * ((dTime / 2) ^ 2) + 10 '+10 = Ðiêm Yo
- Picture1.Print "Ðaòn bay cao nhâìt: " & i & " m"
- Picture1.CurrentX = 250
- Picture1.Print "Ðaòn bay xa: " & Int(X) & " m"
- Exit Do
- End If
- DoEvents
- Z = 4 * 0.001
- dTime = Z * (GetTickCount - Get_Time)
- X = Power * Cos(Rads(Goc)) * dTime + 10 '+10 = Ðiêm Xo
- Y = Power * Sin(Rads(Goc)) * dTime - 0.5 * Gravity * (dTime ^ 2) + 10 '+10 = Ðiêm Yo
- Picture1.Line -(X, Y)
- Loop
- Shotting = False '' Câu sau là diêu kiên shoot hit the aim
- If (Int(X) > Int(Pic3.Left) + 1) And (Int(X) <= Int(Pic3.Left) + Int(Pic3.Width) + 3) Then
- Trung = True
- Picture1.CurrentX = 200
- Picture1.CurrentY = 105
- Label1.Caption = "ÐaÞ bãìn truìng!"
- 'Tính Diêm
- Dim Diêm%: Diêm = 3 + (6 - LanBan)
- Tông = Tông + Diêm
- Else
- Label1.Caption = "CoÌn " & (6 - LanBan) / 2 & " lâÌn bãìn"
- End If
- Label2.Caption = "ÐiêÒm: " & Tông
- Label2.Visible = True
- Label1.Visible = True
- If ((6 - LanBan) / 2 = 0) And (Trung = False) Then
- Command1.Visible = True
- Command1.SetFocus
- End If
- End Sub
- Private Function sMau&(màu As Integer)
- Select Case màu
- Case 0: sMau = &HFF0000
- Case 1: sMau = &H800000
- Case 2: sMau = &HC0&
- Case 3: sMau = &HC000C0
- Case 4: sMau = &H40C0&
- Case 5: sMau = &H8000&
- Case 6: sMau = &H404000
- End Select
- End Function
- Sub XeChay(Optional ByVal level As Byte = 1)
- Dim Them%
- Select Case level
- Case 1
- If Int(Rnd * 2) Then Them = Int(Rnd * 35) Else Them = -Int(Rnd * 35)
- Case 2
- If Int(Rnd * 2) Then Them = Int(Rnd * 75) Else Them = -Int(Rnd * 100)
- Case 3
- If Int(Rnd * 2) Then Them = Int(Rnd * 150) Else Them = -Int(Rnd * 150)
- End Select
- Pic3.Left = Pic3.Left + Them
- End Sub
- Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
- If Shotting Or Command1.Visible Then Exit Sub
- Label1.Visible = False: Label2.Visible = False
- LanBan = LanBan + 1
- If LanBan Mod 2 = 1 Then XeChay
- If Trung Then
- LanBan = 1
- Trung = False
- End If
- If Ve = True Then Ve = False Else Ve = True
- End Sub
- Private Sub Picture1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
- If Shotting Or Command1.Visible Then Exit Sub
- Dim XY#, Singocdoi#
- If Ve Then
- Picture1.Cls
- GioiThieu
- Picture1.Line (10, 10)-(X, Y)
- VeDonVi
- XY = Sqr((X - 10) ^ 2 + (Y - 10) ^ 2)
- Power = Int(XY)
- Singocdoi = (Y - 10) / XY
- Goc = -Int(RadtoDeg(ArcSin(-Singocdoi)))
- Goc_Power
- Else
- X = vitriX: Y = vitriY
- End If
- vitriX = X: vitriY = Y
- End Sub
- Private Sub Picture1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
- If Shotting Or Command1.Visible Then Exit Sub
- If Ve = False Then Fire
- End Sub
- Function ArcSin(trisoSin As Double) As Double ' Chuyên sin sang Góc (Radian)
- Dim Z#: Z = Sqr(1 - trisoSin * trisoSin)
- If Abs(Z) <> 0 Then
- ArcSin = Atn(trisoSin / Z)
- Else
- ArcSin = PI / 2 ' code truongphu
- End If
- End Function
- Function RadtoDeg(Rad) As Double 'Chuyen radian sang degree
- RadtoDeg = Rad * 180 / PI
- End Function
- Private Function Rads(ByVal Degree As Single) As Double ' Convert Degrees to Radian
- Rads = Degree / 180 * PI
- End Function
Project:
- Game ban pháo - truongphu.rar
- (49.68 KiB) Đã tải 160 lần