public void SetSprites(Sprite[] s)
        {
            sprites = s;

            animations = new Dictionary <AnimationType, FrameAnimation>();

            animations.Add(AnimationType.HELMET_IDLE_NORTH, new FrameAnimation("in", new int[] { 0 }, 0.7f, false, false));
            animations.Add(AnimationType.HELMET_IDLE_EAST, new FrameAnimation("ie", new int[] { 1 }, 0.7f, false, false));
            animations.Add(AnimationType.HELMET_IDLE_SOUTH, new FrameAnimation("is", new int[] { 2 }, 0.7f, false, false));
            animations.Add(AnimationType.HELMET_IDLE_WEST, new FrameAnimation("iw", new int[] { 1 }, 0.7f, false, true));

            animations.Add(AnimationType.HELMET_WALK_NORTH, new FrameAnimation("wn", new int[] { 3, 4 }, 0.7f));
            animations.Add(AnimationType.HELMET_WALK_EAST, new FrameAnimation("we", new int[] { 5, 6 }, 0.7f));
            animations.Add(AnimationType.HELMET_WALK_SOUTH, new FrameAnimation("ws", new int[] { 7, 8 }, 0.7f));
            animations.Add(AnimationType.HELMET_WALK_WEST, new FrameAnimation("ww", new int[] { 5, 6 }, 0.7f, true, true));

            animations.Add(AnimationType.NOHELMET_IDLE_NORTH, new FrameAnimation("in", new int[] { 9 }, 0.2f, false, false));
            animations.Add(AnimationType.NOHELMET_IDLE_EAST, new FrameAnimation("ie", new int[] { 10 }, 0.2f, false, false));
            animations.Add(AnimationType.NOHELMET_IDLE_SOUTH, new FrameAnimation("is", new int[] { 11 }, 0.2f, false, false));
            animations.Add(AnimationType.NOHELMET_IDLE_WEST, new FrameAnimation("iw", new int[] { 10 }, 0.2f, false, true));

            animations.Add(AnimationType.NOHELMET_WALK_NORTH, new FrameAnimation("wn", new int[] { 12, 13 }, 0.2f));
            animations.Add(AnimationType.NOHELMET_WALK_EAST, new FrameAnimation("we", new int[] { 14, 15 }, 0.2f));
            animations.Add(AnimationType.NOHELMET_WALK_SOUTH, new FrameAnimation("ws", new int[] { 16, 17 }, 0.2f));
            animations.Add(AnimationType.NOHELMET_WALK_WEST, new FrameAnimation("ww", new int[] { 14, 15 }, 0.2f, true, true));

            currentAnimationType = AnimationType.HELMET_IDLE_SOUTH;
            currentAnimation     = animations[currentAnimationType];
            prevFrameIndex       = 0;
        }
        public void Update(float deltaTime)
        {
            int newAnimation = (int)character.CharFacing;

            if (character.IsWalking)
            {
                newAnimation += 10;
            }

            // TODO: What is the acceptable amount of O2 gas pressure?
            // Using .15 from Need.cs for now.
            if (character.CurrTile.GetGasPressure("O2") >= 0.15f)
            {
                newAnimation += 100; // Remove helmet
            }

            // check if we need to switch animations
            if (newAnimation != (int)currentAnimationType)
            {
                currentAnimationType = (AnimationType)newAnimation;
                currentAnimation     = animations[currentAnimationType];
                if (currentAnimation.FlipX == true && renderer.flipX == false)
                {
                    renderer.flipX = true;
                }
                else if (currentAnimation.FlipX == false && renderer.flipX == true)
                {
                    renderer.flipX = false;
                }
            }

            currentAnimation.Update(deltaTime);

            if (prevFrameIndex != currentAnimation.CurrentIndex)
            {
                ShowSprite(currentAnimation.CurrentIndex);
                prevFrameIndex = currentAnimation.CurrentIndex;
            }

            // if there was change in Y position, update the sorting order
            if (lastCharYPosition - character.Y != 0f)
            {
                CurrentSortingOrder   = Mathf.RoundToInt(character.Y * 100f) * -1;
                renderer.sortingOrder = CurrentSortingOrder;
            }

            lastCharYPosition = character.Y;
        }
        public void Update(float deltaTime)
        {
            int newAnimation = (int)character.CharFacing;

            if (character.IsWalking)
            {
                newAnimation += 10;
            }

            // TODO: What is the acceptable amount of O2 gas pressure?
            // Using .15 from Need.cs for now.
            if (character.CurrTile.GetGasPressure("O2") >= 0.15f)
            {
                newAnimation += 100; // Remove helmet
            }

            // check if we need to switch animations
            if (newAnimation != (int)currentAnimationType)
            {
                currentAnimationType = (AnimationType)newAnimation;
                currentAnimation     = animations[currentAnimationType];
                if (currentAnimation.FlipX == true && renderer.flipX == false)
                {
                    renderer.flipX = true;
                }
                else if (currentAnimation.FlipX == false && renderer.flipX == true)
                {
                    renderer.flipX = false;
                }
            }

            currentAnimation.Update(deltaTime);

            if (prevFrameIndex != currentAnimation.CurrentIndex)
            {
                ShowSprite(currentAnimation.CurrentIndex);
                prevFrameIndex = currentAnimation.CurrentIndex;
            }
        }
        public void SetSprites(Sprite[] s)
        {
            sprites = s;

            // make sure that every sprite has correct filtermode
            foreach (Sprite sprite in sprites)
            {
                sprite.texture.filterMode = FilterMode.Point;
            }

            animations = new Dictionary <AnimationType, FrameAnimation>();

            animations.Add(AnimationType.HELMET_IDLE_NORTH, new FrameAnimation("in", new int[] { 0 }, 0.7f, false, false));
            animations.Add(AnimationType.HELMET_IDLE_EAST, new FrameAnimation("ie", new int[] { 1 }, 0.7f, false, false));
            animations.Add(AnimationType.HELMET_IDLE_SOUTH, new FrameAnimation("is", new int[] { 2 }, 0.7f, false, false));
            animations.Add(AnimationType.HELMET_IDLE_WEST, new FrameAnimation("iw", new int[] { 1 }, 0.7f, false, true));

            animations.Add(AnimationType.HELMET_WALK_NORTH, new FrameAnimation("wn", new int[] { 3, 4 }, 0.7f));
            animations.Add(AnimationType.HELMET_WALK_EAST, new FrameAnimation("we", new int[] { 5, 6 }, 0.7f));
            animations.Add(AnimationType.HELMET_WALK_SOUTH, new FrameAnimation("ws", new int[] { 7, 8 }, 0.7f));
            animations.Add(AnimationType.HELMET_WALK_WEST, new FrameAnimation("ww", new int[] { 5, 6 }, 0.7f, true, true));

            animations.Add(AnimationType.NOHELMET_IDLE_NORTH, new FrameAnimation("in", new int[] { 9 }, 0.2f, false, false));
            animations.Add(AnimationType.NOHELMET_IDLE_EAST, new FrameAnimation("ie", new int[] { 10 }, 0.2f, false, false));
            animations.Add(AnimationType.NOHELMET_IDLE_SOUTH, new FrameAnimation("is", new int[] { 11 }, 0.2f, false, false));
            animations.Add(AnimationType.NOHELMET_IDLE_WEST, new FrameAnimation("iw", new int[] { 10 }, 0.2f, false, true));

            animations.Add(AnimationType.NOHELMET_WALK_NORTH, new FrameAnimation("wn", new int[] { 12, 13 }, 0.2f));
            animations.Add(AnimationType.NOHELMET_WALK_EAST, new FrameAnimation("we", new int[] { 14, 15 }, 0.2f));
            animations.Add(AnimationType.NOHELMET_WALK_SOUTH, new FrameAnimation("ws", new int[] { 16, 17 }, 0.2f));
            animations.Add(AnimationType.NOHELMET_WALK_WEST, new FrameAnimation("ww", new int[] { 14, 15 }, 0.2f, true, true));

            currentAnimationType = AnimationType.HELMET_IDLE_SOUTH;
            currentAnimation     = animations[currentAnimationType];
            prevFrameIndex       = 0;
        }