Ejemplo n.º 1
0
    private void Update()
    {
        bool mayJump  = MayJump();
        bool onGround = this.OnGround2D();

        /*
         * Update last grounded position
         */
        if (onGround)
        {
            _lastGroundedPosition = PositionSnapshot.FromObject(_flippable);
        }

        DebugScreenDrawer.Enable("onground", "onground: " + onGround);
        DebugScreenDrawer.Enable("mayjump", "mayjump: " + mayJump);

        /*
         * Apply jump
         */
        if (Input.GetButtonDown("Jump"))
        {
            _lastAttemptedJumpPosition = PositionSnapshot.FromObject(_flippable);

            if (mayJump)
            {
                StopAllCoroutines();
                StartCoroutine(CoJump());

                CaptureSuccessfulJumpSnapshot();
            }
        }

        //If the player has buffered a jump (in the last 'BufferedJumpFramesInSeconds' seconds) and is grounded
        else if (onGround && (DateTime.Now - _lastAttemptedJumpPosition.Time).TotalSeconds <= BufferedJumpFramesInSeconds)
        {
            //If the player didn't just leave the ground in a jump (Don't want double jumps)
            if ((DateTime.Now - _lastSuccessfulJumpPosition.Time).TotalMilliseconds > DOUBLE_JUMP_PREVENTION_MILLIS)
            {
                StopAllCoroutines();
                StartCoroutine(CoJump());

                CaptureSuccessfulJumpSnapshot();
            }
        }

        /*
         * Limit falling speed
         */
        float maxFallSpeed = MaxFallSpeed;

        if (Commons.CurrentRoomEffects.HasFlag(RoomEffects.LowGravity))
        {
            maxFallSpeed *= Commons.RoomEffectController.LowGravityMultiplier;
        }

        _rigid.SetVelocityY(currentY => Math.Max(-maxFallSpeed, currentY));
    }
Ejemplo n.º 2
0
 public void CaptureSuccessfulJumpSnapshot()
 {
     _lastSuccessfulJumpPosition = PositionSnapshot.FromObject(_flippable);
     _lastAttemptedJumpPosition  = _lastSuccessfulJumpPosition;
 }