Game-Design / Sprint3_actual / ActiveItems / FireballSprite.cs
FireballSprite.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 FireballSprite : AItemSprites
    {
        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 Fireball fireball;
        private int msPerFrame, timeSinceFrameChange, frames, currentFrame;
        public FireballSprite(Fireball fireball, Texture2D texture)
        {
            IsRemoved = false;
            Texture = texture;
            this.fireball = fireball;
            SpriteHeight = 10;
            SpriteWidth = 8;
            SpriteX = 66;
            SpriteY = 68;
            msPerFrame = 100;
            currentFrame = 0;
            frames = 3;
        }
        public override void draw()
        {
            Rectangle sourceRectangle = new Rectangle(SpriteX, SpriteY, SpriteWidth, SpriteHeight);

            GlobalVars.spriteBatch.Draw(Texture, fireball.PositionRectangle(), sourceRectangle, Color.White);
        }

        public override void update(GameTime gameTime)
        {
            timeSinceFrameChange += gameTime.ElapsedGameTime.Milliseconds;
            if (timeSinceFrameChange > msPerFrame)
            {
                timeSinceFrameChange = 0;

                SpriteX += SpriteWidth;

                if (currentFrame == frames)
                {
                    currentFrame = 0;
                }
            }
        }
    }
}