Created
March 12, 2015 03:36
-
-
Save fernandozamoraj/83848afe2971339bc93c to your computer and use it in GitHub Desktop.
jump simple game
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Avatar(scene){ | |
var JUMP_FORCE = 14; | |
var sprite = new Sprite(scene, "./img/image.png", 150, 150); | |
var jumping = false; | |
sprite.init = function(){ | |
this.setSpeed(0); | |
}; | |
sprite.checkGravity = function(){ | |
//the math looks a little funky but that's only | |
//because the x y of the sprite is on the center of the sprite | |
//so you have to do a little math to insure that the avater does | |
//fall off the screen | |
if(this.y > 500){ | |
this.setPosition(this.x, 500 ); | |
//reset jumping so it can only jump when on the ground | |
jumping = false; | |
this.dy = 0; //must clear the dy for some reason | |
} | |
else if(this.y < 500){ | |
this.addVector(180,.8); | |
} | |
}; | |
sprite.checkKeys = function(){ | |
if(keysDown[K_UP] && jumping == false){ | |
jumping = true; | |
this.addVector(0, JUMP_FORCE); | |
} | |
}; | |
return sprite; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment