当前位置:主页 > 资讯 > 如何用vb写赛车游戏

如何用vb写赛车游戏

文章来源:www.cnqiqu.com 作者:启趣网 发布时间:2024-12-13 19:18

如何用vb写赛车游戏

下面是全部源代码,窗体上只需放个按钮Command1就行了!

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

求能放在YY公告上的小游戏代码

[image][image][flash] |600|400[/flash]|400|300[/flash]|380|200[/image]|380|200[/image] 这个我觉得还不错 你去试试吧

  • 热门攻略