Beispiel #1
0
 public ClimbingState(Climb climb, Collider2D col, float movementSpeed, float animationSpeed, ColliderPoint pivot, ColliderPoint player, DirectionFacing climbSide)
 {
     Climb          = climb;
     PivotCollider  = col;
     MovementSpeed  = movementSpeed;
     AnimationSpeed = animationSpeed;
     PivotPosition  = pivot;
     PlayerPosition = player;
     ClimbSide      = climbSide;
     IsUpright      = col.IsUpright();
     IsCorner       = col.IsCorner();
     CanClimbDown   = col.CanClimbDown();
 }
Beispiel #2
0
        public Climb SwitchClimbingState(DirectionFacing direction, bool hanging = false)
        {
            NextClimbingState = new ClimbingState();
            if (CurrentClimbingState.PivotCollider == null)
            {
                return(Climb.None);
            }

            _anim.SetBool("onCorner", CurrentClimbingState.IsUpright);

            var        nextClimb     = Climb.None;
            Climb      currentClimb  = CurrentClimbingState.Climb;
            Collider2D climbCollider = CurrentClimbingState.PivotCollider;

            if (currentClimb == Climb.AcrossLeft || currentClimb == Climb.AcrossRight)
            {
                currentClimb = CurrentClimbingState.PlayerPosition == ColliderPoint.TopLeft || CurrentClimbingState.PlayerPosition == ColliderPoint.TopRight ? Climb.Down : Climb.Up;
            }

            DirectionFacing directionFacing = _motor.GetDirectionFacing();

            if (direction == DirectionFacing.None)
            {
                direction = directionFacing;
            }

            bool forward = direction == directionFacing;

            _anim.SetBool(PlayerAnimBool.Forward, forward);

            switch (currentClimb)
            {
            case Climb.Mantle:
            case Climb.Flip:
            case Climb.Up:
                if (NextClimbs.Contains(Climb.Down) && CanVault() == false)
                {
                    nextClimb = Climb.Down;
                }
                else if (NextClimbs.Contains(Climb.Up) && CheckLedgeAbove(direction, out nextClimb))
                {
                }
                else if (NextClimbs.Contains(Climb.AcrossLeft) && ClimbSide == DirectionFacing.Left)
                {
                    nextClimb = CheckLedgeAcross(DirectionFacing.Left)
                                                        ? Climb.AcrossLeft
                                                        : Climb.Jump;
                }
                else if (NextClimbs.Contains(Climb.AcrossRight) && ClimbSide == DirectionFacing.Right)
                {
                    nextClimb = CheckLedgeAcross(DirectionFacing.Right)
                                                        ? Climb.AcrossRight
                                                        : Climb.Jump;
                }
                else
                {
                    _anim.SetBool(PlayerAnimBool.Moving, NextClimbs.Contains(Climb.AcrossLeft) || NextClimbs.Contains(Climb.AcrossRight));
                }

                if (nextClimb == Climb.Jump && climbCollider.CanClimbDown() == false)
                {
                    nextClimb = Climb.None;
                }
                break;

            case Climb.Down:
            case Climb.Hang:
                if (NextClimbs.Contains(Climb.Up) && (EdgeValidator.CanClimbUpOrDown(climbCollider, _motor.CrouchedCollider) || CheckLedgeWhileHanging()))
                {
                    nextClimb = Climb.Up;
                }
                else if (NextClimbs.Contains(Climb.AcrossLeft) && (CurrentClimbingState.IsUpright == false || ClimbSide == DirectionFacing.Left))
                {
                    nextClimb = hanging && directionFacing == DirectionFacing.Right
                                                        ? Climb.AcrossLeft
                                                        : CheckLedgeAcross(DirectionFacing.Left)
                                                                ? Climb.AcrossLeft
                                                                : Climb.Jump;
                }
                else if (NextClimbs.Contains(Climb.AcrossRight) && (CurrentClimbingState.IsUpright == false || ClimbSide == DirectionFacing.Right))
                {
                    nextClimb = hanging && directionFacing == DirectionFacing.Left
                                                        ? Climb.AcrossRight
                                                        : CheckLedgeAcross(DirectionFacing.Right)
                                                                ? Climb.AcrossRight
                                                                : Climb.Jump;
                }
                else if (NextClimbs.Contains(Climb.Down))
                {
                    nextClimb = Climb.Down;
                }
                else
                {
                    nextClimb = Climb.Hang;
                }

                if ((nextClimb == Climb.Jump || nextClimb == Climb.Down) && CurrentClimbingState.CanClimbDown == false)
                {
                    nextClimb = Climb.Down;
                }

                if (nextClimb == Climb.Jump && NextClimbs.Contains(Climb.Up) && (NextClimbs.Contains(Climb.AcrossLeft) || NextClimbs.Contains(Climb.AcrossRight)))
                {
                    nextClimb = Climb.None;
                }

                if (nextClimb == Climb.Down)
                {
                    _motor.MovementState.IsGrounded = false;
                }

                break;
            }

            if (NextClimbingState.Climb == Climb.None)
            {
                CurrentClimbingState.Climb = nextClimb;
            }

            _motor.MovementState.WasOnSlope = false;
            NextClimbs.Clear();
            _motor.Anim.SetBool("sameEdge", NextClimbingState.Climb == Climb.None && nextClimb != Climb.None);

            return(nextClimb);
        }