-1
私は基本的なポンゲームをビジュアルベーシックでプログラミングしています。if文で助けが必要です。ボールがエッジに当たったら、画面の中央にリセットされ、 "resetBall"がtrueにセットされ、 "R"を押してもう一度動かす必要があります。KeyDown PrivateSubの中でIF文を動作させる方法
Private Sub Timer1_Tick(sender As Object, e As KeyEventArgs) Handles Timer1.Tick
If PictureBox3.Bounds.IntersectsWith(PictureBox2.Bounds) Then
direction = 1
End If
If PictureBox3.Bounds.IntersectsWith(PictureBox1.Bounds) Then
direction = 0
End If
If direction = 0 Then
PictureBox3.Left += 15
End If
If direction = 1 Then
PictureBox3.Left -= 15
End If
If PictureBox3.Bounds.IntersectsWith(leftBumper.Bounds) Then
PictureBox3.SetBounds(325, 165, 0, 0, BoundsSpecified.X Or BoundsSpecified.Y)
direction = 2
resetBall0 = True
End If
If PictureBox3.Bounds.IntersectsWith(rightBumper.Bounds) Then
PictureBox3.SetBounds(325, 165, 0, 0, BoundsSpecified.X Or BoundsSpecified.Y)
direction = 2
resetBall1 = True
End If
End Sub
ただし、コードの次の部分に「If」文を使用すると、機能しません。
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
Select Case e.KeyCode
Case Keys.W
PictureBox1.Top -= 8
Case Keys.S
PictureBox1.Top += 8
Case Keys.Up
PictureBox2.Top -= 8
Case Keys.Down
PictureBox2.Top += 8
If resetBall1 = True Then
Select Case e.KeyCode
Case Keys.R
direction = 1
End Select
End If
If resetBall0 = True Then
Select Case e.KeyCode
Case Keys.R
direction = 0
End Select
End If
End Select
End Sub
どのように動作しませんか? –
'それはうまくいっていません。私たちには何も与えません。 – Plutonix
"R"を押すと、文字通り何の効果もありませんが、エラーメッセージも表示されません。 – Cormack