[VB6 ] 請幫我看看哪邊寫錯了>< (鍵盤事件)
這是鍵盤事件 要寫出一個小遊戲的程式
遊戲中的愛心以鍵盤方向鍵控制 閃躲從右方來的箭
假使碰到箭 被刺到 就會產生爆炸
我現在寫出來了 但是碰到之後的爆炸 還蠻奇怪的
我的問題是: 愛心還沒碰到真正的撞到箭 就爆炸了
似乎是我碰到的那個點沒有寫好
麻煩鄉民跟我說一下 要怎麼寫才會正確呢
(以下是我的程式碼)
Const key_up = 38
Const key_down = 40
Const key_right = 39
Const key_left = 37
Dim heart_x
Dim heart_y
Private Sub Form_Activate()
Q1 = MsgBox("小心別讓你的心被刺到囉,按確定開始遊戲囉", 64, "[ 刺 刺 你 的 心 ] ")
Timer1.Interval = 200
Timer2.Interval = 120
If Image1.Left >= Image3.Left Then
Image1.Visible = True
End If
Timer3.Interval = 100
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case key_up
Image1.Top = Image1.Top - 150
Case key_down
Image1.Top = Image1.Top + 150
Case key_right
Image1.Left = Image1.Left + 150
Case key_left
Image1.Left = Image1.Left - 150
End Select
End Sub
Private Sub Form_Load()
heart_x = Image1.Left
heart_y = Image1.Top
End Sub
Private Sub Timer1_Timer()
Image2.Left = Image2.Left - 680
Image3.Left = Image3.Left - 560
Image4.Left = Image4.Left - 250
If Image2.Left <= -Image2.Width Then
Image2.Left = Width
End If
If Image3.Left <= -Image3.Width Then
Image3.Left = Width
End If
If Image4.Left <= -Image4.Width Then
Image4.Left = Width
End If
End Sub
Private Sub Timer2_Timer()
Image5.Left = Image5.Left - 440
Image6.Left = Image6.Left - 880
If Image5.Left <= -Image5.Width Then
Image5.Left = Width
End If
If Image6.Left <= -Image6.Width Then
Image6.Left = Width
End If
End Sub
Private Sub Timer3_Timer()
If Image1.Left >= Image2.Left - Image1.Width And Image1.Left <= Image2.Left + Image2.Width And Image1.Top >= Image2.Top - Image1.Height And Image1.Top <= Image2.Top + Image2.Height Then
Image1.Visible = False
Image8.Visible = True
Timer1.Interval = False
Image8.Top = Image1.Top
Image8.Left = Image1.Left
MsgBox "GAME OVER", 1, "bye bye"
End
End If
If Image1.Left >= Image3.Left - Image1.Width And Image1.Left <= Image3.Left + Image3.Width Then
If Image1.Top >= Image3.Top - Image1.Height And Image1.Top <= Image3.Top + Image3.Height Then
Image1.Visible = False
Image8.Visible = True
Timer1.Interval = False
Image8.Top = Image1.Top
Image8.Left = Image1.Left
MsgBox "GAME OVER", 1, "bye bye"
End
End If
End If
If Image1.Left >= Image4.Left - Image1.Width And Image1.Left <= Image4.Left + Image4.Width Then
If Image1.Top >= Image4.Top - Image1.Height And Image1.Top <= Image4.Top + Image4.Height Then
Image1.Visible = False
Image8.Visible = True
Timer1.Interval = False
Image8.Top = Image1.Top
Image8.Left = Image1.Left
MsgBox "GAME OVER", 1, "bye bye"
End
End If
End If
If Image1.Left >= Image5.Left - Image1.Width And Image1.Left <= Image5.Left + Image5.Width Then
If Image1.Top >= Image5.Top - Image1.Height And Image1.Top <= Image5.Top + Image5.Height Then
Image1.Visible = False
Image8.Visible = True
Timer2.Interval = False
Image8.Top = Image1.Top
Image8.Left = Image1.Left
MsgBox "GAME OVER", 1, "bye bye"
End
End If
End If
If Image1.Left >= Image6.Left - Image1.Width And Image1.Left <= Image6.Left + Image6.Width Then
If Image1.Top >= Image6.Top - Image1.Height And Image1.Top <= Image6.Top + Image6.Height Then
Image1.Visible = False
Image8.Visible = True
Timer2.Interval = False
Image8.Top = Image1.Top
Image8.Left = Image1.Left
MsgBox "GAME OVER", 1, "bye bye"
End
End If
End If
End Sub
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.172.174.147
→
10/09 15:40, , 1F
10/09 15:40, 1F
推
10/11 12:09, , 2F
10/11 12:09, 2F
推
10/12 19:57, , 3F
10/12 19:57, 3F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 3 篇):
Visual_Basic 近期熱門文章
PTT數位生活區 即時熱門文章