Kollision von 2 Pictureboxen

  • VB.NET

Es gibt 7 Antworten in diesem Thema. Der letzte Beitrag () ist von Lukas97.

    Kollision von 2 Pictureboxen

    Hallo,



    ich arbeite derzeit an einem kleinen 2D Game. Man kann bisjetzt nur rumlaufen. Wie mache ich das nun, dass ich nicht über eine andere Picturebox laufen kann? Ich habe das mal angehangen, spielt des mal, dann seht ihr was ich meine. Ich weiß nicht wie ich das beschreiben soll Oo.
    Dateien
    • GAME.7z

      (169,56 kB, 139 mal heruntergeladen, zuletzt: )
    Also das mit dem Laden-Bildschirm ist wohl ein schlechter Scherz oder? Wegen Dir kam mir grade der Kaffee wieder aus der Nase, weil ich so lachen musst. Echt ey, sorry. Warum was laden, wenns gar nix zu laden gibt. Ich glaub, meine U-Hose hat auch nen gelben Fleck davongetragen. Alles nur wegen Dir, rofl.

    Zum Thema: Kollisionen kannst Du so abfragen, wenn mich nicht alles täuscht.

    VB.NET-Quellcode

    1. If Me.PictureBox1.ClientRectangle.IntersectsWith(PictureBox10.ClientRectangle) Then
    2. End If


    Musst eben bei jeder Bewegung abfragen, ob der Player mit was kollidiert. Gar nicht so schwer. Im Code hab ich irgendwelche PBs verwendet. Die richtigen musst schon selber suchen.
    Die Unendlichkeit ist weit. Vor allem gegen Ende. ?(
    Manche Menschen sind gar nicht dumm. Sie haben nur Pech beim Denken. 8o
    OK, soweit hatte ich das auch mal. Das mit dem Laden, xD, ja da bin ich noch am rumprobieren.

    Wie mache ich nun, wenn die PB's kollidieren, dass sich die "Kuh" nichtmehr bewegt, in die Richtung, in der das PB ist?
    Gibt viele Wege,
    musst dich entscheiden in welchem Zusammenhang du etwas benutzen kannst.

    Ich hab da jetzt z.B. einen Timer im Kopf, der überprüft, ob die Kuh mit etwas kollidiert,..

    Allerdings hab ich davon keine Ahnung und das soll nur eine "Idee" sein. Wenn es was anzuprangern gibt, bitte sagen :D

    Grüße Drahuverar
    Option Strict On!
    Ich hab dir mal deinen Code so erweitert das du zumindes nicht mehr nach links
    in eine andere PictureBox reinsteuern kannst. Nach oben, unten und rechts
    müsstest du jetzt selbst hinbekommen.

    VB.NET-Quellcode

    1. Public Class Game
    2. Dim PB_Liste As List(Of Object) = New List(Of Object)
    3. Dim crash As Boolean
    4. Dim PX As Integer
    5. Dim PY As Integer
    6. Private Sub Game_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    7. crash = False
    8. For Each element As Control In Me.Controls
    9. If TypeOf element Is PictureBox Then
    10. If Not element.Name = "PictureBox22" Then
    11. PB_Liste.Add(element)
    12. End If
    13. End If
    14. Next
    15. End Sub
    16. Private Sub FormKey(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
    17. If e.KeyCode = Keys.Up Then
    18. PictureBox22.Location = New Point(PictureBox22.Location.X, PictureBox22.Location.Y - 10)
    19. ElseIf e.KeyCode = Keys.Down Then
    20. PictureBox22.Location = New Point(PictureBox22.Location.X, PictureBox22.Location.Y + 10)
    21. ElseIf e.KeyCode = Keys.Right Then
    22. PictureBox22.Location = New Point(PictureBox22.Location.X + 10, PictureBox22.Location.Y)
    23. ElseIf e.KeyCode = Keys.Left Then
    24. CrashTestLinks()
    25. If crash = False Then
    26. PictureBox22.Location = New Point(PictureBox22.Location.X - 10, PictureBox22.Location.Y)
    27. End If
    28. ElseIf e.KeyCode = Keys.Escape Then
    29. Me.Close()
    30. End If
    31. End Sub
    32. Private Sub CrashTestLinks()
    33. For Each Eintrag In PB_Liste
    34. Get_Coordinaten(Eintrag)
    35. If PictureBox22.Location.X - 10 <= PX + 25 Then
    36. If PictureBox22.Location.X - 10 >= PX Then
    37. If PictureBox22.Location.Y <= PY + 25 Then
    38. If PictureBox22.Location.Y >= PY Then
    39. crash = True
    40. Exit Sub
    41. Else : crash = False
    42. End If
    43. Else : crash = False
    44. End If
    45. If PictureBox22.Location.Y + 25 >= PY Then
    46. If PictureBox22.Location.Y + 25 <= PY + 25 Then
    47. crash = True
    48. Exit Sub
    49. Else : crash = False
    50. End If
    51. Else : crash = False
    52. End If
    53. Else : crash = False
    54. End If
    55. Else : crash = False
    56. End If
    57. Next
    58. End Sub
    59. Private Sub Get_Coordinaten(ByVal PB As Object)
    60. PX = PB.Location.X
    61. PY = PB.Location.Y
    62. End Sub
    63. End Class