# Angry Bird

Jul 7th, 2021
491
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. Dim startX, startY  '紀錄拋物線開始座標
2. Dim offsetX, offsetY  '第四題可能會用到
3. Private Sub Command1_Click()
4.     Timer1.Interval = 100
5.     Label3 = 0
6.     startX = Image1.Left
7.     startY = Image1.Top
8. End Sub
9.
10. '第二題之2，完成碰撞副程式
11. Public Function IsImpact(ByVal Obj1 As Object, ByVal Obj2 As Object) As Boolean
12.     Dim xScale As Boolean, yScale As Boolean
13.     If (Obj1.Left >= Obj2.Left And Obj1.Left <= Obj2.Left + Obj2.Width) Then
14.         xScale = True
15.     End If
16.     '2-2仿照上面寫top height
17.    If (Obj1.Top >= Obj2.Top And Obj1.Top <= Obj2.Top + Obj2.Height) Then
18.         xScale = True
19.     End If
20.
21.     '2-3仿照下面寫left width
22.    If (Obj1.Left + Obj1.Width >= Obj2.Left And Obj1.Left + Obj1.Width <= Obj2.Left + Obj2.Width) Then
23.         yScale = True
24.     End If
25.     If (Obj1.Top + Obj1.Height >= Obj2.Top And Obj1.Top + Obj1.Height <= Obj2.Top + Obj2.Height) Then
26.         yScale = True
27.     End If
28.     IsImpact = xScale And yScale
29. End Function
30.
31. Private Sub Timer1_Timer()
32.     '第一題
33.    Label3 = Label3 + 1
34.     Label1 = Text1 * Label3
35.     Label2 = Text2 * Label3 - 1 / 2 * 9.8 * Label3 * Label3
36.     Image1.Left = startX + Label1
37.     Image1.Top = startY - Label2
38.
39.     '第二題之1，碰撞加分，小豬消失，之2之3請完成上面的isimpact副程式
40.    If IsImpact(Image1, Image2) = True And Image2.Visible = True Then
41.         Label6 = Label6 + 1
42.         Image2.Visible = False
43.     End If
44.
45.     '第三題，原點轉移，觸地反彈，水平速度<20就停止，重新開始
46.    If Image1.Top + Image1.Height > Form1.ScaleHeight Then
47.         startX = Image1.Left
48.         startY = Form1.ScaleHeight - Image1.Height
49.         Text1 = Text1 / 2
50.         Text2 = Text2 / 2
51.         Label3 = 0
52.         If Text1 < 20 Then
53.             Timer1.Interval = 0
54.             Image1.Left = Shape1.Left
55.             Image1.Top = Shape1.Top
56.             Image2.Visible = True
57.             Image2.Left = 5000 + 3000 * Rnd
58.             Image2.Top = Form1.ScaleHeight - Image2.Height
59.             Text1 = 100 + Rnd * 100
60.             Text2 = 100 + Rnd * 100
61.         End If
62.
63.     End If
64. End Sub
65.
66. '第四題，拖曳施力，水平速度text1=拖曳的水平位移/3，垂直速度text2=拖曳的垂直位移/3
67. Private Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
68.     Text1 = (Shape1.Left - (X - offsetX)) / 3
69.     Text2 = ((Y - offsetY) - Shape1.Top) / 3
70.
71. End Sub
72. Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
73.     Text1 = (Shape1.Left - (X - offsetX)) / 3
74.     Text2 = ((Y - offsetY) - Shape1.Top) / 3
75.     Source.Move X - offsetX, Y - offsetY
76.     Source.Drag vbEndDrag
77.     Command1_Click
78. End Sub
79.
80. Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
81.     If Button = 1 Then
82.         offsetX = X
83.         offsetY = Y
84.         Image1.Drag vbBeginDrag
85.     End If
86. End Sub