JumpResult CanJump()
        {
            JumpResult jumpResult = JumpResult.Invalid;

            if (!verticalMovementParameters.canJump)
            {
                return(jumpResult);
            }

            if (wantToCrouch)
            {
                return(jumpResult);
            }


            switch (CharacterActor.CurrentState)
            {
            case CharacterActorState.StableGrounded:

                if (CharacterActions.jump.StartedElapsedTime <= verticalMovementParameters.preGroundedJumpTime && groundedJumpAvailable)
                {
                    jumpResult = JumpResult.Grounded;
                }

                break;

            case CharacterActorState.NotGrounded:

                if (CharacterActions.jump.Started)
                {
                    // First check if the "grounded jump" is available. If so, execute a "coyote jump".
                    if (CharacterActor.NotGroundedTime <= verticalMovementParameters.postGroundedJumpTime && groundedJumpAvailable)
                    {
                        jumpResult = JumpResult.Grounded;
                    }
                    else if (notGroundedJumpsLeft != 0)      // Do a not grounded jump
                    {
                        jumpResult = JumpResult.NotGrounded;
                    }
                }

                break;

            case CharacterActorState.UnstableGrounded:

                if (CharacterActions.jump.StartedElapsedTime <= verticalMovementParameters.preGroundedJumpTime && verticalMovementParameters.canJumpOnUnstableGround)
                {
                    jumpResult = JumpResult.Grounded;
                }

                break;
            }

            return(jumpResult);
        }
        public static JumpResult GetJumpResult(IJumpData jumpData, IHillInfo hillInfo, bool gateComp, bool windComp)
        {
            var jump = new JumpResult(jumpData.Distance, jumpData.JudgesMarks, jumpData.GatesDiff, jumpData.Wind,
                                      jumpData.Speed);

            jump.distancePoints = hillInfo.GetDistancePoints(jump.distance);
            jump.windPoints     = windComp ? hillInfo.GetWindPoints(jump.wind) : 0m;
            jump.gatePoints     = gateComp ? hillInfo.GetGatePoints(jump.gatesDiff) : 0m;
            jump.totalPoints    = Math.Max(0,
                                           jump.distancePoints + jump.judgesTotalPoints + jump.windPoints + jump.gatePoints);
            return(jump);
        }
Beispiel #3
0
    private void handleResultHints(Tile tile)
    {
        if (!onCorrectWay || JumpResult.Count == 0)
        {
            return;
        }

        JumpResult.RemoveAt(0);
        KeyValuePair <int, int> tilePosition = GetTilePosition(tile);

        if (tilePosition.Key != jumpResult[0].Key || tilePosition.Value != jumpResult[0].Value)
        {
            onCorrectWay = false;
        }
    }
        protected virtual void ProcessJump(float dt)
        {
            if (CharacterActor.IsGrounded)
            {
                notGroundedJumpsLeft = verticalMovementParameters.availableNotGroundedJumps;

                groundedJumpAvailable = true;
            }


            if (isAllowedToCancelJump)
            {
                if (verticalMovementParameters.cancelJumpOnRelease)
                {
                    if (CharacterActions.jump.StartedElapsedTime >= verticalMovementParameters.cancelJumpMaxTime || CharacterActor.IsFalling)
                    {
                        isAllowedToCancelJump = false;
                    }
                    else if (!CharacterActions.jump.value && CharacterActions.jump.StartedElapsedTime >= verticalMovementParameters.cancelJumpMinTime)
                    {
                        // Get the velocity mapped onto the current jump direction
                        Vector3 projectedJumpVelocity = Vector3.Project(CharacterActor.Velocity, jumpDirection);

                        CharacterActor.Velocity -= projectedJumpVelocity * (1f - verticalMovementParameters.cancelJumpMultiplier);

                        isAllowedToCancelJump = false;
                    }
                }
            }
            else
            {
                JumpResult jumpResult = CanJump();

                switch (jumpResult)
                {
                case JumpResult.Grounded:
                    groundedJumpAvailable = false;

                    break;

                case JumpResult.NotGrounded:
                    notGroundedJumpsLeft--;

                    break;

                case JumpResult.Invalid:
                    return;
                }

                // Events ---------------------------------------------------
                if (CharacterActor.IsGrounded)
                {
                    if (OnGroundedJumpPerformed != null)
                    {
                        OnGroundedJumpPerformed(true);
                    }
                }
                else
                {
                    if (OnNotGroundedJumpPerformed != null)
                    {
                        OnNotGroundedJumpPerformed(notGroundedJumpsLeft);
                    }
                }

                if (OnJumpPerformed != null)
                {
                    OnJumpPerformed();
                }

                // Define the jump direction ---------------------------------------------------
                jumpDirection = SetJumpDirection();

                // Force the not grounded state, without this the character will not leave the ground.
                CharacterActor.ForceNotGrounded();

                // First remove any velocity associated with the jump direction.
                CharacterActor.Velocity -= Vector3.Project(CharacterActor.Velocity, jumpDirection);
                CharacterActor.Velocity += jumpDirection * verticalMovementParameters.JumpSpeed;

                if (verticalMovementParameters.cancelJumpOnRelease)
                {
                    isAllowedToCancelJump = true;
                }
            }
        }