Yahoo奇摩知識+將於 2021 年 5 月 4 日 (美國東部時間) 終止服務。自 2021 年 4 月 20 日 (美國東部時間) 起,Yahoo奇摩知識+服務將會轉為唯讀模式。其他Yahoo奇摩產品與服務或您的Yahoo奇摩帳號都不會受影響。如需關於Yahoo奇摩知識+ 停止服務以及下載您個人資料的資訊,請參閱說明網頁。

夢想 發問時間: 電腦與網際網路程式設計 · 1 0 年前

關於VB6.0程式設計

我是一個VB新手

我想做一個彈跳球的遊戲

能幫我介紹一下大概!!

跟遊戲迴圈

程式打法

能一一介紹嗎?

感激不盡

已更新項目:

抱歉我打錯了,不是彈跳球,是打磚塊= =

2 個已更新項目:

DRG可以讓他按一個東西在開始嗎?

也可以讓她重新

我想要讓他有分數

^^

拜託嘞

3 個已更新項目:

可以順便幫我解釋一下ㄇ?

可以交我用時間嗎?

3 個解答

評分
  • DRGO
    Lv 5
    1 0 年前
    最佳解答

    請先新增元件Timer

    Dim sx(4, 2) As Integer, sy(4, 2) As Integer, sv(4, 2) As Boolean

    Dim ballx As Integer, bally As Integer, lx As Integer

    Const speed = 50

    Private Sub Form_Load()

    Timer1.Interval = 20

    Me.AutoRedraw = True

    Me.Width = 6275

    Me.Height = 5415

    For i = 0 To 4

    For j = 0 To 2

    sx(i, j) = 1000 + i * 1000

    sy(i, j) = 500 + j * 400

    sv(i, j) = True

    Next j

    Next i

    ballx = Me.Width / 2: bally = Me.Height - 1000

    End Sub

    Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

    lx = X: ly = Y

    End Sub

    Private Sub Timer1_Timer()

    Static ax As Boolean, ay As Boolean

    Cls

    If ballx <= 50 Then ax = True

    If ballx >= Me.ScaleWidth - 50 Then ax = False

    If bally <= 50 Then ay = True

    If bally >= Me.ScaleHeight - 50 Then Timer1.Enabled = False: MsgBox "Game Over"

    If ax Then ballx = ballx + speed Else ballx = ballx - speed

    If ay Then bally = bally + speed Else bally = bally - speed

    Line (lx - 300, Me.ScaleHeight - 500)-(lx + 300, Me.ScaleHeight - 400), RGB(0, 0, 0), BF

    If bally + 50 >= Me.ScaleHeight - 500 And ballx + 50 >= lx - 300 And ballx - 50 <= lx + 300 Then ay = False

    For i = 0 To 4

    For j = 0 To 2

    If sv(i, j) Then

    Line (1000 + i * 1000 - 400, 500 + j * 400 - 140)-(1000 + i * 1000 + 400, 500 + j * 400 + 140), RGB(255, 0, 0), BF

    If ballx + 50 >= sx(i, j) - 400 And ballx - 50 <= sx(i, j) + 400 And bally + 50 >= sy(i, j) - 140 And bally - 50 <= sy(i, j) + 140 Then

    If ballx > sx(i, j) + 300 Then ax = True

    If ballx < sx(i, j) - 300 Then ax = False

    If bally > sy(i, j) + 100 Or bally < sy(i, j) - 100 Then ay = Not ay

    sv(i, j) = False

    End If

    End If

    Next j

    Next i

    Circle (ballx, bally), 100, RGB(0, 0, 255)

    End Sub

    參考資料: feeling
  • 1 0 年前

    啪啪啪啪啪啪啪啪啪啪啪啪啪啪啪啪.............灰常集赫....感謝..偶要把他大佳改進一下...呵呵...

  • Ev
    Lv 4
    1 0 年前

    Attribute VB_Name = "Form1"

    Attribute VB_GlobalNameSpace = False

    Attribute VB_Creatable = False

    Attribute VB_PredeclaredId = True

    Attribute VB_Exposed = False

    Private Declare Function MessageBeep Lib "user32" (ByVal wType As Long) As Long

    Dim Dh As Boolean, Dw As Boolean

    Dim Dhd, Dwd

    Private Sub Form_Activate()

    Inkey.SetFocus

    End Sub

    Private Sub Form_Load()

    Dh = True

    Dw = True

    Dhd = 4

    Dwd = 2

    End Sub

    Private Sub Form_Unload(Cancel As Integer)

    End

    End Sub

    Private Sub Inkey_KeyDown(KeyCode As Integer, Shift As Integer)

    If KeyCode = vbKeyLeft Then Command1.Left = Command1.Left - 5

    If KeyCode = vbKeyRight Then Command1.Left = Command1.Left + 5

    If Shape1.Top + Shape1.Height >= Command1.Top And (Shape1.Left >= Command1.Left And Shape1.Left <= Command1.Left + Command1.Width - Shape1.Width) Then

    If KeyCode = vbKeyLeft Then

    If Dw = True Then

    If Dwd > 2 Then Dwd = Dwd - 2

    Else

    If Dwd < 7 Then Dwd = Dwd + 2

    End If

    End If

    If KeyCode = vbKeyRight Then

    If Dw = False Then

    If Dwd > 2 Then Dwd = Dwd - 2

    Else

    If Dwd < 7 Then Dwd = Dwd + 2

    End If

    End If

    End If

    End Sub

    Private Sub Inkey_KeyPress(KeyAscii As Integer)

    KeyAscii = 0

    End Sub

    Private Sub Inkey_LostFocus()

    Inkey.SetFocus

    End Sub

    Private Sub Timer1_Timer()

    If Dh = True Then Shape1.Top = Shape1.Top + Dhd

    If Dh = False Then Shape1.Top = Shape1.Top - Dhd

    If Dw = True Then Shape1.Left = Shape1.Left + Dwd

    If Dw = False Then Shape1.Left = Shape1.Left - Dwd

    2007-05-18 19:10:57 補充:

    If Shape1.Top + Shape1.Height >= Command1.Top And (Shape1.Left >= Command1.Left And Shape1.Left <= Command1.Left + Command1.Width - Shape1.Width) Then Dh = False: Call MessageBeep(48)

    2007-05-18 19:11:04 補充:

    If Shape1.Top + Shape1.Height >= Command1.Top And (Shape1.Left + Shape1.Width >= Command1.Left And Shape1.Left < Command1.Left) Then Dh = False: Dw = False: If Dwd < 7 Then Dwd = Dwd + 5: Call MessageBeep(0)

    2007-05-18 19:11:11 補充:

    If Shape1.Top + Shape1.Height >= Command1.Top And (Shape1.Left >= Command1.Left + Command1.Width - Shape1.Width And Shape1.Left < Command1.Left + Command1.Width) Then Dh = False: Dw = True: If Dwd < 7 Then Dwd = Dwd + 5: Call MessageBeep(0)

    If Shape1.Top <= 0 Then Dh = True

    2007-05-18 19:11:17 補充:

    If Shape1.Left <= 0 Then Dw = True: Call MessageBeep(16)

    If Shape1.Left >= Picture1.ScaleWidth - Shape1.Width Then Dw = False: Call MessageBeep(16)

    2007-05-18 19:11:25 補充:

    If Shape1.Top >= Picture1.Height - Shape1.Height Then

    MsgBox "你失敗了", 16

    For N = 0 To 49

    Bk(N).Visible = True

    Shape1.Move 184, 184

    DoEvents

    Next

    Command1.Caption = 0

    Exit Sub

    End If

    2007-05-18 19:11:54 補充:

    For N = 0 To 49

    If Bk(N).Visible = True Then

    If Shape1.Left + Shape1.Width >= Bk(N).Left And Shape1.Left <= Bk(N).Left + Bk(N).Width Then

    If Shape1.Top + Shape1.Height >= Bk(N).Top And Shape1.Top <= Bk(N).Top + Bk(N).Height Then

    Bk(N).Visible = False

    2007-05-18 19:12:05 補充:

    If Shape1.Left < Bk(N).Left + Bk(N).Width And Shape1.Left > Bk(N).Left Then Dw = Not Dw

    If Shape1.Top < Bk(N).Top + Bk(N).Height And Shape1.Top > Bk(N).Top Then Dh = Not Dh

    Call MessageBeep(0)

    Command1.Caption = Val(Command1.Caption) + 100

    2007-05-18 19:12:13 補充:

    Exit For

    End If

    End If

    End If

    If N = 10 Then DoEvents

    Next

    2007-05-18 19:12:25 補充:

    Dim All As Boolean

    All = False

    For N = 0 To 49

    If Bk(N).Visible = True Then All = True

    If N = 30 Then DoEvents

    Next

    If All = False Then

    R = MsgBox("所有磚塊擊完,要繼續嗎?", 36, "")

    If R = 6 Then End

    For N = 0 To 49

    Bk(N).Visible = True

    Shape1.Move 184, 184

    Dwd = 4

    Dhd = 4

    Next

    End If

    2007-05-18 19:12:30 補充:

    End Sub

    2007-05-18 19:12:56 補充:

    載點 http://163.32.98.8/b790113g/aaa.rar

還有問題?馬上發問,尋求解答。