cyycoish 发表于 2014-12-20 01:34:16

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


技术不宅老C给你用200多行VB代码撸个小游戏
大家来吐槽2d碰撞检测,蛤蛤蛤,谁说vb不适合开发游戏蟆~~
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



wypabcd 发表于 2014-12-21 06:52:33

新人正在学习中

Ink_Hin_fifteen 发表于 2019-5-10 21:03:55

哈哈哈。

巴跋丷霸 发表于 2019-5-10 21:36:08

下载体验一下

imr2013 发表于 2022-11-23 23:44:08

支持楼主,体验一把!

Proxy 发表于 2023-4-4 15:18:29

这不是忍者神龟那个。。
页: [1]
查看完整版本: 【VB】两百行代码给你撸个生死时速