Пример #1
0
        private void AiComponent_StateChanged1(T arg1, T arg2)
        {
            string anim;

            if (!AnimalType.AnimationMappings.TryGetValue(arg2, out anim))
            {
                anim = AnimalType.DefaultAnimation;
            }

            animation.SwitchTo(anim);
        }
Пример #2
0
        public void SwitchToState(PlayerState newState)
        {
            State = newState;

            switch (State)
            {
            case PlayerState.Luring:
                attractAnim.SwitchTo("playing");
                scareAnim.SwitchTo("stopped");
                break;

            case PlayerState.Shouting:
                attractAnim.SwitchTo("stopped");
                scareAnim.SwitchTo("playing");
                break;

            default:
                attractAnim.SwitchTo("stopped");
                scareAnim.SwitchTo("stopped");
                break;
            }
        }
        public void Update(float elapsedSeconds, float totalSeconds)
        {
            float   currentMovementSpeed = GetCurrentSpeed();
            Vector2 desiredVelocity;

            // Regenerate stamina
            if (stamina < 1.0f)
            {
                stamina += staminaRegenerationRate * elapsedSeconds;
            }

            // While dashing
            if (playerEntity.State == PlayerState.Dashing)
            {
                desiredVelocity = dashDirection * currentMovementSpeed;
                dashTime       += elapsedSeconds;
                //Entity.Body.Mass = 2000;
            }
            else if (playerEntity.State == PlayerState.Dizzy)
            {
                dizzyTime += elapsedSeconds;
                var intendedSpeed   = inputMovementDirection.Length();
                var isStandingStill = intendedSpeed <= 0.001f;
                var perpendicularV  =
                    (isStandingStill)
                        ? (VectorExtensions.AngleToUnitVector(Entity.Body.Rotation + (float)Math.PI / 2.0f))
                        : (new Vector2(inputMovementDirection.Y, -inputMovementDirection.X).Normalized());
                var inDirectionV = new Vector2(perpendicularV.Y, -perpendicularV.X);

                // Add 'drunk' on movement on top of input
                float drunkNoise1 = (float)(0.5 * Math.Sin(3.4 + totalSeconds * 7.1f) + 0.8 * Math.Sin(totalSeconds * 5.1f) + 1.3 * Math.Sin(1.2f + totalSeconds * 3.3f));
                float drunkNoise2 = (float)(0.3 * Math.Sin(2.1 + totalSeconds * 8.3f) + 0.5 * Math.Sin(totalSeconds * 4.7f) + 0.7 * Math.Sin(5.2f + totalSeconds * 2.5f));
                // adjust the noise when standing still, as otherwise the player just spinns around like crazy
                float d1 = (isStandingStill) ? 0.1f * drunkNoise1 : drunkNoise1;
                float d2 = (isStandingStill) ? (drunkNoise2 + 1.5f) * 0.3f : drunkNoise2;
                desiredVelocity =
                    (inputMovementDirection + inDirectionV * d2 + perpendicularV * d1).Normalized() *
                    (intendedSpeed * 0.3f + 0.3f) * currentMovementSpeed;
                UpdateRotation(elapsedSeconds, desiredVelocity);
            }
            else
            {
                desiredVelocity = inputMovementDirection * currentMovementSpeed;
                UpdateRotation(elapsedSeconds, desiredVelocity);
            }

            // reset dash
            if (playerEntity.State == PlayerState.Dashing && !(dashTime < totalDashTime))
            {
                ResetDash();
            }
            // reset dizzy
            if (playerEntity.State == PlayerState.Dizzy && !(dizzyTime < totalDizzyTime))
            {
                ResetDizzy();
            }



            float drag = 0.2f;

            // interpolate from the current velocity to the desired velocity
            Entity.Body.LinearVelocity = drag * desiredVelocity + (1.0f - drag) * Entity.Body.LinearVelocity;


            // player animation
            if (playerEntity.State == PlayerState.Dashing)
            {
                animationComponent.SwitchTo("dashing");
            }
            else if (playerEntity.State == PlayerState.Dizzy)
            {
                animationComponent.SwitchTo("dizzy");
            }
            else
            {
                if (Entity.Body.LinearVelocity.LengthSquared() > 0.1f)
                {
                    animationComponent.SwitchTo("walking");
                }
                else
                {
                    animationComponent.SwitchTo("standing");
                }
            }
        }