Game-Design / Sprint3_actual / Everything_NPC / Damager.cs
Damager.cs
Raw
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using System;
using System.Collections.Generic;
using System.Text;
using Sprint3_actual.ActiveItems;
using Sprint3_actual.Everything_NPC;
using Sprint3_actual.SoundManagement;
namespace Sprint3_actual.Everything_NPC
{
    public class Damager : INPC
    {
        private ISprite Sprite;
        private ISprite StarEffect;
        private Rectangle posRect;
        private bool removed;
        private int rectWH = 48;
        private float life;
        private bool death;
        private int deathTimer;
        public bool canTakeDirectDamage => true;
        public bool hasMultipleNodes => false;

        public Damager(int spawnX, int spawnY, room room, Game1 game)
        {
            this.removed = false;
            posRect = new Rectangle(spawnX, spawnY, rectWH, rectWH);
            Sprite = NPCSpriteFactory.Instance.CreateDamager(posRect.X, posRect.Y, this);
            StarEffect = NPCSpriteFactory.Instance.CreateStarEffect(posRect.X, posRect.Y, this);
            this.life = 0.5f;
            this.deathTimer = 0;

        }

        public Rectangle getRect()
        {
            return posRect;
        }

        public void SetPosition(int x, int y)
        {
            posRect.X = x;
            posRect.Y = y;
        }

        public void DrawNPC()
        {
            if (death)
            {
                StarEffect.draw();
            }
            else
            {
                Sprite.draw();
            }
        }

        public void UpdateNPC()
        {
            if (death)
            {
                if (deathTimer == 0)
                {
                    SoundEngine.Instance.playEnemyDeath();
                }
                this.deathTimer += GlobalVars.gameTime.ElapsedGameTime.Milliseconds;
                if (this.deathTimer > 600)
                {
                    removed = true;
                }
                StarEffect.update(GlobalVars.gameTime);

            }
            else
            {
            }
                Sprite.update(GlobalVars.gameTime);
        }

        public void Spawn()
        {
        }
        public void takeDamage(float damage)
        {
            life -= damage;

            if (life <= 0.0)
            {
                death = true;
            }
        }
        public float Collide()
        {
            return 0.5f;
        }

        public bool IsRemoved()
        {
            return removed;
        }

        public bool IsSpawning()
        {
            return false;
        }

        public bool IsDead()
        {
            return death;
        }

    }
}