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.ActiveItems { class FireProjectileSprite : AItemSprites { public Texture2D Texture { get; set; } private int SpriteWidth; private int SpriteHeight; private int SpriteX; private int SpriteY; private int currentFrame; private int frames; private int timeSinceFrameChange; private int msPerFrame; private int X; private int Y; private int removeCounter; private bool isMoving; private int direction; public FireProjectileSprite(Vector2 pos, Texture2D texture, int direction) { IsRemoved = false; X = (int)pos.X; Y = (int)pos.Y; Texture = texture; SpriteHeight = 16; SpriteWidth = 16; SpriteX = 191; SpriteY = 185; currentFrame = 0; frames = 2; timeSinceFrameChange = 0; msPerFrame = 250; removeCounter = 80; isMoving = true; this.direction = direction; if(this.direction == 1) { this.X += 32; } else if(this.direction == 2) { this.X -= 32; } else if(this.direction == 3) { this.Y -= 32; } else { this.Y += 32; } } public override void draw() { Rectangle sourceRectangle = new Rectangle(SpriteX, SpriteY, SpriteWidth, SpriteHeight); Rectangle destinationRectangle = new Rectangle(X-8, Y-8, 2 * SpriteWidth, 2 * SpriteHeight); if (currentFrame == 0) { GlobalVars.spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0f); } else { GlobalVars.spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White, 0f, Vector2.Zero, SpriteEffects.FlipHorizontally, 0f); } } public override void update(GameTime gameTime) { this.timeSinceFrameChange += gameTime.ElapsedGameTime.Milliseconds; if (this.timeSinceFrameChange > this.msPerFrame) { this.timeSinceFrameChange = 0; this.currentFrame++; if (this.currentFrame == this.frames) { this.currentFrame = 0; } } if (isMoving) { if (direction == 1) { X += (int)(gameTime.ElapsedGameTime.TotalMilliseconds * 0.15); } else if (direction == 2) { X -= (int)(gameTime.ElapsedGameTime.TotalMilliseconds * 0.15); } else if (direction == 3) { Y -= (int)(gameTime.ElapsedGameTime.TotalMilliseconds * 0.15); } else { Y += (int)(gameTime.ElapsedGameTime.TotalMilliseconds * 0.15); } } removeCounter--; if (removeCounter == 0) { IsRemoved = true; } if (removeCounter < 40) { isMoving = false; } } } }