Game-Design / Sprint3_actual / ActiveItems / FireProjectileSprite.cs
FireProjectileSprite.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.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 FireProjectile FireProjectile;

        public FireProjectileSprite(FireProjectile Fire, Texture2D texture)
        {
            Texture = texture;
            SpriteHeight = 16;
            SpriteWidth = 16;
            SpriteX = 191;
            SpriteY = 185;
            FireProjectile = Fire;
            currentFrame = 0;
            frames = 2;
            timeSinceFrameChange = 0;
            msPerFrame = 250;
        }
        public override void draw()
        {
            Rectangle sourceRectangle = new Rectangle(SpriteX, SpriteY, SpriteWidth, SpriteHeight);
            Rectangle destinationRectangle = FireProjectile.PositionRectangle();

            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;
                }
            }
        }
    }
}