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
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:
VB.NET-Quellcode
- Public Class Form1
- 'Bodenkollision
- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
- Dim BMAP As Bitmap = Me.BackgroundImage
- If BMAP.GetPixel(PictureBox1.Location.X, PictureBox1.Bottom) = New Color().FromArgb(255, 0, 0, 0) Then
- Else
- PictureBox1.Location = PictureBox1.Location + New Point(0, 2)
- End If
- End Sub
- Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
- Dim BMAP As Bitmap = Me.BackgroundImage
- 'Wenn die Linkstaste gedrückt wird
- If e.KeyCode = Keys.Left Then
- If BMAP.GetPixel(PictureBox1.Left - 6, PictureBox1.Location.Y - PictureBox1.Width) = New Color().FromArgb(255, 0, 0, 0) Or _
- BMAP.GetPixel(PictureBox1.Location.X - 6, PictureBox1.Location.Y) = New Color().FromArgb(255, 0, 0, 0) Or _
- BMAP.GetPixel(PictureBox1.Location.X - 6, PictureBox1.Location.Y + (PictureBox1.Width - 1)) = New Color().FromArgb(255, 0, 0, 0) Then
- Else
- PictureBox1.Location = PictureBox1.Location - New Point(6, 0)
- End If
- End If
- 'Wenn die Rechtstaste gedrückt wird
- If e.KeyCode = Keys.Right Then
- If BMAP.GetPixel(PictureBox1.Right + 6, PictureBox1.Location.Y - PictureBox1.Width) = New Color().FromArgb(255, 0, 0, 0) Or _
- BMAP.GetPixel(PictureBox1.Location.X + 6, PictureBox1.Location.Y) = New Color().FromArgb(255, 0, 0, 0) Or _
- BMAP.GetPixel(PictureBox1.Location.X + 6, PictureBox1.Location.Y + (PictureBox1.Width - 1)) = New Color().FromArgb(255, 0, 0, 0) Then
- Else
- PictureBox1.Location = PictureBox1.Location + New Point(6, 0)
- End If
- End If
- If e.KeyCode = Keys.Up Then
- If BMAP.GetPixel(PictureBox1.Right + 6, PictureBox1.Location.Y - PictureBox1.Width) = New Color().FromArgb(255, 0, 0, 0) Or _
- BMAP.GetPixel(PictureBox1.Location.Y - 6, PictureBox1.Location.X) = New Color().FromArgb(255, 0, 0, 0) Or _
- BMAP.GetPixel(PictureBox1.Location.Y - 6, PictureBox1.Location.X + (PictureBox1.Width - 1)) = New Color().FromArgb(255, 0, 0, 0) Then
- Else
- PictureBox1.Location = PictureBox1.Location + New Point(0, -6)
- End If
- End If
- If e.KeyCode = Keys.Down Then
- If BMAP.GetPixel(PictureBox1.Right + 6, PictureBox1.Location.Y - PictureBox1.Width) = New Color().FromArgb(255, 0, 0, 0) Or _
- BMAP.GetPixel(PictureBox1.Location.Y + 6, PictureBox1.Location.X) = New Color().FromArgb(255, 0, 0, 0) Or _
- BMAP.GetPixel(PictureBox1.Location.Y + 6, PictureBox1.Location.X + (PictureBox1.Width - 1)) = New Color().FromArgb(255, 0, 0, 0) Then
- Else
- PictureBox1.Location = PictureBox1.Location + New Point(0, 6)
- End If
- End If
- End Sub
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
- End Sub
- End Class