using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Sprint2_actual.StateFiles; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Sprint2_actual { class AnimatedMovingSprite : ISprite { public Texture2D Texture { get; set; } public int OscilatingFramesNum { get; set; } public int SpriteWidth { get; set; } private Link link; private int currentFrame; private bool advancing; private List<int> XVals { get; set; } private int YVal { get; set; } public AnimatedMovingSprite(Texture2D texture, int oscilatingFramesNum, int spriteWidth, List<int> xVals, int yVal, Link link) { Texture = texture; OscilatingFramesNum = oscilatingFramesNum; SpriteWidth = spriteWidth; XVals = xVals; YVal = yVal; this.link = link; currentFrame = 0; advancing = true; } public void draw() { Rectangle sourceRectangle; //= new Rectangle(StartingSpriteX + (currentFrame * SpriteWidth), StartingSpriteY, SpriteWidth, SpriteWidth); Rectangle destinationRectangle; //= new Rectangle((int)pos.X, (int)pos.Y, SpriteWidth, SpriteWidth); if (currentFrame == 0) { sourceRectangle = new Rectangle(XVals.ElementAt(0), YVal, 115, 115); destinationRectangle = new Rectangle((int)link.linkX - 57, (int)link.linkY - 57, 115, 115); } else { sourceRectangle = new Rectangle(XVals.ElementAt(1), YVal, 115, 115); destinationRectangle = new Rectangle((int)link.linkX - 57, (int)link.linkY - 57, 115, 115); } GlobalVars.spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White); } public void update(GameTime gameTime) { if ((int)gameTime.TotalGameTime.TotalMilliseconds % 60 < 15) { if (advancing) { currentFrame++; if (currentFrame == OscilatingFramesNum) { advancing = false; currentFrame--; } } else { currentFrame--; if (currentFrame < 0) { advancing = true; currentFrame++; } } } } } }