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

namespace Sprint3_actual.Everything_NPC
{
    class LightningBolt : INPC
    {
        private ISprite LightningSprite;
        private ISprite DangerIcon;
        private Rectangle posRect;
        private Rectangle dangerIconRect;
        private bool spawning, miniLightningSpawned;
        private int spawnTimer, aliveTimer;
        private const int totalAliveTime = 800;
        private bool removed;
        private const int posrectWH = 48;
        private room room;
        private Game1 game;
        public bool canTakeDirectDamage => false;

        public bool hasMultipleNodes => false;

        public LightningBolt(int spawnX, int spawnY, room room, Game1 game)
        {
            this.removed = false;
            posRect = new Rectangle(spawnX, spawnY, posrectWH, posrectWH);
            dangerIconRect = new Rectangle(spawnX+12, spawnY+12, 24, 24);
            LightningSprite = NPCSpriteFactory.Instance.CreateLightningStrike(posRect.X, posRect.Y, this);
            DangerIcon = NPCSpriteFactory.Instance.CreateDangerIcon(dangerIconRect.X, dangerIconRect.Y, this);

            this.room = room;
            this.game = game;
            spawning = true;
            spawnTimer = 0;
            this.miniLightningSpawned = false;

        }

        public Rectangle getRect()
        {
            if (spawning)
            {
                return this.dangerIconRect;
            }
            else
            {
                return this.posRect;
            }
        }

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

        public void DrawNPC()
        {
            if (spawning)
            {
                DangerIcon.draw();
            }
            else
            {
                LightningSprite.draw();
            }
        }

        public void UpdateNPC()
        {
            if (spawning)
            {
                this.spawnTimer += GlobalVars.gameTime.ElapsedGameTime.Milliseconds;
                DangerIcon.update(GlobalVars.gameTime);
                if (this.spawnTimer > 1000)
                {
                    spawning = false;
                    spawnTimer = 0;
                    SoundEngine.Instance.playLightningBlast();
                }

            }
            else
            {
                if(!miniLightningSpawned)
                {
                    
                    IActiveItem miniLightning1 = new MiniLightning(posRect.X, posRect.Y, room);
                    IActiveItem miniLightning2 = new MiniLightning(posRect.X, posRect.Y, room);
                    IActiveItem miniLightning3 = new MiniLightning(posRect.X, posRect.Y, room);
                    IActiveItem miniLightning4 = new MiniLightning(posRect.X, posRect.Y, room);
                    miniLightning1.ActiveItemUp();
                    miniLightning2.ActiveItemLeft();
                    miniLightning3.ActiveItemRight();
                    miniLightning4.ActiveItemDown();

                    miniLightningSpawned = true;
                }
                this.aliveTimer += GlobalVars.gameTime.ElapsedGameTime.Milliseconds;
                if(aliveTimer > totalAliveTime)
                {
                    removed = true;
                }

                LightningSprite.update(GlobalVars.gameTime);
            }

        }
        public void Spawn()
        {
            
        }

        public void takeDamage(float damage)
        {
            
        }

        public float Collide()
        {
            return 0.5f;
        }

        public bool IsRemoved()
        {
            return removed;
        }

        public bool IsSpawning()
        {
            return spawning;
        }

        public bool IsDead()
        {
            return false;
        }
    }
}