[例题]一个圆在窗体内规则运动[类似浮动广告条]

 =========cike例题===========

name = 弹动的小圆

窗体=1个圆  1个时间

设置:把Shape设置成圆 时间间隔=20

代码:

==================================

 

Dim  下右  As   Boolean
Dim  下左  As   Boolean
Dim  上右  As   Boolean
Dim  上左  As   Boolean   ' 定义方向

Private   Sub  Form_Load()
Randomize     '  这里让圆随机方向移动
=   Int ( Rnd   *   4 )

If  a  =   0   Then  上左  =   False : 上右  =   False : 下左  =   False : 下右  =   True
If  a  =   1   Then  上左  =   False : 上右  =   False : 下左  =   True : 下右  =   False
If  a  =   2   Then  上左  =   False : 上右  =   True : 下左  =   False : 下右  =   False
If  a  =   3   Then  上左  =   True : 上右  =   False : 下左  =   False : 下右  =   False


End Sub

Private   Sub  Timer1_Timer()   ' 移动过程
=  Shape1.Left              ' 提取当前x
=  Shape1.Top               ' 提取当前y
If  下右  =   True   And  x  +  Shape1.Width  >  Me.Width  -   140   Then  下左  =   True : 下右  =   False   ' 若方向是 下右 并且碰到 右边 则向 下左
If  下右  =   True   And  y  +  Shape1.Width  >  Me.Height  -   500   Then  上右  =   True : 下右  =   False   ' 若方向是 下右 并且碰到 下边 则向 上右
If  上右  =   True   And  x  +  Shape1.Width  >  Me.Width  -   140   Then  上右  =   False : 上左  =   True   '  类推....
If  上右  =   True   And  y  <   0   Then  上右  =   False : 下右  =   True
If  上左  =   True   And  x  <   0   Then  上左  =   False : 上右  =   True
If  上左  =   True   And  y  <   0   Then  上左  =   False : 下左  =   True
If  下左  =   True   And  y  +  Shape1.Width  >  Me.Height  -   500   Then  下左  =   False : 上左  =   True
If  下左  =   True   And  x  <   0   Then  下左  =   False : 下右  =   True
If  上左  =   True   Then  x  =  x  -   30 : y  =  y  -   30    ' 判断是什么方向 就怎么移动
If  上右  =   True   Then  x  =  x  +   30 : y  =  y  -   30
If  下左  =   True   Then  x  =  x  -   30 : y  =  y  +   30
If  下右  =   True   Then  x  =  x  +   30 : y  =  y  +   30
Shape1.Move x, y   
' 使用move 函数 移动
End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值