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

namespace Sprint3_actual.StateFiles
{
    public interface ILink
    {
        //FLOAT or ICOLLISION side?
        void TakeDamage(ICollision side, float damage);
        void Update();
        void MoveUp();
        void MoveDown();
        void MoveLeft();
        void MoveRight();
        void Idle();
        void SetSpeed(int speed);
        Vector2 Position();
        Rectangle PositionRectangle();
        Rectangle getHitbox();

        Rectangle getBlockHitbox();
        void SetPosition(int x, int y);
        void Attack();
        void SetItem(IActiveItem item);
        IActiveItem GetItem();
        void UseItem();
        void Draw();
        void gainHealth();
        //public IActiveItem Item { get; set; }
    }

    public class Link : ILink
    {
        public ILinkState state;
        public Game1 game { get; set; }
        public ISprite linkSprite { get; set; }
        public int linkX { get; set; }
        public int linkY { get; set; }
        public Texture2D texture { get; set; }
        public Color linkColor { get; set; }
        public IActiveItem Item { get; set; }
        public Rectangle positionRectangle { get; set; }

        private Rectangle hitboxRectangle;
        private Rectangle blockHitbox;
        public int linkSpeed { get; set; }
        private int linkHealth;
        public int LinkHealth
        {
            get
            {
                return linkHealth;
            }
            set
            {
                linkHealth = value;
            }
        }
       
        public IActiveItem Sword { get; set; }
        public IActiveItem SwordBeam { get; set; }
        public Link(Game1 game, Texture2D Texture)
        {
            this.game = game;
            linkX = 336;
            linkY = 336;
            linkColor = Color.White;
            texture = Texture;
            state = new LinkStateRightIdle(this);
            positionRectangle = new Rectangle(linkX, linkY, 48, 48);
            hitboxRectangle = new Rectangle(linkX + 6, linkY + 6, 36, 36);
            blockHitbox = new Rectangle(linkX + 6, linkY + 12, 36, 30);
            linkSpeed = 275;
            Item = new Null();
            linkHealth = 6;
            Sword = new SwordHitbox(this, game);
            SwordBeam = new SwordBeam(this, game);
        }

        public void TakeDamage(ICollision side, float damage)
        {
            if (linkHealth < 2) die();
            state.TakeDamage(side);
            linkHealth--;
            SoundEngine.Instance.playLinkDamage();
        }

        public void gainHealth()
        {
            linkHealth += 2;
        }

        public void MoveUp()
        {
            state.MoveUp();
        }
        public void MoveDown()
        {
            state.MoveDown();
        }
        public void MoveLeft()
        {
            state.MoveLeft();
        }
        public void MoveRight()
        {
            state.MoveRight();
        }
        public void Attack()
        {
            state.Attack();
        }
        public void Idle()
        {
            state.Idle();
        }

        public void SetSpeed(int speed)
        {
            linkSpeed = speed;
        }
        public Vector2 Position()
        {
            return new Vector2(linkX, linkY);
        }
        public Rectangle PositionRectangle()
        {
            return positionRectangle;
        }
        public Rectangle getHitbox()
        {
            return hitboxRectangle;
        }

        public Rectangle getBlockHitbox()
        {
            return blockHitbox;
        }
        public void SetPosition(int x, int y)
        {
            linkX = x;
            linkY = y;
        }
        public void SetItem(IActiveItem item)
        {
            if (item.GetType() != Item.GetType())
            {
                Item.Remove();
                Item.Update();
                Item = item;
            }
        }
        public IActiveItem GetItem()
        {
            return Item;
        }
        public void UseItem()
        {
            if (Item.IsRemoved())
            {
                Item.ItemSound();
            }
            state.UseItem();
        }

        public void Update()
        {
            positionRectangle = new Rectangle(linkX, linkY, 48, 48);
            hitboxRectangle.X = linkX + 6;
            hitboxRectangle.Y = linkY + 6;
            blockHitbox.X = linkX + 6;
            blockHitbox.Y = linkY + 12;
            state.Update();
            linkSprite.update(GlobalVars.gameTime);
        }
        public void Draw()
        {
            linkSprite.draw();
        }

        public void die()
        {
            game.isLinkDead = true;
        }

        public void TakeDamage(float damage)
        {

        }
    }
}