Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function mainJump():void{
  2.         //When this function is called...
  3.         //If we're not jumping...
  4.         if(!mainJumping){
  5.                 //Now we are jumping...
  6.                 mainJumping = true;
  7.                 //And our jump speed is the maximum jump speed.
  8.                 //Since (0, 0) is the top left corner, we have to subtract to go up.
  9.                 //As such, we multiply jumpSpeedLimit by -1 (we could have also said "jumpSpeed = -jumpSpeedLimit").
  10.                 jumpSpeed = jumpSpeedLimit*-1;
  11.                 //However, setting our jump speed alone does not move our character. We now must modify our character's
  12.                 //position by the amount in jumpSpeed.
  13.                 main_mc.y += jumpSpeed;
  14.         //However, if we're already jumping...
  15.         } else {
  16.                 //If our jump speed is less than 0, meaning the character is still going up...
  17.                 if(jumpSpeed < 0){
  18.                         //Our jump speed is multiplied by 1 minus the maximum jump speed divided by 75 to slowly degrade
  19.                         //the jump speed by a factor of (1 - jumpSpeedLimit/75), creating the first half of the arc.
  20.                         jumpSpeed *= 1 - jumpSpeedLimit/75;
  21.                         //However, if our jump speed is greater than 1/5 of our maximum jump speed in the upper direction...
  22.                         //Remember that being greater than 1/5 of our maximum jump speed means our jump speed is approaching 0,
  23.                         //meaning that we will have to change our behavior to account for it soon, since we can only go up
  24.                         //if our jump speed is less than 0.
  25.                         if(jumpSpeed > -jumpSpeedLimit/5){
  26.                                 //Multiply our jump speed by -1 so that it begins our descent, creating the beginning of
  27.                                 //the second half of the arc.
  28.                                 jumpSpeed *= -1;
  29.                         }
  30.                 }
  31.                 //However, if our jumpSpeed is greater than 0, meaning we are falling, and our jump speed is also less than
  32.                 //our maximum jump speed (no longer negative, as we are falling, heading away from (0, 0))...
  33.                 if(jumpSpeed > 0 && jumpSpeed <= jumpSpeedLimit) {
  34.                         //Multiply our jump speed by a factor of (1 + jumpSpeedLimit/50), pushing us closer to our maximum jump speed.
  35.                         jumpSpeed *= 1 + jumpSpeedLimit/50;
  36.                 }
  37.                 //Now that we've decided what our jump speed should be this step, we add it to our y position to move our character.
  38.                 main_mc.y += jumpSpeed;
  39.  
  40.                 //If the character hits the bottom of the screen minus its height (so that it is still visible)...
  41.                 if(main_mc.y >= stage.stageHeight - main_mc.height) {
  42.                         //Our character is no longer jumping.
  43.                         mainJumping = false;
  44.                         //And its y position should stay at the bottom of the screen minus its height.
  45.                         main_mc.y = stage.stageHeight - main_mc.height;
  46.                 }
  47.         }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement