Game-Design / Sprint3_actual / ActiveItems / Fireball.cs
Fireball.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 Fireball : IActiveItem
    {

        private Texture2D texture;
        public int ItemX;
        public int ItemY;
        private Rectangle itemRectangle;
        private Vector2 Velocity;
        private bool Removed;
        private int removeCounter;
        private AItemSprites ItemSprites;
        private const double speedmultiplier = 0.175;
        private room Room;
        public Fireball(Texture2D Texture, int X, int Y, Vector2 direction, room Room)
        {
            ItemX = X;
            ItemY = Y;
            texture = Texture;
            Velocity = direction;
            itemRectangle = new Rectangle(ItemX, ItemY, 16, 20);
            removeCounter = 80;
            ItemSprites = new FireballSprite(this, texture);
            this.Room = Room;
        }
        public void ActiveItemDown()
        {
            throw new NotImplementedException();
        }

        public void ActiveItemLeft()
        {
            Room.EnemyItems.Add(this);
        }

        public void ActiveItemRight()
        {
            throw new NotImplementedException();
        }

        public void ActiveItemUp()
        {
            throw new NotImplementedException();
        }

        public float Collide()
        {
            Remove();
            return 1.0f;
        }

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

        public bool IsRemoved()
        {
            return Removed;
        }

        public Rectangle PositionRectangle()
        {
            return itemRectangle;
        }

        public void Remove()
        {
            Removed = true;
            removeCounter = 0;
        }

        public void Update()
        {
            removeCounter--;
            if(removeCounter == 0)
            {
                Remove();
            }
            if (!Removed)
            {
                itemRectangle.X += (int)(Velocity.X * GlobalVars.gameTime.ElapsedGameTime.TotalMilliseconds * speedmultiplier);
                itemRectangle.Y += (int)(Velocity.Y * GlobalVars.gameTime.ElapsedGameTime.TotalMilliseconds * speedmultiplier);
            }
        }
        public void ItemSound()
        {
            SoundEngine.Instance.playFlameShot();
        }
    }
}