2016-08-31 4 views
0

私はプラットフォーマーゲームを作成しています。マップの両側には、2つの目に見えない壁があります。プレイヤーの画像ボックスがこれらの壁に接触すると、移動が止まり、プレイヤーはマップの境界外に移動できなくなります。画像ボックスの動きを止める簡単な方法はありますか?誰かがそれを望む場合、またはもし私が何をしようとしているのかを見たい場合は、私のコードを下に貼り付けます。platformerのゲームのためのVB.NETのプレーヤーの動きを防ぐには?

Public Class Form2 

    Dim clsnBoxes(1) As PictureBox 

    Private Sub Form2_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown 

     'allows for left/right movement 
     Select Case e.KeyCode 
      Case Keys.Right 
       tmrRight.Enabled = True 
       tmrLeft.Enabled = False 
       clsnTmr.Enabled = True 
      Case Keys.Left 
       tmrRight.Enabled = False 
       tmrLeft.Enabled = True 
       clsnTmr.Enabled = True 
     End Select 


    End Sub 

    Private Sub Form2_KeyUp(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp 

     'stops movement after key has been released 
     Select Case e.KeyCode 
      Case Keys.Right 
       tmrRight.Enabled = False 
      Case Keys.Left 
       tmrLeft.Enabled = False 
     End Select 

    End Sub 

    Private Sub Form2_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load 

     'stops manual scrolling 
     Me.AutoScroll = False 

     clsnBoxes(0) = Me.clsnBx1 
     clsnBoxes(1) = Me.clsnBx2 

    End Sub 

    Private Sub tmrLeft_Tick(sender As System.Object, e As System.EventArgs) Handles tmrLeft.Tick 

     'moves all of the clouds left 
     Dim Objects() As PictureBox = {pic1, pic2, pic3, pic4, pic5, pic6, clsnBx1, clsnBx2} 
     For x = 0 To Objects.Length - 1 
      Objects(x).Left += 3 
     Next 

    End Sub 

    Private Sub tmrRight_Tick(sender As System.Object, e As System.EventArgs) Handles tmrRight.Tick 

     'moves all of the clouds right 
     Dim Objects() As PictureBox = {pic1, pic2, pic3, pic4, pic5, pic6, clsnBx1, clsnBx2} 
     For x = 0 To Objects.Length - 1 
      Objects(x).Left -= 3 
     Next 

    End Sub 

    Private Sub clsnTmr_Tick(sender As System.Object, e As System.EventArgs) Handles clsnTmr.Tick 
     For index = 0 To 1 
      If Me.picPlayer.Bounds.IntersectsWith(clsnBoxes(index).Bounds) Then 

      End If 
     Next 
    End Sub 
End Class 
+2

ようこそ、スタックオーバーフロー!いくつかの詳細を記入してください:何を試してみましたか、そして現在どのような問題がありますか? [良い質問をするにはどうすればいいですか?](http://stackoverflow.com/help/how-to-ask)も参照してください。 –

+0

いくつかの不思議な理由のために、あなたは左右逆転しています。オブジェクト(x).Left = Math.Max(LeftWallPosition、Objects(x).Left - 3)。 –

答えて

0

例では1つの動きしか取り上げませんが、他の動きでも同じです。移動を行う前にテストを追加するだけです。

Private Sub tmrLeft_Tick(sender As System.Object, e As System.EventArgs) Handles tmrLeft.Tick 

     'Assuming that pic1 is the most left pictures of all 
     'Assuming that MINIMUM_LEFT is the position of the wall + its width 
     If pic1.Left <= MINIMUM_LEFT Then Exit Sub 

     [...your movement code...] 

    End Sub 
関連する問題