Wednesday, May 4, 2011

...)
that.checkJump = function() {
if (that.Y > height*0.4) {
//if player is under about half of the screen - let him move
that.setPosition(that.X, that.Y - that.jumpSpeed);
} else {
//in other dont move player up, move platforms and circles down instead
MoveCircles(that.jumpSpeed * 0.5);
//clouds are in the background, further than platforms and player, so we will move it with half speed

platforms.forEach(function(platform, ind){
platform.y += that.jumpSpeed;

if (platform.y > height) {
//if platform moves outside the screen, we will generate another one on the top
var type = ~~(Math.random() * 5);
if (type == 0)
type = 1;
else
type = 0;
platforms[ind] = new Platform(Math.random() * (width - platformWidth), platform.y - height, type);
}
});
}


that.jumpSpeed--;
if (that.jumpSpeed == 0) {
that.isJumping = false;
that.isFalling = true;
that.fallSpeed = 1;
}

}