VB程序:画一个圆在在form1上,单机按钮后,球能沿着45度的方向运动.碰到边以后就往相反方向运动.timer1.interval的值为100.轨迹为45度直线
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 03:19:04
VB程序:画一个圆在在form1上,单机按钮后,球能沿着45度的方向运动.碰到边以后就往相反方向运动.timer1.interval的值为100.轨迹为45度直线
VB程序:画一个圆在在form1上,单机按钮后,球能沿着45度的方向运动.碰到边以后就往相反方向运动.
timer1.interval的值为100.
轨迹为45度直线
VB程序:画一个圆在在form1上,单机按钮后,球能沿着45度的方向运动.碰到边以后就往相反方向运动.timer1.interval的值为100.轨迹为45度直线
'不知道有没有理解你的意思
Private dx As Integer, dy As Integer, stp As Integer, ox As Integer, oy As Integer, rad As Integer
Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Form_Load()
Me.ScaleMode = 3
Me.FillStyle = 0
Me.FillColor = vbYellow
Me.AutoRedraw = True
ox = 100: oy = 100: rad = 10
Me.Circle (ox, oy), rad, vbRed
dx = 1: dy = -1: stp = 10
Timer1.Interval = 100
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Me.Cls
ox = ox + dx * stp: oy = oy + dy * stp
Dim l As Integer, r As Integer, t As Integer, b As Integer
l = ox - rad: r = ox + rad: t = oy - rad: b = oy + rad
If l + dx * stp = Me.ScaleWidth Then ox = Me.ScaleWidth - rad
If t + dy * stp = Me.ScaleHeight Then oy = Me.ScaleHeight - rad
Me.Circle (ox, oy), rad, vbRed
Dim i As Integer: i = -1 * Sgn(dx * dy)
If ox = rad Then dx = 1: dy = i * dx
If ox = Me.ScaleWidth - rad Then dx = -1: dy = i * dx
If oy = rad Then dy = 1: dx = i * dy
If oy = Me.ScaleHeight - rad Then dy = -1: dx = i * dy
End Sub