Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dim startX, startY '紀錄拋物線開始座標
- Dim offsetX, offsetY '第四題可能會用到
- Private Sub Command1_Click()
- Timer1.Interval = 100
- Label3 = 0
- startX = Image1.Left
- startY = Image1.Top
- End Sub
- '第二題之2,完成碰撞副程式
- Public Function IsImpact(ByVal Obj1 As Object, ByVal Obj2 As Object) As Boolean
- Dim xScale As Boolean, yScale As Boolean
- If (Obj1.Left >= Obj2.Left And Obj1.Left <= Obj2.Left + Obj2.Width) Then
- xScale = True
- End If
- '2-2仿照上面寫top height
- If (Obj1.Top >= Obj2.Top And Obj1.Top <= Obj2.Top + Obj2.Height) Then
- xScale = True
- End If
- '2-3仿照下面寫left width
- If (Obj1.Left + Obj1.Width >= Obj2.Left And Obj1.Left + Obj1.Width <= Obj2.Left + Obj2.Width) Then
- yScale = True
- End If
- If (Obj1.Top + Obj1.Height >= Obj2.Top And Obj1.Top + Obj1.Height <= Obj2.Top + Obj2.Height) Then
- yScale = True
- End If
- IsImpact = xScale And yScale
- End Function
- Private Sub Timer1_Timer()
- '第一題
- Label3 = Label3 + 1
- Label1 = Text1 * Label3
- Label2 = Text2 * Label3 - 1 / 2 * 9.8 * Label3 * Label3
- Image1.Left = startX + Label1
- Image1.Top = startY - Label2
- '第二題之1,碰撞加分,小豬消失,之2之3請完成上面的isimpact副程式
- If IsImpact(Image1, Image2) = True And Image2.Visible = True Then
- Label6 = Label6 + 1
- Image2.Visible = False
- End If
- '第三題,原點轉移,觸地反彈,水平速度<20就停止,重新開始
- If Image1.Top + Image1.Height > Form1.ScaleHeight Then
- startX = Image1.Left
- startY = Form1.ScaleHeight - Image1.Height
- Text1 = Text1 / 2
- Text2 = Text2 / 2
- Label3 = 0
- If Text1 < 20 Then
- Timer1.Interval = 0
- Image1.Left = Shape1.Left
- Image1.Top = Shape1.Top
- Image2.Visible = True
- Image2.Left = 5000 + 3000 * Rnd
- Image2.Top = Form1.ScaleHeight - Image2.Height
- Text1 = 100 + Rnd * 100
- Text2 = 100 + Rnd * 100
- End If
- End If
- End Sub
- '第四題,拖曳施力,水平速度text1=拖曳的水平位移/3,垂直速度text2=拖曳的垂直位移/3
- Private Sub Form_DragOver(Source As Control, X As Single, Y As Single, State As Integer)
- Text1 = (Shape1.Left - (X - offsetX)) / 3
- Text2 = ((Y - offsetY) - Shape1.Top) / 3
- End Sub
- Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
- Text1 = (Shape1.Left - (X - offsetX)) / 3
- Text2 = ((Y - offsetY) - Shape1.Top) / 3
- Source.Move X - offsetX, Y - offsetY
- Source.Drag vbEndDrag
- Command1_Click
- End Sub
- Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
- If Button = 1 Then
- offsetX = X
- offsetY = Y
- Image1.Drag vbBeginDrag
- End If
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement