Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function mainJump():void{
- //When this function is called...
- //If we're not jumping...
- if(!mainJumping){
- //Now we are jumping...
- mainJumping = true;
- //And our jump speed is the maximum jump speed.
- //Since (0, 0) is the top left corner, we have to subtract to go up.
- //As such, we multiply jumpSpeedLimit by -1 (we could have also said "jumpSpeed = -jumpSpeedLimit").
- jumpSpeed = jumpSpeedLimit*-1;
- //However, setting our jump speed alone does not move our character. We now must modify our character's
- //position by the amount in jumpSpeed.
- main_mc.y += jumpSpeed;
- //However, if we're already jumping...
- } else {
- //If our jump speed is less than 0, meaning the character is still going up...
- if(jumpSpeed < 0){
- //Our jump speed is multiplied by 1 minus the maximum jump speed divided by 75 to slowly degrade
- //the jump speed by a factor of (1 - jumpSpeedLimit/75), creating the first half of the arc.
- jumpSpeed *= 1 - jumpSpeedLimit/75;
- //However, if our jump speed is greater than 1/5 of our maximum jump speed in the upper direction...
- //Remember that being greater than 1/5 of our maximum jump speed means our jump speed is approaching 0,
- //meaning that we will have to change our behavior to account for it soon, since we can only go up
- //if our jump speed is less than 0.
- if(jumpSpeed > -jumpSpeedLimit/5){
- //Multiply our jump speed by -1 so that it begins our descent, creating the beginning of
- //the second half of the arc.
- jumpSpeed *= -1;
- }
- }
- //However, if our jumpSpeed is greater than 0, meaning we are falling, and our jump speed is also less than
- //our maximum jump speed (no longer negative, as we are falling, heading away from (0, 0))...
- if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit) {
- //Multiply our jump speed by a factor of (1 + jumpSpeedLimit/50), pushing us closer to our maximum jump speed.
- jumpSpeed *= 1 + jumpSpeedLimit/50;
- }
- //Now that we've decided what our jump speed should be this step, we add it to our y position to move our character.
- main_mc.y += jumpSpeed;
- //If the character hits the bottom of the screen minus its height (so that it is still visible)...
- if(main_mc.y >= stage.stageHeight - main_mc.height) {
- //Our character is no longer jumping.
- mainJumping = false;
- //And its y position should stay at the bottom of the screen minus its height.
- main_mc.y = stage.stageHeight - main_mc.height;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement