Skip to content
This repository has been archived by the owner on Nov 12, 2024. It is now read-only.

Commit

Permalink
improve jump example
Browse files Browse the repository at this point in the history
  • Loading branch information
slmjkdbtl committed Nov 12, 2023
1 parent a396ada commit 4a76037
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions examples/gravity.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ player.onGround(() => {

// Accelerate falling when player holding down arrow key
onKeyDown("down", () => {
if (player.vel.y > 0 && !player.isGrounded()) {
player.vel.y *= 1.1
if (!player.isGrounded()) {
player.vel.y += dt() * 1200
}
})

// Jump higher if space is held
onKeyDown("space", () => {
if (!player.isGrounded() && player.vel.y < 0) {
player.vel.y -= dt() * 600
}
})

Expand Down

0 comments on commit 4a76037

Please sign in to comment.