Game-Design / Sprint2 / Sprint2_actual / ActiveItems / UpFlamingArrowSprite.cs
UpFlamingArrowSprite.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 UpFlamingArrowSprite : 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 int X;
        private int Y;
        private int removeCounter;
        private bool isFlying;

        public UpFlamingArrowSprite(Vector2 pos, Texture2D texture)
        {
            IsRemoved = false;
            X = (int)pos.X;
            Y = (int)pos.Y;
            Texture = texture;
            SpriteHeight = 16;
            SpriteWidth = 5;
            SpriteX = 29;
            SpriteY = 185;
            removeCounter = 75;
            isFlying = true;
        }
        public override void draw()
        {
            Rectangle sourceRectangle;
            Rectangle destinationRectangle;
            if (isFlying)
            {
                sourceRectangle = new Rectangle(SpriteX, SpriteY, SpriteWidth, SpriteHeight);
                destinationRectangle = new Rectangle(X - 8, Y - 2, 2 * SpriteWidth, 2 * SpriteHeight);
            }
            else
            {
                sourceRectangle = new Rectangle(53, 189, 8, 8);
                destinationRectangle = new Rectangle(X - 8, Y - 2, 2 * 8, 2 * 8);
            }
            GlobalVars.spriteBatch.Draw(Texture, destinationRectangle, sourceRectangle, Color.White, 0f, Vector2.Zero, SpriteEffects.None, 0f);
        }

        public override void update(GameTime gameTime)
        {
            if (isFlying)
            {
                Y -= (int)(gameTime.ElapsedGameTime.TotalMilliseconds * 0.5);
            }
            removeCounter--;
            if (removeCounter == 0)
            {
                IsRemoved = true;
            }
            if (removeCounter < 10)
            {
                isFlying = false;
            }
        }
    }
}