Game-Design / Sprint3_actual / ActiveItems / Bomb.cs
Bomb.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
{
    class Bomb : IActiveItem
    {
        private ILink link;
        private Game1 game;
        private Texture2D texture;
        private int SpriteWidth;
        private int SpriteHeight;
        private Vector2 pos;
        private Rectangle ItemRectangle;
        private bool Removed;
        private int RemoveCounter;
        private AItemSprites ItemSprite;
        private const int shift = 45;
            
        public Bomb(ILink link, Game1 game)
        {
            this.link = link;
            this.game = game;
            texture = game.PlayerTexture;
            Removed = true;
            SpriteWidth = 96;
            SpriteHeight = 96;
        }

        public void ActiveItemDown()
        {
            if (Removed)
            {
                pos = link.Position();
                pos.Y += shift;
                RemoveCounter = GlobalVars.itemCounter;
                ItemSprite = new ActiveBombSprite(pos, texture);
                ItemRectangle = new Rectangle((int)pos.X, (int)pos.Y, SpriteWidth, SpriteHeight);
                Removed = false;
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public void ActiveItemLeft()
        {
            if (Removed)
            {
                pos = link.Position();
                pos.X -= shift;
                RemoveCounter = GlobalVars.itemCounter;
                ItemSprite = new ActiveBombSprite(pos, texture);
                ItemRectangle = new Rectangle((int)pos.X, (int)pos.Y, SpriteWidth, SpriteHeight);
                Removed = false;
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public void ActiveItemRight()
        {
            if (Removed)
            {
                pos = link.Position();
                pos.X += shift;
                RemoveCounter = GlobalVars.itemCounter;
                ItemSprite = new ActiveBombSprite(pos, texture);
                ItemRectangle = new Rectangle((int)pos.X, (int)pos.Y, SpriteWidth, SpriteHeight);
                Removed = false;
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public void ActiveItemUp()
        {
            if (Removed)
            {
                pos = link.Position();
                pos.Y -= shift;
                RemoveCounter = GlobalVars.itemCounter;
                ItemSprite = new ActiveBombSprite(pos, texture);
                ItemRectangle = new Rectangle((int)pos.X, (int)pos.Y, SpriteWidth, SpriteHeight);
                Removed = false;
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public float Collide()
        {
            //Only collide with the item rectangle as bomb is exploding
            if(RemoveCounter <= 5)
            {
                return 4.0f;
            }
            else
            {
                return 0.0f;
            }
        }

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

        public bool IsRemoved()
        {
            return Removed;
        }

        public Rectangle PositionRectangle()
        {
            return ItemRectangle;
        }

        public void Remove()
        {
            Removed = true;
        }

        public void Update()
        {
            if (!Removed)
            {
                RemoveCounter--;
                ItemSprite.update(GlobalVars.gameTime);
                if (RemoveCounter <= 0)
                {
                    Removed = true;
                    Inventory.Instance.BombCount--;
                }
            }
        }

        public void ItemSound()
        {
            SoundEngine.Instance.playBombSounds();
        }
    }
}