Example #1
0
        private void TickAnimation_(TickAnimationEvent _)
        {
            var useStateColor = false;

            if (useStateColor)
            {
                var stateColor = this.stateMachine_.State switch {
                    PlayerState.STANDING => Color.White,
                    PlayerState.WALKING => Color.Yellow,
                    PlayerState.RUNNING => Color.Orange,
                    PlayerState.TURNING => Color.Magenta,
                    PlayerState.STOPPING => Color.Bisque,
                    PlayerState.DUCKING => Color.Chartreuse,
                    PlayerState.DUCKWALKING => Color.ForestGreen,
                    PlayerState.SLIDING => Color.LightGreen,
                    PlayerState.JUMPING => Color.Cyan,
                    PlayerState.WALL_SLIDING => Color.MediumPurple,
                    PlayerState.WALLJUMPING => Color.Maroon,
                    PlayerState.BACKFLIPPING => Color.Purple,
                    PlayerState.LONGJUMPING => Color.DodgerBlue,
                    PlayerState.FALLING => Color.RoyalBlue,
                    PlayerState.LANDING => Color.Blue,
                    PlayerState.INITIALLY_FALLING_OFF_LEDGE => Color.CadetBlue,
                    _ => Color.Black,
                };
                this.boxPlayerRenderer_.Color = stateColor;
            }
            else
            {
                this.boxPlayerRenderer_.Color = ColorConstants.WHITE;
            }
        }
        private void TickAnimations_(TickAnimationEvent _)
        {
            if (this.stateMachine_.IsMovingUprightOnGround ||
                this.stateMachine_.IsMovingDuckedOnGround)
            {
                this.distanceToNextFootstep_ -=
                    FloatMath.Abs(this.rigidbody_.XVelocity);
            }

            if (this.distanceToNextFootstep_ <= 0)
            {
                var isUpright = this.stateMachine_.IsMovingUprightOnGround;
                this.PlayAtRandomPitch_(isUpright
                                    ? this.footstepHeavy_
                                    : this.footstepLight_);

                this.distanceToNextFootstep_ += this.distanceBetweenFootsteps_;
            }
        }
Example #3
0
 public void TickAnimations(TickAnimationEvent _)
 {
 }
Example #4
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);
        }
 public void TickAnimations(TickAnimationEvent _)
 => this.CurrentItem.TickAnimations(_);