扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
Const D = 100 '方格的宽度 Const BT = 3000 '跑道底部的y坐标 Dim l1(22) As Integer '每层跑道左边有几个方块 Dim l2(22) As Integer '每层跑道右边有几个方块 Dim cx As Single '赛车的在x轴的位置 Private Sub Command1_Click() cx = Width / 2 - 3 * D / 2 cy = Height - D drawcar For i = 1 To 20 l1(i) = 0 l2(i) = 0 drawway (i) Next i Timer1.Enabled = True End Sub Private Sub drawcar() Line (cx, BT - 100)-Step(3 * D, D), BackColor, BF Line (cx + D, BT - 200)-Step(D, D), BackColor, BF '先擦 Line (cx, BT - 100)-Step(3 * D, D), RGB(225, 0, 0), BF Line (cx + D, BT - 200)-Step(D, D), RGB(225, 0, 0), BF End Sub Private Sub drawway(n) Line (Width/2-3*D/2-2*D,BT-n*D)-Step(7*D,D),BackColor, BF '先擦后画 Line (Width/2-3*D/2-2*D,BT-n*D)-Step(l1(n)*D, D), ,BF Line (Width/2-3*D/2+5*D,BT-n*D)-Step(-l2(n)*D,D), ,BF End Sub Private Sub Form_KeyPress(KeyAscii As Integer) Select Case KeyAscii Case Asc("a"), Asc("A") cx = cx - D Case Asc("s"), Asc("S") cx = cx + D End Select End Sub Private Sub Timer1_Timer() Randomize For i = 1 To 19 l1(i) = l1(i + 1) l2(i) = l2(i + 1) drawway (i) Next i Do l1(20) = Int(Rnd * 5) l2(20) = Int(Rnd * 5) Loop Until ((l1(20) + l2(20) <= 4) And (l1(20) - l1(19) <= 1) And _ (l2(20) - l2(19) <= 1) And (l1(19) + l2(20) <= 4) And _ (l1(20) + l2(19) <= 4)) '这里生成新一层跑道, '注意要筛去玩家不可能通过的情况! drawway (20) '以上画出跑道 drawcar test End Sub Private Sub test() If 3.5*D-Width/2+cx<l1(1)*D Then Timer1.Enabled=False If 3.5*D-Width/2+cx+D<l1(2)*D Then Timer1.Enabled=False If 3.5*D-(cx+3*D-Width/2)<l2(1)*D Then Timer1.Enabled=False If 3.5*D-(cx+2*D-Width/2)<l2(2)*D Then Timer1.Enabled=False End Sub |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者