|
>もう一つのボタンをボールのように跳ねさして、
フツーに考えると落下かピンボールっぽい動きかな?
↓単純なやつ
Option Explicit
Private Declare Sub Sleep Lib "KERNEL32.dll" (ByVal dwMilliseconds As Long)
Public fh As Long
Public fw As Long
Public tsleep As Long
Private Sub UserForm_Initialize()
fh = Me.InsideHeight
fw = Me.InsideWidth
tsleep = 10
Me.CommandButton1.Caption = "徘徊"
Call btr
End Sub
Private Sub CommandButton1_Click()
If Me.CommandButton1.Caption = "徘徊" Then
Call bttest1
ElseIf Me.CommandButton1.Caption = "落下" Then
Call bttest2
ElseIf Me.CommandButton1.Caption = "ピンボール" Then
Call bttest3
End If
End Sub
Function bts()
Me.CommandButton1.Height = 20
Me.CommandButton1.Width = 20
Me.CommandButton1.Caption = "■"
End Function
Function btr()
Me.CommandButton1.Height = 25
Me.CommandButton1.Width = 60
Me.CommandButton1.Top = (fh / 2) - 12
Me.CommandButton1.Left = (fw / 2) - 30
End Function
Function bst(x As Long, y As Long)
DoEvents
Me.CommandButton1.Left = x
Me.CommandButton1.Top = y
Sleep tsleep
End Function
Function bttest1()
Dim bt1w As Long, bt1h As Long, x As Long, y As Long
Call bts
bt1w = Me.CommandButton1.Width
bt1h = Me.CommandButton1.Height
x = 1
y = 1
For x = 1 To (fw - bt1w)
Call bst(x, y)
Next x
For y = 1 To (fh - bt1h)
Call bst(x, y)
Next y
For x = (fw - bt1w) To 1 Step -1
Call bst(x, y)
Next x
For y = (fh - bt1h) To 1 Step -1
Call bst(x, y)
Next y
Call btr
Me.CommandButton1.Caption = "落下"
End Function
Function bttest2()
Dim bt1w As Long, bt1h As Long, lfw As Long, lfh As Long, _
cf1 As Double, cf2 As Double, cf3 As Double, x As Double, y As Double
Call bts
bt1w = Me.CommandButton1.Width
bt1h = Me.CommandButton1.Height
lfw = fw - bt1w
lfh = fh - bt1h
cf1 = lfh / ((lfw / 3) * (lfw / 3))
cf2 = (lfh / 2) / ((lfw / 6) * (lfw / 6))
cf3 = (lfh / 4) / ((lfw / 6) * (lfw / 6))
x = 1
y = 1
For x = 1 To lfw / 3
y = cf1 * x * x
Call bst(CLng(x), CLng(y))
Next x
For x = lfw / 3 To lfw / 3 * 2
y = (cf2 * (x - (lfw / 2)) * (x - (lfw / 2))) + (lfh / 2)
Call bst(CLng(x), CLng(y))
Next x
For x = lfw / 3 * 2 To lfw
y = (cf3 * (x - (lfw * 5 / 6)) * (x - (lfw * 5 / 6))) + (lfh * 3 / 4)
Call bst(CLng(x), CLng(y))
Next x
Call btr
Me.CommandButton1.Caption = "ピンボール"
End Function
Function bttest3()
Dim bt1w As Long, bt1h As Long, lfw As Long, lfh As Long, i As Long, _
x As Long, y As Long, px As Long, py As Long
Call bts
bt1w = Me.CommandButton1.Width
bt1h = Me.CommandButton1.Height
lfw = fw - bt1w
lfh = fh - bt1h
x = 1
y = 1
For i = 1 To 1000
If x = lfw Then
px = -1
ElseIf x = 1 Then
px = 1
End If
If y = lfh Then
py = -1
ElseIf y = 1 Then
py = 1
End If
x = x + px
y = y + py
Call bst(x, y)
Next i
Call btr
Me.CommandButton1.Caption = "徘徊"
End Function
|
|