Skip to content

Commit

Permalink
Add player ability to double jump
Browse files Browse the repository at this point in the history
  • Loading branch information
MattyRad committed Feb 13, 2020
1 parent 738f5d0 commit 5d70c47
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions public/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ scene.add( plane );

scene.background = new THREE.Color( 0x99ffff );

var jumping = false;
var jumping = doublejumping = false;
var jump_distance = 0.1;
var acceleration = 0.0025;
var acceleration_step = 0.0025;
Expand Down Expand Up @@ -97,10 +97,16 @@ var animate = function () {
}

if (keyboard.pressed("space")) {
if (jumping && ! doublejumping && jump_distance < 0.07) {
jump_distance = 0.1;
acceleration_step = acceleration;
doublejumping = true;
}

jumping = true;
}

if (jumping) {
if (jumping || doublejumping) {
acceleration_step = acceleration_step * (1 + acceleration);

jump_distance -= acceleration_step;
Expand All @@ -109,7 +115,7 @@ var animate = function () {
}

if (player.position.y < initial_y) { // hit the "ground"
jumping = false;
jumping = doublejumping = false;

// reset our acceleration calculations
jump_distance = 0.1;
Expand Down

0 comments on commit 5d70c47

Please sign in to comment.