Game-Design / Sprint3_actual / Everything_NPC / OldWomanPhases / ElectrifyPhase.cs
ElectrifyPhase.cs
Raw
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Sprint3_actual.BorderElements;
using Sprint3_actual.Text;
using Sprint3_actual.SoundManagement;

namespace Sprint3_actual.Everything_NPC.OldWomanPhases
{
    public class ElectrifyPhase : IPhase
    {

        private room room;
        private Game1 game;
        private int roomXMod;
        private int roomYMod;
        private bool finished;
        private int currentTime;
        private int strikeTime, strikeCount;
        private const int strikeMaxTime = 800, strikeMaxAmount = 18;
        private const int textTime2 = 3000, textFinishTime = 6000;
        private bool text2Printed, textFinished;
        private IBorder textBox;
        private Rectangle PlayerPos;

        public ElectrifyPhase(room room, Game1 game, int roomXMod, int roomYMod)
        {
            this.room = room;
            this.game = game;
            this.roomXMod = roomXMod;
            this.roomYMod = roomYMod;
            this.textBox = BorderElementsFactory.Instance.CreateTextBox(96 + roomXMod, 432 + roomYMod);
            this.currentTime = 0;
            this.strikeTime = 0;
            this.strikeCount = 0;
            room.Addons[0] = textBox;

            room.TextList.Add(TextFactory.Instance.CreateText(3, 215 + roomXMod, 468 + roomYMod));
        }

        public void Update(GameTime gameTime)
        {
            this.currentTime += GlobalVars.gameTime.ElapsedGameTime.Milliseconds;
            if (!textFinished)
            {
                if (currentTime > textFinishTime)
                {
                    room.Addons[0] = null;
                    SoundEngine.Instance.playWitchLaugh();
                    textFinished = true;
                }
                if (!text2Printed && currentTime > textTime2)
                {
                    room.TextList.Add(TextFactory.Instance.CreateText(4, 215 + roomXMod, 468 + roomYMod));
                    text2Printed = true;
                }
            } else
            {
                this.strikeTime += GlobalVars.gameTime.ElapsedGameTime.Milliseconds;
                if(strikeTime > strikeMaxTime)
                {
                    strikeTime = 0;
                    strikeCount++;
                    PlayerPos = game.Player.getHitbox();
                    PlayerPos.X -= 6;
                    PlayerPos.Y -= 6;
                    room.NPCList.Add(NPCFactory.Instance.CreateNPC(16, PlayerPos.X, PlayerPos.Y, room, game));
                    if(strikeCount >= strikeMaxAmount)
                    {
                        finished = true;
                    }
                }
            }
        }

        public bool IsFinished()
        {
            return finished;
        }
    }
}