Time for action – overriding the Update() method – part 2
Inside the
Public Methods
region of thePlayer
class, add theJump()
method:Public Sub Jump() Velocity = New Vector2(Velocity.X, -500) End Sub
Add the following code to the
Update()
method right after theif
statement for detecting movement to the right, and before the check for which animation to play:If (keyState.IsKeyDown(Keys.Space) Or (padState.Buttons.A = ButtonState.Pressed)) Then If OnGround Then Jump() newAnimation = "jump" End If End If If CurrentAnimation = "jump" Then newAnimation = "jump" End If
Still in the
Update()
method, add the following line right before the call toMyBase.Update()
(outside of the conditional for the player being dead—being dead will not prevent the player's body from falling due to gravity):Velocity += _fallSpeed
Execute the Gemstone Hunter project. Use the Space bar or the A button on the gamepad to jump.
What just happened?
When you execute the game, the player...