模拟一个小球在屏幕上匀速直线运动,当小球碰到屏幕第四个边时便会弹回,用QBASIC怎么编程序
来源:百度知道 编辑:UC知道 时间:2024/05/12 04:38:27
首先创建一个不规则形状的窗口,网上很多例子.
然后声明2个整数变量CX,CY和两个Boolean 变量ToLeft,ToTop
窗口上添加一个Timer控见.
添加如下代码:
Private sub Timer1_timer()
if cx<=0 Then
toleft=true
else
toleft=false
end if
if cy<=0 then
totop=false
else
totop=true
end if
if toleft then
cx=cx-10
else
cx=cx+10
end if
if totop then
cy=cy-10
else
cy=cy+10
end if
move cx,cy
end sub