[RESOLVED] Key Press Problem
I am using the following code to change the direction of my snake in a game:
Code:
Public Sub PressKey(ByVal Key As Input.Keys)
Select Case Key
Case Keys.Escape 'Exit Game'
MyBase.Exit()
Case Keys.Up 'Change Direction To Up'
If GameState = GameStates.Playing Then
If Snake(0).Direction <> BodyParts.Directions.South Then
Snake(0).Direction = BodyParts.Directions.North
End If
End If
Case Keys.Right 'Change Direction To Up'
If GameState = GameStates.Playing Then
If Snake(0).Direction <> BodyParts.Directions.West Then
Snake(0).Direction = BodyParts.Directions.East
End If
End If
Case Keys.Down 'Change Direction To Up'
If GameState = GameStates.Playing Then
If Snake(0).Direction <> BodyParts.Directions.North Then
Snake(0).Direction = BodyParts.Directions.South
End If
End If
Case Keys.Left 'Change Direction To Up
If GameState = GameStates.Playing Then
If Snake(0).Direction <> BodyParts.Directions.East Then
Snake(0).Direction = BodyParts.Directions.West
End If
End If
End Select
End Sub
I have set it up so that if the direction is set as east and the left key is pressed not to change the direction to west so the snake doesn't eat itself.
This works however if the direction is east and I quickly press down then left the snake doesn't have time to move down and just moves to the left causing the snake to eat itself.
Anyone know how i can solve this?