Game-Design / Sprint3_actual / ActiveItems / FlamingArrow.cs
FlamingArrow.cs
Raw
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Sprint3_actual.StateFiles;
using Sprint3_actual.SoundManagement;
using System;
using System.Collections.Generic;
using System.Text;

namespace Sprint3_actual.ActiveItems
{
    public class FlamingArrow : IActiveItem
    {

        private ILink link;
        private Game1 game;
        private Texture2D texture;
        public int ItemX;
        public int ItemY;
        public Rectangle itemRectangle { get; set; }
        private int SpriteHeight;
        private int SpriteWidth;
        private bool hasCollided;
        private bool Removed;
        private int removeCounter;
        private enum Direction
        {
            Up,
            Down,
            Left,
            Right
        }
        private Direction direction;
        private AItemSprites ItemSprite;
        private const int shift = 16;
        private const double speedmultiplier = 0.5;
        public FlamingArrow(ILink link, Game1 game)
        {
            this.link = link;
            this.game = game;
            texture = game.PlayerTexture;
            Removed = true;
            hasCollided = false;
        }
        public void ActiveItemDown()
        {
            if (Removed)
            {
                Vector2 pos = link.Position();
                ItemX = (int)pos.X + shift;
                ItemY = (int)pos.Y;
                direction = Direction.Down;
                SpriteHeight = 48;
                SpriteWidth = 15;
                Removed = false;
                hasCollided = false;
                removeCounter = 10;
                ItemSprite = new DownFlamingArrowSprite(this, texture);
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public void ActiveItemLeft()
        {
            if (Removed)
            {
                Vector2 pos = link.Position();
                ItemX = (int)pos.X;
                ItemY = (int)pos.Y + shift;
                direction = Direction.Left;
                SpriteHeight = 15;
                SpriteWidth = 48;
                Removed = false;
                hasCollided = false;
                removeCounter = 10;
                ItemSprite = new LeftFlamingArrowSprite(this, texture);
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public void ActiveItemRight()
        {
            if (Removed)
            {
                Vector2 pos = link.Position();
                ItemX = (int)pos.X;
                ItemY = (int)pos.Y + shift;
                direction = Direction.Right;
                SpriteHeight = 15;
                SpriteWidth = 48;
                Removed = false;
                hasCollided = false;
                removeCounter = 10;
                ItemSprite = new RightFlamingArrowSprite(this, texture);
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public void ActiveItemUp()
        {
            if (Removed)
            {
                Vector2 pos = link.Position();
                ItemX = (int)pos.X + shift;
                ItemY = (int)pos.Y;
                direction = Direction.Up;
                SpriteHeight = 48;
                SpriteWidth = 15;
                Removed = false;
                hasCollided = false;
                removeCounter = 10;
                ItemSprite = new UpFlamingArrowSprite(this, texture);
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public Rectangle PositionRectangle()
        {
            return itemRectangle;
        }
        public float Collide()
        {
            hasCollided = true;
            return 2.5f;
        }
        public bool HasCollided()
        {
            return hasCollided;
        }

        public void Draw()
        {
            if (!Removed)
                ItemSprite.draw();
        }

        public bool IsRemoved()
        {
            return Removed;
        }


        public void Remove()
        {
            Removed = true;
        }

        public void Update()
        {
            if (!Removed)
            {
                if (!hasCollided)
                {
                    if (direction == Direction.Up)
                    {
                        ItemY -= (int)(GlobalVars.gameTime.ElapsedGameTime.TotalMilliseconds * speedmultiplier);
                    }
                    else if (direction == Direction.Down)
                    {
                        ItemY += (int)(GlobalVars.gameTime.ElapsedGameTime.TotalMilliseconds * speedmultiplier);
                    }
                    else if (direction == Direction.Left)
                    {
                        ItemX -= (int)(GlobalVars.gameTime.ElapsedGameTime.TotalMilliseconds * speedmultiplier);
                    }
                    else
                    {
                        ItemX += (int)(GlobalVars.gameTime.ElapsedGameTime.TotalMilliseconds * speedmultiplier);
                    }
                    itemRectangle = new Rectangle(ItemX, ItemY, SpriteWidth, SpriteHeight);
                }

            }
            if (hasCollided)
            {
                removeCounter--;
                if (removeCounter == 0)
                {
                    Removed = true;
                    hasCollided = false;
                    itemRectangle = Rectangle.Empty;
                }
            }
        }
        public void ItemSound()
        {
            SoundEngine.Instance.playArrowShot();
        }

    }
}