Thank you very much! I have a small problem now, if the user holds down the up arrow key after the character has doublejumped then the character will no longer doublejump, but just do one jump instead.
Here is my jump code in the form_Keydown event:
vb Code:
If doubleJump = False Then
If e.KeyCode = Keys.Up Then
'Resets the animation if the character was moving
If tmrJump.Enabled = True Then
tmrJump.Enabled = False
doubleJump = True
characterCount = 0
End If
' Disables movement animation
tmrMove.Enabled = False
'Resets character movement
characterCount = 0
' Sets the animation image to the right direction
If movement = "Right" Then
movement = "RightJump"
ElseIf movement = "Left" Then
movement = "LeftJump"
End If
keyPressed(e.KeyCode) = True
tmrJump.Enabled = True
End If
vb Code:
Private Sub tmrJump_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrJump.Tick
' Next animated frame
characterCount += 1
' Causes the character to jump
CharacterJump()
If keyPressed(Keys.Right) Or keyPressed(Keys.Left) Then
CharacterMove()
End If
End Sub
vb Code:
Private Sub CharacterJump()
Dim newLocation As Integer = locationY
Select Case characterCount
Case 1
newLocation -= 8
Case 2
newLocation -= 6
Case 3
newLocation -= 4
Case 4
System.Threading.Thread.Sleep(50)
Case 5
If doubleJump = True Then
newLocation += 8
Else
newLocation += 4
End If
Case 6
If doubleJump = True Then
newLocation += 12
Else
newLocation += 6
End If
Case 7
If doubleJump = True Then
newLocation += 16
Else
newLocation += 8
End If
Case 8
'Disables the animation
tmrJump.Enabled = False
'Resets the character to standing image
characterCount = 0
If doubleJump = True Then
doubleJump = False
End If
keyPressed(Keys.Up) = False
If movement = "RightJump" Then
movement = "Right"
ElseIf movement = "LeftJump" Then
movement = "Left"
End If
' Continues previous movement on ground
If keyPressed(Keys.Right) Or keyPressed(Keys.Left) Then
tmrMove.Enabled = True
End If
End Select
If CheckForGround(newLocation) = True Then
newLocation = 342
End If
locationY = newLocation
' Animates the character's jump
Me.Refresh()
vb Code:
Private Sub tmrMove_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrMove.Tick
If movement = "Right" Or movement = "Left" Then
If characterCount = 10 Then
' Loops the animation
characterCount = 1
Else
' Gets the next animation image
characterCount += 1
End If
End If
CharacterMove()
End Sub