
左
then
'
向左运动
x1=x1+1
end
if
if
右
then
'
向右运动
x1=x1-1
end
if
if
上
then
'
向上运动
y1=y1+1
'
使用自定义
坐标系统
有统一的坐标转换过程
end
if
if
下
then
'
向下运动
y1=y1-1
end
if
''达到最大边界后判断处理过程,回原始位置再来
还是
向反方向走
''
我只会左右反d球。 S1是ShapePrivate Sub Timer1_Timer()
Static s
If S1.Left >= Form1.Width - S1.Width And s = 2 Then s = 0
If S1.Left <= 0 And s = 0 Then s = 2
If s = 0 Then S1.Left = S1.Left - 100
If s = 2 Then S1.Left = S1.Left + 100
End Sub
题目没有看清··我做的是个以窗体为背景的反d球,你只要拿去改一下就好了··呵呵··蛮有意思的···Option Explicit
Dim flag As Boolean, vx As Single, vy As Single
Private Sub Form_Click()
If flag = False Then
Randomize
vx = Rnd * (-1) ^ Int(Rnd * 2)
Randomize
vy = Rnd * (-1) ^ Int(Rnd * 2)
End If
flag = True
Timer1.Enabled = Not Timer1.Enabled
Form1.Caption = IIf(Timer1.Enabled, "点击屏幕开始", "点击屏幕暂停")
End Sub
Private Sub Form_Load()
Shape1.Shape = 3
Shape1.FillStyle = 0
Shape1.FillColor = vbRed
End Sub
Private Sub Timer1_Timer()
Shape1.Left = Shape1.Left + vx * 50
Shape1.Top = Shape1.Top + vy * 50
If Shape1.Left <0 Or Shape1.Left + Shape1.Width >Form1.Width Then vx = -1 * vx
If Shape1.Top <0 Or Shape1.Top + Shape1.Height >Form1.ScaleHeight Then vy = -1 * vy
End Sub
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)