Пример #1
0
        public void ProcessInputs(ProcessInputsEvent _)
        {
            var secondaryAnalogStick = this.gamepad_[AnalogStickType.SECONDARY];
            var secStickX            = secondaryAnalogStick.RawAxes.X;
            var secStickY            = secondaryAnalogStick.RawAxes.Y;

            var secStickMag = TrigMath.DistanceBetween(0, 0, secStickX, secStickY);

            if (secStickMag < GamepadConstants.DEADZONE)
            {
                secStickMag = 0;
            }

            var wasShieldOut = this.isShieldOut_;

            this.isShieldOut_ = secStickMag > 0;

            if (this.isShieldOut_)
            {
                var secStickDeg = TrigMath.DegreesBetween(0, 0, secStickX, secStickY);

                var toHandDeg = secStickDeg;

                var maxHorizontalHandDis = this.playerRigidbody_.Width / 2 + 2;
                var maxVerticalHandDis   = this.playerRigidbody_.Height / 2 + 2;
                var maxHandDis           =
                    FloatMath.Abs(
                        TrigMath.LenDegX(maxHorizontalHandDis, secStickDeg)) +
                    FloatMath.Abs(
                        TrigMath.LenDegY(maxVerticalHandDis, secStickDeg));

                var toHandDis = maxHandDis * secStickMag;

                if (!wasShieldOut)
                {
                    this.handDis_ = toHandDis;
                    this.handDeg_ = toHandDeg;
                }
                else
                {
                    var accFactor = 3;

                    this.handDis_ += (toHandDis - this.handDis_) / accFactor;
                    this.handDeg_ +=
                        TrigMath.DifferenceInDegrees(toHandDeg, this.handDeg_) /
                        accFactor;
                }
            }
        }
Пример #2
0
        // TODO: Remove this.
        public void UpdateMatrices()
        {
            if (this.parent_ == null)
            {
                this.endImpl_.X = this.startImpl_.X = this.Transform.X;
                this.endImpl_.Y = this.startImpl_.Y = this.Transform.Y;

                this.transform_.GlobalDeg = this.Transform.RelativeDeg;
                return;
            }

            var startX = this.startImpl_.X = this.parent_.End.X + this.Transform.X;
            var startY = this.startImpl_.Y = this.parent_.End.Y + this.Transform.Y;

            var length  = this.transform_.Length;
            var globDeg = this.transform_.GlobalDeg =
                this.parent_.transform_.GlobalDeg +
                this.transform_.RelativeDeg;

            this.endImpl_.X = startX + TrigMath.LenDegX(length, globDeg);
            this.endImpl_.Y = startY - TrigMath.LenDegY(length, globDeg);
        }
Пример #3
0
        private void TickAnimation_(TickAnimationEvent _)
        {
            var xVel = this.playerRigidbody_.XVelocity;

            var xVelSign = MathF.Sign(xVel);

            if (xVelSign != 0)
            {
                this.xDir_ = xVelSign;
            }

            var isStanding    = this.stateMachine_.State == PlayerState.STANDING;
            var isWalking     = this.stateMachine_.State == PlayerState.WALKING;
            var isRealRunning = this.stateMachine_.State == PlayerState.RUNNING;

            if (isStanding)
            {
                this.frameFraction_.Value += .01f;
            }

            if (isWalking)
            {
                var walkFraction = FloatMath.Abs(this.playerRigidbody_.XVelocity) /
                                   PlayerConstants.UPRIGHT_MAX_SLOW_XSPD;
                var animationSpeed = FloatMath.Max(.01f, .02f * walkFraction);

                this.frameFraction_.Value += animationSpeed;
            }

            if (isRealRunning)
            {
                var runFraction = FloatMath.Abs(this.playerRigidbody_.XVelocity) /
                                  PlayerConstants.UPRIGHT_MAX_FAST_XSPD;
                var animationSpeed = FloatMath.Max(.01f, .04f * runFraction);

                this.frameFraction_.Value += animationSpeed;
            }

            var frameFraction = this.frameFraction_.Value;
            var frameAngle    = this.frameFraction_.Value * 360;

            var hipWidth      = PlayerConstants.HSIZE * .6f;
            var backHipWidth  = .4f * hipWidth;
            var frontHipWidth = hipWidth - backHipWidth;

            if (isStanding)
            {
                this.hipCenter_.Transform.RelativeDeg = 0;
                this.hipLeft_.Transform.Length        = frontHipWidth;
                this.hipRight_.Transform.Length       = backHipWidth;

                var leanAngle = this.OscillateAround_(15, 15, frameAngle);

                this.upperLegLeft_.Transform.RelativeDeg  = 90 + leanAngle;
                this.upperLegRight_.Transform.RelativeDeg = -90 + leanAngle;

                this.lowerLegLeft_.Transform.RelativeDeg  = -leanAngle;
                this.lowerLegRight_.Transform.RelativeDeg = -leanAngle;
            }


            if (isWalking)
            {
                var hipAngle = TrigMath.LenDegX(15, -20 + frameAngle);
                this.hipCenter_.Transform.RelativeDeg = hipAngle;

                this.hipLeft_.Transform.Length =
                    frontHipWidth * this.OscillateAround_(1, .5f, hipAngle + 180);
                this.hipRight_.Transform.Length =
                    backHipWidth * this.OscillateAround_(1, .5f, hipAngle);

                var upperLegRange = 20;
                this.upperLegLeft_.Transform.RelativeDeg =
                    90 + TrigMath.LenDegX(upperLegRange / 2, frameAngle);
                this.upperLegRight_.Transform.RelativeDeg =
                    -90 + TrigMath.LenDegX(upperLegRange / 2, frameAngle + 180);

                var lowerLegAngle = -15 + frameAngle;
                var lowerLegRange = 30;
                this.lowerLegLeft_.Transform.RelativeDeg =
                    -lowerLegRange / 2 +
                    TrigMath.LenDegX(lowerLegRange / 2, lowerLegAngle);
                this.lowerLegRight_.Transform.RelativeDeg =
                    -lowerLegRange / 2 +
                    TrigMath.LenDegX(lowerLegRange / 2, lowerLegAngle + 180);
            }


            if (isRealRunning)
            {
                var hipAngle = TrigMath.LenDegX(15, -45 + frameAngle);
                this.hipCenter_.Transform.RelativeDeg = hipAngle;

                this.hipLeft_.Transform.Length =
                    frontHipWidth * this.OscillateAround_(1, .5f, hipAngle + 180);
                this.hipRight_.Transform.Length =
                    backHipWidth * this.OscillateAround_(1, .5f, hipAngle);

                this.upperLegLeft_.Transform.RelativeDeg =
                    180 + this.CalcUpperBoneAngle_(frameFraction, false);
                this.upperLegRight_.Transform.RelativeDeg =
                    this.CalcUpperBoneAngle_(frameFraction, true);

                this.lowerLegLeft_.Transform.RelativeDeg =
                    this.CalcLowerBoneAngle_(frameFraction, false);
                this.lowerLegRight_.Transform.RelativeDeg =
                    this.CalcLowerBoneAngle_(frameFraction, true);
            }

            // TODO: Should this happen automatically?
            this.ForEachBone_(bone => bone.UpdateMatrices());

            var leftHeight =
                FloatMath.Abs(TrigMath.LenDegY(this.upperLegLeft_.Transform.Length,
                                               this.upperLegLeft_.Transform
                                               .GlobalDeg)) +
                FloatMath.Abs(TrigMath.LenDegY(this.lowerLegLeft_.Transform.Length,
                                               this.lowerLegLeft_.Transform
                                               .GlobalDeg));
            var rightHeight =
                FloatMath.Abs(TrigMath.LenDegY(this.upperLegRight_.Transform.Length,
                                               this.upperLegRight_.Transform
                                               .GlobalDeg)) +
                FloatMath.Abs(TrigMath.LenDegY(this.lowerLegRight_.Transform.Length,
                                               this.lowerLegRight_.Transform
                                               .GlobalDeg));

            this.legHeight_ = FloatMath.Max(leftHeight, rightHeight);
        }