Math behind the Jump
Inheritance: Jump
    /// <summary>
    /// Stick, then slide down. Can dismount jumping if enableWallJumps
    /// </summary>
    public override void PerformAction(float delta) {
      ++slidingFrames;

      int wallDirX = (pc2d.collisions.left) ? -1 : 1;
      float x = input.GetAxisRawX();

      // terminal velocity
      // NOTE apply -gravity to compensate
      if (character.velocity.y < -wallSlideSpeedMax) {
        character.velocity.y = -wallSlideSpeedMax - character.pc2d.gravity.y * delta;
      }

      // TODO manage in frames
      if (timeToWallStickLeave > 0) {
        character.velocity.x = 0;

        if (x != wallDirX && x != 0) {
          timeToWallStickLeave -= delta;
        }
        else {
          timeToWallStickLeave = wallStickLeaveTime;
        }
      }
      else {
        timeToWallStickLeave = wallStickLeaveTime;
      }

      // Jump
      if (enableWallJumps && input.IsActionHeld(actionJump.action)) {
        wallStickLeaveAgainCounter = 0; // reset!
        JumpConstant jump;
        character.ExitState(States.WallSliding);
        slidingFrames = 0;

        if (wallDirX == x) {
          jump = new JumpConstant(character,
            wallJumpClimb.Clone(-wallDirX)
          );
        } else if (x == 0) {
          jump = new JumpConstant(character,
            wallJumpOff.Clone(-wallDirX)
          );
        } else {
          jump = new JumpConstant(character,
            wallLeap.Clone(-wallDirX)
          );
        }
        actionJump.Jump(jump);
      }

    }
示例#2
0
        public override void PerformAction(float delta)
        {
            ++slidingFrames;

            int   wallDirX = (pc2d.collisions.left) ? -1 : 1;
            float x        = input.GetAxisRawX();

            // terminal velocity
            // NOTE apply -gravity to compensate
            if (character.velocity.y < -wallSlideSpeedMax)
            {
                character.velocity.y = -wallSlideSpeedMax - character.pc2d.gravity.y * delta;
            }

            // TODO manage in frames
            if (timeToWallStickLeave > 0)
            {
                character.velocity.x = 0;

                if (x != wallDirX && x != 0)
                {
                    timeToWallStickLeave -= delta;
                }
                else
                {
                    timeToWallStickLeave = wallStickLeaveTime;
                }
            }
            else
            {
                timeToWallStickLeave = wallStickLeaveTime;
            }

            // Jump
            if (enableWallJumps && input.IsActionHeld(actionJump.action))
            {
                wallStickLeaveAgainCounter = 0; // reset!
                JumpConstant jump;
                character.ExitState(States.WallSliding);
                slidingFrames = 0;

                if (wallDirX == x)
                {
                    jump = new JumpConstant(character,
                                            wallJumpClimb.Clone(-wallDirX)
                                            );
                }
                else if (x == 0)
                {
                    jump = new JumpConstant(character,
                                            wallJumpOff.Clone(-wallDirX)
                                            );
                }
                else
                {
                    jump = new JumpConstant(character,
                                            wallLeap.Clone(-wallDirX)
                                            );
                }
                actionJump.Jump(jump);
            }
        }