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

namespace Sprint3_actual.ActiveItems
{
    class SwordHitbox : IActiveItem
    {
        private ILink link;
        private Vector2 Pos;
        private Rectangle ItemRectangle;
        private bool Removed;
        private int RemoveCounter;
        private const int shift12 = 12;
        private const int shift26 = 26;
        private const int shift28 = 28;
        private const int shift32 = 32;
        private Game1 game;
        public SwordHitbox(Link link, Game1 game)
        {
            this.link = link;
            this.game = game;
            Removed = true;
        }
        public void ActiveItemDown()
        {
            if (Removed)
            {
                RemoveCounter = GlobalVars.swordCounter;
                Removed = false;
                Pos = link.Position();
                Pos.Y += 48;
                Pos.X += 15;
                ItemRectangle = new Rectangle((int)Pos.X, (int)Pos.Y, 24, 33);
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public void ActiveItemLeft()
        {
            if (Removed)
            {
                RemoveCounter = GlobalVars.swordCounter;
                Removed = false;
                Pos = link.Position();
                Pos.Y += 6;
                Pos.X -= 33;
                ItemRectangle = new Rectangle((int)Pos.X, (int)Pos.Y, 33, 36);
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public void ActiveItemRight()
        {
            if (Removed)
            {
                RemoveCounter = GlobalVars.swordCounter;
                Removed = false;
                Pos = link.Position();
                Pos.Y += 6;
                Pos.X += 48;
                ItemRectangle = new Rectangle((int)Pos.X, (int)Pos.Y, 33, 36);
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public void ActiveItemUp()
        {
            if (Removed)
            {
                RemoveCounter = GlobalVars.swordCounter;
                Removed = false;
                Pos = link.Position();
                Pos.Y -= 36;
                Pos.X += 9;
                ItemRectangle = new Rectangle((int)Pos.X, (int)Pos.Y, 24, 36);
                game.currentRoom.LinkItems.Add(this);
            }
        }

        public float Collide()
        {
            Removed = true;
            return 0.5f;
        }

        public void Draw()
        {
        }

        public bool IsRemoved()
        {
            return Removed;
        }

        public Rectangle PositionRectangle()
        {
            return ItemRectangle;
        }

        public void Remove()
        {
            Removed = true;
        }

        public void Update()
        {
            RemoveCounter--;
            if(RemoveCounter == 0)
            {
                Removed = true;
            }
        }
        public void ItemSound()
        {
            SoundEngine.Instance.playSwordSlash();
        }
    }
}