Yahoo奇摩知識+ 將於 2021 年 5 月 4 日 (美國東部時間) 終止服務。自 2021 年 4 月 20 日 (美國東部時間) 起,Yahoo奇摩知識+ 網站將會轉為唯讀模式。其他 Yahoo奇摩產品與服務或您的 Yahoo奇摩帳號都不會受影響。如需關於 Yahoo奇摩知識+ 停止服務以及下載您個人資料的資訊,請參閱說明網頁。
滑鼠控制VB物件移動
就像是 打磚塊遊戲ㄧ樣
滑鼠移動可以控制下面的板子
用VB6 要怎麼寫??
那個板子要用哪個物件?
我現在已經寫出 球的反彈
就差這個了
有大大可以交一下嗎
請問阿旺 先生
有辦法能讓球 碰到木版就回彈嗎?
1 個解答
- ㄚ旺Lv 51 0 年前最佳解答
1.加入一個Shape1
2.把以下程式碼放上去
Private Sub Form_Load()
Shape1.FillStyle = 0
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Shape1.Top = Me.Height - 1000
Shape1.Left = X - Shape1.Width / 2
End Sub
2009-06-14 17:23:45 補充:
由於你的發問交付票選比例相當高.有點不太想回答.這個是我以前寫的範例.拿出來給你參考一下.
若是有其他想法自己想方法修改.
執行結果不是你要的,或是超過一天沒有回應,留言一下我會把他刪除掉.
1.貼上一個 Timer component 名為 Timer1
2.貼上一個 Shape component 名為 Shape1
3.貼上一個 Shape component 名為 Shape2
4.將以下程式碼貼上
Dim x As Long
Dim y As Long
Private Sub Form_Load()
Shape1.FillStyle = 0
Shape1.Width = 1500
Shape1.Height = 300
Shape2.FillStyle = 0
Shape2.Width = 100
Shape2.Height = 100
Shape2.BackColor = &HFF&
Shape2.Shape = 3
Me.Width = 12000
Me.Height = 9000
Timer1.Interval = 25 ' 速度
x = -160
y = -200
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
Shape1.Top = Me.Height - 1000
Shape1.Left = x - Shape1.Width / 2
End Sub
Private Sub Timer1_Timer()
Dim i As Long
Dim p As Long
Shape2.Top = Shape2.Top + y
Shape2.Left = Shape2.Left + x
' 判斷左右上邊界
If Shape2.Top < 0 Then
y = -y
Shape2.Top = Shape2.Top + y
Beep
End If
If Shape2.Left < 0 Or Shape2.Left + Shape2.Width + 100 > Me.Width Then
x = -x
Shape2.Left = Shape2.Left + x
Beep
End If
' 判斷 bar 碰撞
i = Shape2.Top + Shape2.Height
If i > Shape1.Top And i < Shape1.Top + Shape1.Height Then
i = Shape2.Left + Shape2.Width / 2
p = 0
If i > Shape1.Left And i < Shape1.Left + Shape1.Width Then
p = Int((i - Shape1.Left) * 9 / Shape1.Width) - 4
x = IIf(p, p * 60, IIf(x > 30, 30, -30))
y = -(360 - Abs(x))
Beep
End If
End If
' 判斷結束
If Shape2.Top > Me.Height Then
MsgBox "end"
End
End If
End Sub
若這結果不是你要的,請勿交付票選,我會把他先刪除掉