技术宅的结界

 找回密码
 立即注册→加入我们

QQ登录

只需一步,快速开始

搜索
热搜: 下载 VB C 实现 编写
查看: 1396|回复: 3
收起左侧

【VB】两百行代码给你撸个生死时速

[复制链接]

85

主题

263

帖子

3643

积分

用户组: 管理员

No. 418

UID
418
精华
13
威望
52 点
宅币
1969 个
贡献
1242 次
宅之契约
0 份
在线时间
252 小时
注册时间
2014-8-9
发表于 2014-12-20 01:34:16 | 显示全部楼层 |阅读模式

欢迎访问技术宅的结界,请注册或者登录吧。

您需要 登录 才可以下载或查看,没有帐号?立即注册→加入我们

x
捕获.JPG
技术不宅老C给你用200多行VB代码撸个小游戏
大家来吐槽2d碰撞检测,蛤蛤蛤,谁说vb不适合开发游戏蟆~~
[Visual Basic] 纯文本查看 复制代码
Option Explicit

Dim mySpeed         As Integer
Dim myHP            As Integer
Dim nailVisible     As Boolean
Dim lightingVisible As Boolean
'Dim showNailTime    As Long
'Dim showLigTime     As Long
Dim raceTime        As Double

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    'MsgBox KeyCode
    If (KeyCode = 38) Or (KeyCode = 87) Then
        TimUp.Enabled = True
    End If
    If (KeyCode = 40) Or (KeyCode = 83) Then
        TimDown.Enabled = True
    End If
    If (KeyCode = 39) Or (KeyCode = 68) Then
        mySpeed = 75
    End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
    If (KeyCode = 39) Or (KeyCode = 68) Then
        mySpeed = 50
    End If
End Sub

Private Sub Form_Load()
    Randomize
    mySpeed = 50
    myHP = 100
    nailVisible = False
    lightingVisible = False
    'showLigTime = Int(Rnd() * 5 + 1)
    'showNailTime = Int(Rnd() * 5 + 1)
    TimShowNail.Interval = Int(Rnd() * 5 + 1)
    TimShowLig.Interval = Int(Rnd() * 5 + 1)
    raceTime = 0
End Sub

Private Sub MuAbout_Click()
    MsgBox "VGT v1.0 Demo" & vbCrLf & "Created By Cyycoish,漫天飞雪 0711" & vbCrLf & "Copyright (C) Ctechnology 2012", , "VGT Demo"
End Sub

Private Sub MuExit_Click()
    End
End Sub

Private Sub MuStart_Click()
    Randomize
    ImgBike2.Left = 120
    ImgBike2.Top = 1080
    ImgBike1.Top = 600
    ImgBike1.Left = 3960
    ImgGov.Left = 2880
    ImgGov.Top = 2400
    
    Label1.Caption = "HP:100%"
    Label6.Caption = "Race time:0s"
    
    mySpeed = 50
    myHP = 100
    nailVisible = False
    lightingVisible = False
    'showLigTime = Int(Rnd() * 5 + 1)
    'showNailTime = Int(Rnd() * 5 + 1)
    TimShowNail.Interval = Int(Rnd() * 5 + 1)
    TimShowLig.Interval = Int(Rnd() * 5 + 1)
    raceTime = 0
    
    TimBack.Enabled = True
    TimClo.Enabled = True
    TimShowNail.Enabled = True
    TimShowLig.Enabled = True
    Timer1.Enabled = True
End Sub

Private Sub TimBack_Timer()
    ImgBack.Left = ImgBack.Left - mySpeed
    If ImgBack.Left <= (-1 * ImgBack.Width / 2) Then
        ImgBack.Left = 0
    End If
    If ImgNail.Visible = True Then
        ImgNail.Left = ImgNail.Left - mySpeed
        If ImgNail.Left <= -1 * (ImgNail.Width) Then
            ImgNail.Visible = False
        End If
        If ((1560 = ImgNail.Top) And ((ImgBike1.Top >= 600) And (ImgBike1.Top <= 780))) And ((ImgBike1.Left <= ImgNail.Left) And (ImgNail.Left <= ImgBike1.Left + ImgBike1.Width)) Then
            ImgNail.Visible = False
            myHP = myHP - 25
            mySpeed = 50
            Label1.Caption = "HP:" & myHP & "%"
            If 0 = myHP Then
                TimBack.Enabled = False
                TimClo.Enabled = False
                TimUp.Enabled = False
                TimDown.Enabled = False
                TimGO.Enabled = True
                Timer1.Enabled = False
            End If
        End If
        If ((1920 = ImgNail.Top) And ((ImgBike1.Top >= 780) And (ImgBike1.Top <= 1080))) And ((ImgBike1.Left <= ImgNail.Left) And (ImgNail.Left <= ImgBike1.Left + ImgBike1.Width)) Then
            ImgNail.Visible = False
            myHP = myHP - 25
            mySpeed = 50
            Label1.Caption = "HP:" & myHP & "%"
            If 0 = myHP Then
                TimBack.Enabled = False
                TimClo.Enabled = False
                TimUp.Enabled = False
                TimDown.Enabled = False
                TimGO.Enabled = True
                Timer1.Enabled = False
            End If
        End If
        
        'Label3.Caption = ImgNail.Left
    End If
    
    If ImgLig.Visible = True Then
        ImgLig.Left = ImgLig.Left - mySpeed
        If ImgLig.Left <= -1 * (ImgLig.Width) Then
            ImgLig.Visible = False
        End If
        If ((1560 = ImgLig.Top) And ((ImgBike1.Top >= 600) And (ImgBike1.Top <= 780))) And ((ImgBike1.Left <= ImgLig.Left) And (ImgLig.Left <= ImgBike1.Left + ImgBike1.Width)) Then
            ImgLig.Visible = False
            mySpeed = 100
            TimLig.Enabled = True
        End If
        If ((1920 = ImgLig.Top) And ((ImgBike1.Top >= 780) And (ImgBike1.Top <= 1080))) And ((ImgBike1.Left <= ImgLig.Left) And (ImgLig.Left <= ImgBike1.Left + ImgBike1.Width)) Then
            ImgLig.Visible = False
            mySpeed = 100
            TimLig.Enabled = True
        End If
    End If
    
    ImgBike2.Left = ImgBike2.Left + (65 - mySpeed)
    If ImgBike2.Left >= ImgBike1.Left Then
        TimBack.Enabled = False
        TimClo.Enabled = False
        TimUp.Enabled = False
        TimDown.Enabled = False
        TimGO.Enabled = True
        Timer1.Enabled = False
    End If
    Label2.Caption = "Map Position:" & ImgBack.Left
End Sub

Private Sub TimClo_Timer()
    ImgClo.Left = ImgClo.Left - 50
    If ImgClo.Left <= (-1 * ImgClo.Width) Then
        ImgClo.Left = Me.ScaleWidth
    End If
End Sub

Private Sub TimDown_Timer()
    TimUp.Enabled = False
    If ImgBike1.Top >= 1080 Then
        TimDown.Enabled = False
        Exit Sub
    End If
    ImgBike1.Top = ImgBike1.Top + 10
End Sub

Private Sub Timer1_Timer()
    raceTime = raceTime + 0.1
    Label6.Caption = "Race Time:" & Format(CStr(raceTime), "0.0") & "s"
End Sub

Private Sub TimGO_Timer()
    If ImgGov.Top <= 840 Then
        TimGO.Enabled = False
        Exit Sub
    End If
    ImgGov.Top = ImgGov.Top - 10
End Sub

Private Sub TimLig_Timer()
    mySpeed = 50
    TimLig.Enabled = False
End Sub

Private Sub TimShowLig_Timer()
    Randomize
    TimShowLig.Interval = Int(Rnd() * 5 + 1)
    If ImgLig.Visible = False Then
        Call ResetLightingPlace(((Int(Rnd() * 10) Mod 2)) = 0)
        ImgLig.Visible = True
    End If
End Sub

Private Sub TimShowNail_Timer()
    Randomize
    'Dim uDN As Boolean
    'uDN = (((Int(Rnd() * 10) Mod 2)) = 0)
    TimShowNail.Interval = Int(Rnd() * 5 + 1)
    If ImgNail.Visible = False Then
        Call ResetNailPlace(((Int(Rnd() * 10) Mod 2)) = 0)
        ImgNail.Visible = True
    End If
    'Label4.Caption = TimShowNail.Interval
End Sub

Private Sub TimUp_Timer()
    TimDown.Enabled = False
    If ImgBike1.Top <= 600 Then
        TimUp.Enabled = False
        Exit Sub
    End If
    ImgBike1.Top = ImgBike1.Top - 10
End Sub

Private Sub ResetNailPlace(upOrDown As Boolean)
    If upOrDown = True Then
        ImgNail.Left = 9600
        ImgNail.Top = 1560
    Else
        ImgNail.Left = 9600
        ImgNail.Top = 1920
    End If
End Sub

Private Sub ResetLightingPlace(upOrDown As Boolean)
    If upOrDown = True Then
        ImgLig.Left = 9600
        ImgLig.Top = 1560
    Else
        ImgLig.Left = 9600
        ImgLig.Top = 1920
    End If
End Sub


vgtr.zip (93.89 KB, 下载次数: 30)

评分

参与人数 1威望 +5 贡献 +10 收起 理由
0xAA55 + 5 + 10 支持!

查看全部评分

In the beginning I was not the best.
And the world was also not the best.
But I still know that I am who I am.
Because I think that it is good.
I have been working hard.
I have been keeping growth with the world.
And it was so.

0

主题

13

帖子

18

积分

用户组: 初·技术宅

UID
606
精华
0
威望
2 点
宅币
1 个
贡献
0 次
宅之契约
0 份
在线时间
0 小时
注册时间
2014-12-21
发表于 2014-12-21 06:52:33 | 显示全部楼层
新人正在学习中

1

主题

40

帖子

127

积分

用户组: 小·技术宅

UID
4683
精华
0
威望
0 点
宅币
87 个
贡献
0 次
宅之契约
0 份
在线时间
14 小时
注册时间
2019-2-11
发表于 2019-5-10 21:03:55 | 显示全部楼层
哈哈哈。
回复

使用道具 举报

0

主题

3

帖子

21

积分

用户组: 初·技术宅

UID
4899
精华
0
威望
0 点
宅币
18 个
贡献
0 次
宅之契约
0 份
在线时间
2 小时
注册时间
2019-4-30
发表于 2019-5-10 21:36:08 | 显示全部楼层
下载体验一下

本版积分规则

QQ|申请友链||Archiver|手机版|小黑屋|技术宅的结界 ( 滇ICP备16008837号|网站地图

GMT+8, 2019-7-20 05:27 , Processed in 0.102310 second(s), 35 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表