作者r770619a (被催眠的爱情//我)
站内Visual_Basic
标题[VB6 ] 请帮我看看哪边写错了>< (键盘事件)
时间Sat Oct 8 21:44:30 2005
这是键盘事件 要写出一个小游戏的程式
游戏中的爱心以键盘方向键控制 闪躲从右方来的箭
假使碰到箭 被刺到 就会产生爆炸
我现在写出来了 但是碰到之後的爆炸 还蛮奇怪的
我的问题是: 爱心还没碰到真正的撞到箭 就爆炸了
似乎是我碰到的那个点没有写好
麻烦乡民跟我说一下 要怎麽写才会正确呢
(以下是我的程式码)
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
1F:→ r770619a:没有人帮我看~>< 拜托乡民啊218.172.174.147 10/09 15:40
2F:推 BearWu:来个程式的连结吧,拿来测测看 59.113.167.150 10/11 12:09
3F:推 r770619a:只有程式码耶 连结那个我不会~><" 218.172.169.18 10/12 19:57