Exemplo n.º 1
0
        public void UpdateAnimation(DwarfTime gameTime, ChunkManager chunks, Camera camera)
        {
            float veloNorm = Physics.Velocity.Length();

            if (veloNorm > Stats.MaxSpeed)
            {
                Physics.Velocity = (Physics.Velocity / veloNorm) * Stats.MaxSpeed;
                if (IsOnGround && CurrentCharacterMode == CharacterMode.Idle)
                {
                    CurrentCharacterMode = CharacterMode.Walking;
                }
            }

            if (veloNorm > 0.25f)
            {
                if (IsOnGround && CurrentCharacterMode == CharacterMode.Idle)
                {
                    CurrentCharacterMode = CharacterMode.Walking;
                }
            }

            if (CurrentCharacterMode == CharacterMode.Attacking)
            {
                return;
            }

            if (!IsOnGround)
            {
                return;
            }

            if (veloNorm < 0.25f || Physics.IsSleeping)
            {
                if (CurrentCharacterMode == CharacterMode.Walking)
                {
                    CurrentCharacterMode = CharacterMode.Idle;
                }
            }
            else
            {
                if (CurrentCharacterMode == CharacterMode.Idle)
                {
                    CurrentCharacterMode = CharacterMode.Walking;
                    Animation walk = Sprite.GetAnimation(CharacterMode.Walking, Sprite.CurrentOrientation);
                    if (walk != null)
                    {
                        walk.SpeedMultiplier = MathFunctions.Clamp(veloNorm / Stats.MaxSpeed * 5.0f, 0.5f, 3.0f);
                    }
                }
            }
        }