Skip to content

Commit

Permalink
Use gestures to control DoodleJump
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinao committed May 17, 2016
1 parent 72b926a commit c20f775
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions public/js/widget_doodlejump.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,18 @@ function callbackGestureDoodleJump(gesture) {

previousGesture = currentGesture;
currentGesture = gesture;
console.log(currentGesture);
if (previousGesture == null)
return;

var diffX = currentGesture.centerX - previousGesture.centerX;
console.log("diffX: " + diffX)
player.isMovingLeft = false;
player.isMovingRight = false;
if (diffX > 10)
{
player.isMovingLeft = true;
dir = "left";
}
else if (diffX > -10)
else if (diffX < -10)
{
player.isMovingRight = true;
dir = "right";
Expand Down Expand Up @@ -303,25 +301,25 @@ function init() {
//Accelerations produces when the user hold the keys
if (player.isMovingLeft === true) {
player.x += player.vx;
player.vx -= 0.15;
player.vx -= 0.30;
} else {
player.x += player.vx;
if (player.vx < 0) player.vx += 0.1;
if (player.vx < 0) player.vx += 0.2;
}

if (player.isMovingRight === true) {
player.x += player.vx;
player.vx += 0.15;
player.vx += 0.30;
} else {
player.x += player.vx;
if (player.vx > 0) player.vx -= 0.1;
if (player.vx > 0) player.vx -= 0.2;
}

// Speed limits!
if(player.vx > 4)
player.vx = 4;
else if(player.vx < -4)
player.vx = -4;
if(player.vx > 3)
player.vx = 3;
else if(player.vx < -3)
player.vx = -3;

//console.log(player.vx);

Expand Down

0 comments on commit c20f775

Please sign in to comment.