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

namespace Sprint3_actual.ActiveItems
{
    public class FireProjectile : IActiveItem
    {

        private ILink link;
        private Game1 game;
        private Texture2D texture;
        private int SpriteWidth;
        private int SpriteHeight;
        private Vector2 Velocity;
        private Vector2 Pos;
        private Rectangle ItemRectanlge;
        private AItemSprites ItemSprite;
        private bool Removed;
        private int RemoveCounter;
        public FireProjectile(ILink link, Game1 game)
        {
            this.link = link;
            this.game = game;
            texture = game.PlayerTexture;
            SpriteHeight = 48;
            SpriteWidth = 48;
            Removed = true;
        }
        public void ActiveItemDown()
        {
            if (Removed)
            {
                Pos = link.Position();
                Pos += new Vector2(0, 48);
                Velocity = new Vector2(0, 1);
                ItemSprite = new FireProjectileSprite(this, texture);
                Removed = false;
                RemoveCounter = GlobalVars.itemCounter;
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public void ActiveItemLeft()
        {
            if (Removed)
            {
                Pos = link.Position();
                Pos += new Vector2(-48, 0);
                Velocity = new Vector2(-1, 0);
                ItemSprite = new FireProjectileSprite(this, texture);
                Removed = false;
                RemoveCounter = GlobalVars.itemCounter;
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public void ActiveItemRight()
        {
            if (Removed)
            {
                Pos = link.Position();
                Pos += new Vector2(48, 0);
                Velocity = new Vector2(1, 0);
                ItemSprite = new FireProjectileSprite(this, texture);
                Removed = false;
                RemoveCounter = GlobalVars.itemCounter;
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public void ActiveItemUp()
        {
            if (Removed)
            {
                Pos = link.Position();
                Pos += new Vector2(0, -48);
                Velocity = new Vector2(0, -1);
                ItemSprite = new FireProjectileSprite(this, texture);
                Removed = false;
                RemoveCounter = GlobalVars.itemCounter;
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public float Collide()
        {
            Velocity = Vector2.Zero;
            return 1.0f;
        }

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

        public bool IsRemoved()
        {
            return Removed;
        }

        public Rectangle PositionRectangle()
        {
            return ItemRectanlge;
        }

        public void Remove()
        {
            Removed = true;
        }

        public void Update()
        {
            if (!Removed)
            {
                ItemSprite.update(GlobalVars.gameTime);
                if (RemoveCounter == 0)
                {
                    Removed = true;
                }
                if (RemoveCounter > 30)
                {
                    Pos += Velocity;
                }
                
                RemoveCounter--;
                ItemRectanlge = new Rectangle((int)Pos.X, (int)Pos.Y, SpriteWidth, SpriteHeight);
            }
        }
        public void ItemSound()
        {
            SoundEngine.Instance.playFlameShot();
        }
    }
}