Game-Design / Sprint3 / Link State Files / LinkSpriteLeftWalking.cs
LinkSpriteLeftWalking.cs
Raw
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Sprint2_actual.StateFiles;
using System;
using System.Collections.Generic;
using System.Text;

namespace Sprint2_actual.StateFiles
{
    class LinkSpriteLeftWalking : ISprite
    {
        public Texture2D Texture { get; set; }
        public int SpriteWidth { get; set; }
        private int SpriteHeight { get; set; }
        public int SpriteX { get; set; }
        public int SpriteY { get; set; }
        private Link link;

        //variables specific to animation
        private int CurrentFrame;
        private int TotalFrames;
        private int Counter;
        private int Sprite2X;
        private int Sprite2Y;
        public LinkSpriteLeftWalking(Link link)
        {
            Texture = link.texture;
            SpriteWidth = 16;
            SpriteHeight = 16;
            SpriteX = 35;
            SpriteY = 11;
            Sprite2X = 52;
            Sprite2Y = 11;
            CurrentFrame = 0;
            Counter = 0;
            TotalFrames = 2;
            this.link = link;
        }
        public void draw()
        {
            SpriteEffects flip = SpriteEffects.FlipHorizontally;
            Rectangle sourceRectangle = new Rectangle(SpriteX, SpriteY, SpriteWidth, SpriteHeight);
            Rectangle sourceRectangle2 = new Rectangle(Sprite2X, Sprite2Y, SpriteWidth, SpriteHeight);
            Rectangle destinationRectangle = new Rectangle(link.linkX - 8, link.linkY - 8, 2*SpriteWidth, 2*SpriteHeight);



            if (CurrentFrame == 0)
            {
                GlobalVars.spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, link.linkColor, 0f, Vector2.Zero, flip, 0f);
            }

            else if (CurrentFrame == 1)
            {
                GlobalVars.spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle2, link.linkColor, 0f, Vector2.Zero, flip, 0f);
            }

        }

        public void update(GameTime gameTime)
        {
            Counter++;
            if (Counter == 7)
            {
                CurrentFrame++;
                Counter = 0;
            }
            if (CurrentFrame == TotalFrames)
                CurrentFrame = 0;
        }
    }
}