Game-Design / Sprint2 / Sprint2_actual / ActiveItems / LeftFireballSprite.cs
LeftFireballSprite.cs
Raw
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 LeftFireballSprite : AItemSprites
    {
        public Texture2D Texture { get; set; }
        public int SpriteWidth { get; set; }
        public int OscillatingFramesNum { get; set; }
        private int SpriteHeight { get; set; }
        public int SpriteX { get; set; }
        public int SpriteY { get; set; }
        private int X;
        private int Y;
        private int removeCounter;
        private int currentFrame;
        private bool advancing;
        private bool isFlying;
        public LeftFireballSprite(int x, int y, Texture2D texture)
        {
            IsRemoved = false;
            X = x;
            Y = y;
            OscillatingFramesNum = 1;
            currentFrame = 0;
            Texture = texture;
            advancing = true;
            isFlying = true;
            this.IsRemoved = false;
            SpriteHeight = 16;
            SpriteWidth = 8;
            SpriteX = 66;
            SpriteY = 65;
            removeCounter = 100;
        }
        public override void draw()
        {
            Rectangle sourceRectangle = new Rectangle(SpriteX + (currentFrame * SpriteWidth), SpriteY, SpriteWidth, SpriteHeight);
            Rectangle destinationRectangle = new Rectangle(X, Y, SpriteWidth, SpriteHeight);

            GlobalVars.spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White); //0f, new Vector2(X,Y), SpriteEffects.None, 0f);
        }

        public override void update(GameTime gameTime)
        {
            if ((int)gameTime.TotalGameTime.TotalMilliseconds % 60 < 15)
            {
                if (advancing)
                {
                    currentFrame++;
                    if (currentFrame == OscillatingFramesNum)
                    {
                        advancing = false;
                        currentFrame--;
                    }
                }
                else
                {
                    currentFrame--;
                    if (currentFrame < 0)
                    {
                        advancing = true;
                        currentFrame++;
                    }
                }
            }

            X -= (int)(gameTime.ElapsedGameTime.TotalMilliseconds * 0.175);
            removeCounter--;
            if (removeCounter == 0)
            {
                IsRemoved = true;
            }
        }
    }
}