Hilfe bei 2D SPieleprogrammierung

  • VB.NET

Es gibt 2 Antworten in diesem Thema. Der letzte Beitrag () ist von Confix.npage.de.

    Hilfe bei 2D SPieleprogrammierung

    Guten Tag,
    Ich habe beim Sourcecode austausch ein Code gefunden wie man sein eigenes 2D spiel machen kann.
    Mein Problem ist nur folgendes, ich habe noch die Funktionen hinzugefügt dass die "Figur" nach oben kann und nach unten, aber das geht dann immer nur 7 Schritte mehr nicht obwohl es nicht an den schwarzen bereich herankommt. Jedoch bei Rechts und Links die schon da waren geht es problemlos, hier mein Code:
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Public Class Form1
    2. 'Bodenkollision
    3. Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    4. Dim BMAP As Bitmap = Me.BackgroundImage
    5. If BMAP.GetPixel(PictureBox1.Location.X, PictureBox1.Bottom) = New Color().FromArgb(255, 0, 0, 0) Then
    6. Else
    7. PictureBox1.Location = PictureBox1.Location + New Point(0, 2)
    8. End If
    9. End Sub
    10. Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    11. Dim BMAP As Bitmap = Me.BackgroundImage
    12. 'Wenn die Linkstaste gedrückt wird
    13. If e.KeyCode = Keys.Left Then
    14. If BMAP.GetPixel(PictureBox1.Left - 6, PictureBox1.Location.Y - PictureBox1.Width) = New Color().FromArgb(255, 0, 0, 0) Or _
    15. BMAP.GetPixel(PictureBox1.Location.X - 6, PictureBox1.Location.Y) = New Color().FromArgb(255, 0, 0, 0) Or _
    16. BMAP.GetPixel(PictureBox1.Location.X - 6, PictureBox1.Location.Y + (PictureBox1.Width - 1)) = New Color().FromArgb(255, 0, 0, 0) Then
    17. Else
    18. PictureBox1.Location = PictureBox1.Location - New Point(6, 0)
    19. End If
    20. End If
    21. 'Wenn die Rechtstaste gedrückt wird
    22. If e.KeyCode = Keys.Right Then
    23. If BMAP.GetPixel(PictureBox1.Right + 6, PictureBox1.Location.Y - PictureBox1.Width) = New Color().FromArgb(255, 0, 0, 0) Or _
    24. BMAP.GetPixel(PictureBox1.Location.X + 6, PictureBox1.Location.Y) = New Color().FromArgb(255, 0, 0, 0) Or _
    25. BMAP.GetPixel(PictureBox1.Location.X + 6, PictureBox1.Location.Y + (PictureBox1.Width - 1)) = New Color().FromArgb(255, 0, 0, 0) Then
    26. Else
    27. PictureBox1.Location = PictureBox1.Location + New Point(6, 0)
    28. End If
    29. End If
    30. If e.KeyCode = Keys.Up Then
    31. If BMAP.GetPixel(PictureBox1.Right + 6, PictureBox1.Location.Y - PictureBox1.Width) = New Color().FromArgb(255, 0, 0, 0) Or _
    32. BMAP.GetPixel(PictureBox1.Location.Y - 6, PictureBox1.Location.X) = New Color().FromArgb(255, 0, 0, 0) Or _
    33. BMAP.GetPixel(PictureBox1.Location.Y - 6, PictureBox1.Location.X + (PictureBox1.Width - 1)) = New Color().FromArgb(255, 0, 0, 0) Then
    34. Else
    35. PictureBox1.Location = PictureBox1.Location + New Point(0, -6)
    36. End If
    37. End If
    38. If e.KeyCode = Keys.Down Then
    39. If BMAP.GetPixel(PictureBox1.Right + 6, PictureBox1.Location.Y - PictureBox1.Width) = New Color().FromArgb(255, 0, 0, 0) Or _
    40. BMAP.GetPixel(PictureBox1.Location.Y + 6, PictureBox1.Location.X) = New Color().FromArgb(255, 0, 0, 0) Or _
    41. BMAP.GetPixel(PictureBox1.Location.Y + 6, PictureBox1.Location.X + (PictureBox1.Width - 1)) = New Color().FromArgb(255, 0, 0, 0) Then
    42. Else
    43. PictureBox1.Location = PictureBox1.Location + New Point(0, 6)
    44. End If
    45. End If
    46. End Sub
    47. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    48. End Sub
    49. Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
    50. End Sub
    51. End Class