Game-Design / Sprint3_actual / Link_State_Files / LinkSpriteDownWalking.cs
LinkSpriteDownWalking.cs
Raw
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Sprint3_actual.StateFiles;
using System;
using System.Collections.Generic;
using System.Text;

namespace Sprint3_actual.StateFiles
{
    class LinkSpriteDownWalking : 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 LinkSpriteDownWalking(Link link)
        {
            Texture = link.texture;
            SpriteWidth = 16;
            SpriteHeight = 16;
            SpriteX = 1;
            SpriteY = 11;
            Sprite2X = 18;
            Sprite2Y = 11;
            CurrentFrame = 0;
            Counter = 0;
            TotalFrames = 2;
            this.link = link;
        }
        public void draw()
        {
            Rectangle sourceRectangle = new Rectangle(SpriteX, SpriteY, SpriteWidth, SpriteHeight);
            Rectangle sourceRectangle2 = new Rectangle(Sprite2X, Sprite2Y, SpriteWidth, SpriteHeight);


            if (CurrentFrame == 0)
            {
                GlobalVars.spriteBatch.Draw(Texture, link.positionRectangle, sourceRectangle, link.linkColor);
            }

            else if (CurrentFrame == 1)
            {
                GlobalVars.spriteBatch.Draw(Texture, link.positionRectangle, sourceRectangle2, link.linkColor);
            }

        }

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