Exemplo n.º 1
0
 // Use this for initialization
 void Start()
 {
     phase  = 0;
     phase1 = this.gameObject.GetComponent <Phase1>();
     phase2 = this.gameObject.GetComponent <Phase2>();
     phase3 = this.gameObject.GetComponent <Phase3>();
     phase4 = this.gameObject.GetComponent <Phase4>();
     phase5 = this.gameObject.GetComponent <Phase5>();
 }
Exemplo n.º 2
0
    // Starting Zoom at 2

    private void Start()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
        }
    }
Exemplo n.º 3
0
    void Start()
    {
        anim   = GetComponent <Animator>();
        ag     = GetComponent <NavMeshAgent>();
        p      = FindObjectOfType <Player>();
        w      = GetComponentInChildren <Weapon>();
        health = GetComponent <EnemyHealth>();
        //バトルはステップに別れています、リストのなかでステップを作る
        BossPhase phase1 = new Phase1(ag, anim, state, w, p, transform, this);
        BossPhase phase2 = new Phase2(ag, anim, state, w, p, transform, this);
        BossPhase phase3 = new Phase3(ag, anim, state, w, p, transform, this);

        phases.Add(phase1);
        phases.Add(phase2);
        phases.Add(phase3);
        //スポーンポジションを登録する
        startPos = transform.position;
        smoke    = GetComponentInChildren <ParticleSystem>();
        //現在phaseの設定
        currentPhase = phases[phaseIndex];
        //phaseエントリー
        currentPhase.EnterState();
        wp = GetComponentInChildren <Weapon>();
        //スポンサー設定
        Transform[] allChildren = GetComponentsInChildren <Transform>();
        foreach (var c in allChildren)
        {
            if (c.gameObject.name == "KnifeSpawner")
            {
                knifeSpawner = c.transform;
            }
            else if (c.gameObject.name == "MagicSpawner")
            {
                magicSpawner = c.transform;
            }
        }
        //スポーンprefab
        enemy = enemyToSpawn;
    }
Exemplo n.º 4
0
    void Update()
    {
        if (BossClass.instance.Health > 600)
        {
            switch (currentState)
            {
            case Phase1.Intro:
                if (BossClass.instance.playIntro)
                {
                    ChangeAnimationState("SlimeBoss_Intro");
                    if (counter > 0)
                    {
                        counter -= Time.deltaTime;
                    }
                    else
                    {
                        currentState = Phase1.Idle;
                        counter      = phase1Idle;
                    }
                }
                break;

            case Phase1.Idle:
                ChangeAnimationState("SlimeBoss_Idle");

                if (counter > 0)
                {
                    counter -= Time.deltaTime;
                }
                else
                {
                    counter      = jumpTime;
                    currentState = Phase1.Jump;
                }
                break;

            case Phase1.Shooting:

                ChangeAnimationState("SlimeBoss_Idle");

                if (shootPhaseBegginBreakCounter > 0)
                {
                    shootPhaseBegginBreakCounter -= Time.deltaTime;
                }
                else
                {
                    if (counter > 0)
                    {
                        counter -= Time.deltaTime;

                        shootingPhaseBreakBetweenPhaseCounter -= Time.deltaTime;

                        //beggin break; 1
                        if (shootPhaseBegginBreakCounter < 0)
                        {
                            if (shootingPhaseBreakBetweenPhaseCounter > 0)
                            {
                                if (shootCounter > 0)
                                {
                                    shootCounter -= Time.deltaTime;
                                }
                                else
                                {
                                    foreach (Transform t in shootingFirePoints)
                                    {
                                        Instantiate(projectile, t.position, t.rotation);
                                    }
                                    shootCounter = breaksBetweenShoots;
                                }
                            }
                        }
                        else
                        {
                            shootPhaseBegginBreakCounter -= Time.deltaTime;
                        }
                    }
                    else
                    {
                        shootingPhaseBreakBetweenPhaseCounter = shootPhase1Time - shootingPhaseEndBreak;
                        //beggin break
                        shootPhaseBegginBreakCounter = shootPhaseBegginBreak;

                        counter      = jumpTime;
                        currentState = Phase1.Jump;
                    }
                }



                break;

            case Phase1.Jump:
                ChangeAnimationState("SlimeBoss_Jump");

                if (counter > 0)
                {
                    transform.position = Vector2.MoveTowards(transform.position, player.transform.position, activeSpeed * Time.deltaTime);
                    counter           -= Time.deltaTime;
                }
                else
                {
                    currentState = Phase1.Landing;
                    counter      = landingTime;
                }


                break;

            case Phase1.Landing:

                if (canShakeCamera)
                {
                    CameraShaker.ShakeStrong(landingTime, .15f);
                    canShakeCamera = false;
                }

                if (dontShoot == false)
                {
                    foreach (Transform t in landingShootFirePoints)
                    {
                        Instantiate(projectile, t.position, t.rotation);
                    }

                    dontShoot = true;
                }

                ChangeAnimationState("SlimeBoss_Landing");



                if (counter > 0)
                {
                    counter -= Time.deltaTime;
                }
                else
                {
                    dontShoot = false;


                    canShakeCamera = true;

                    if (currentJumps == howManyTimesToJump)
                    {
                        currentJumps = 0;
                        counter      = shootPhase1Time;
                        currentState = Phase1.Shooting;
                    }
                    else
                    {
                        currentState = Phase1.Jump;
                        counter      = jumpTime;
                        currentJumps++;
                    }
                }

                break;
            }
        }
        else
        {
            if (hasCounterBeenSet == false)
            {
                counter           = Phase2introTime;
                hasCounterBeenSet = true;
            }

            switch (phase2CurrentState)
            {
            case Phase2.Intro:
                ChangeAnimationState("SlimeBoss_Stage 2 Intro");

                if (canShakeCamera)
                {
                    CameraShaker.ShakeStrong(Phase2introTime, .35f);
                    canShakeCamera = false;
                }

                if (counter > 0)
                {
                    counter -= Time.deltaTime;
                }
                else
                {
                    canShakeCamera = true;

                    activeSpeed = Phase2speed;

                    counter      = Phase2Idle;
                    shootCounter = Phase2breaksBetweenShoots;

                    shootingPhaseBreakBetweenPhaseCounter = Phase2shootPhase1Time - Phase2shootingPhaseEndBreak;

                    shootPhaseBegginBreakCounter = Phase2shootPhaseBegginBreak;



                    phase2CurrentState = Phase2.Idle;
                }

                break;

            case Phase2.Idle:

                ChangeAnimationState("SlimeBoss_Idle Stage 2");

                if (counter > 0)
                {
                    counter -= Time.deltaTime;
                }
                else
                {
                    counter            = Phase2jumpTime;
                    phase2CurrentState = Phase2.Jump;
                }
                break;

            case Phase2.Shooting:

                ChangeAnimationState("SlimeBoss_Idle Stage 2");

                //rotate
                allFirePoints.Rotate(Vector3.forward * speedToRotateAroundSpiral * Time.deltaTime);

                if (shootPhaseBegginBreakCounter > 0)
                {
                    shootPhaseBegginBreakCounter -= Time.deltaTime;
                }
                else
                {
                    if (counter > 0)
                    {
                        counter -= Time.deltaTime;

                        shootingPhaseBreakBetweenPhaseCounter -= Time.deltaTime;

                        if (shootPhaseBegginBreakCounter < 0)
                        {
                            //shootingPhaseBreakBetweenPhaseCounter;

                            if (shootingPhaseBreakBetweenPhaseCounter > 0)
                            {
                                if (shootCounter > 0)
                                {
                                    shootCounter -= Time.deltaTime;
                                }
                                else
                                {
                                    foreach (Transform t in Phase2shootingFirePoints)
                                    {
                                        Instantiate(projectile, t.position, t.rotation);
                                    }
                                    shootCounter = Phase2breaksBetweenShoots;
                                }
                            }
                        }
                        else
                        {
                            shootingPhaseBreakBetweenPhaseCounter -= Time.deltaTime;
                        }
                    }
                    else
                    {
                        shootingPhaseBreakBetweenPhaseCounter = Phase2shootPhase1Time - Phase2shootingPhaseEndBreak;

                        shootPhaseBegginBreakCounter = Phase2shootPhaseBegginBreak;

                        counter = Phase2jumpTime;
                        allFirePoints.rotation = Quaternion.identity;
                        phase2CurrentState     = Phase2.Jump;
                    }
                }



                break;

            case Phase2.Jump:
                ChangeAnimationState("SlimeBoss_Stage 2 Jump");

                if (counter > 0)
                {
                    transform.position = Vector2.MoveTowards(transform.position, player.transform.position, activeSpeed * Time.deltaTime);
                    counter           -= Time.deltaTime;
                }
                else
                {
                    phase2CurrentState = Phase2.Landing;
                    counter            = Phase2landingTime;
                }


                break;

            case Phase2.Landing:

                if (canShakeCamera)
                {
                    CameraShaker.ShakeStrong(landingTime, .15f);
                    canShakeCamera = false;
                }

                if (dontShoot == false)
                {
                    foreach (Transform t in Phase2landingShootFirePoints)
                    {
                        Instantiate(projectile, t.position, t.rotation);
                    }

                    dontShoot = true;
                }

                ChangeAnimationState("SlimeBoss_Landing Stage 2");



                if (counter > 0)
                {
                    counter -= Time.deltaTime;
                }
                else
                {
                    dontShoot = false;

                    canShakeCamera = true;

                    if (currentJumps == Phase2howManyTimesToJump)
                    {
                        currentJumps       = 0;
                        counter            = Phase2shootPhase1Time;
                        phase2CurrentState = Phase2.Shooting;
                    }
                    else
                    {
                        phase2CurrentState = Phase2.Jump;
                        counter            = Phase2jumpTime;
                        currentJumps++;
                    }
                }

                break;
            }
        }
    }
        public static void Apply(AAProgram ast, FinalTransformations finalTrans)
        {
            //Build list of file dependacies
            Phase1 phase1 = new Phase1(finalTrans);
            ast.Apply(phase1);
            var dependancies = phase1.dependancies;
            if (dependancies.Keys.Count == 0) return;
            AASourceFile root = Util.GetAncestor<AASourceFile>(finalTrans.mainEntry) ??
                                dependancies.Keys.FirstOrDefault(file => !file.GetName().Text.Contains("\\")) ??
                                dependancies.Keys.First(file => true);

            //Remove files unreachable from root
            //On second thought, dont. there might be static refferences the other way which needs to be included
            /*{
                List<AASourceFile> reachable = GetReachable(root, dependancies);
                AASourceFile[] keys = new AASourceFile[dependancies.Count];
                dependancies.Keys.CopyTo(keys, 0);
                foreach (AASourceFile key in keys)
                {
                    if (!reachable.Contains(key))
                        dependancies.Remove(key);
                }
            }*/

            //Push common depancies up
            /*
             * root -> (item1 -> (item3), item2 -> (item4 -> (item3)))
             *
             * root -> (item3, item1, item2 -> (item4))
             */

            //Add unreachable to the root
            while (true)
            {
                List<AASourceFile> reachable = new List<AASourceFile>();
                GetReachable(root, dependancies, ref reachable);
                if (reachable.Count == dependancies.Count + (reachable.Contains(null) ? 1 : 0)) break;
                AASourceFile[] keys = new AASourceFile[dependancies.Count];
                dependancies.Keys.CopyTo(keys, 0);
                foreach (AASourceFile key in keys)
                {
                    if (!reachable.Contains(key))
                    {
                        AASourceFile k = key;
                        //See if you can find another unreachable file which need this file
                        Dictionary<AASourceFile, int> decendantCounts = new Dictionary<AASourceFile, int>();
                        decendantCounts.Add(k, CountDecendants(k, dependancies, new List<AASourceFile>()));
                        while (true)
                        {
                            AASourceFile file = null;
                            foreach (KeyValuePair<AASourceFile, List<AASourceFile>> dependancy in dependancies)
                            {
                                if (decendantCounts.ContainsKey(dependancy.Key))
                                    continue;
                                if (!dependancy.Value.Contains(k))
                                    continue;
                                file = dependancy.Key;
                                break;
                            }

                            //AASourceFile file = dependancies.FirstOrDefault(item => item.Value.Contains(k)).Key;
                            if (file == null) break;
                            decendantCounts.Add(file, CountDecendants(file, dependancies, new List<AASourceFile>()));
                            k = file;
                        }
                        foreach (KeyValuePair<AASourceFile, int> decendantItem in decendantCounts)
                        {
                            if (decendantItem.Value > decendantCounts[k])
                                k = decendantItem.Key;
                        }

                        dependancies[root].Add(k);
                        break;
                    }
                }
            }
            //It is moved down here because cycles are not removed in unreachable
            RemoveCycles(root, dependancies, new List<AASourceFile> { root });

            //Convert to tree to make it easier
            List<Item> allItems = new List<Item>();
            IncludeItem rootIncludeItem = MakeTree(root, dependancies, allItems, null);
            bool[] removed = new bool[allItems.Count];
            for (int i = 0; i < removed.Length; i++)
                removed[i] = false;
            int removedCount = 0;

            //Ensure that each include is only included one place
            for (int i = 0; i < allItems.Count; i++)
            {
                if (removed[i])
                    continue;

                IncludeItem item1 = (IncludeItem)allItems[i];
                for (int j = i + 1; j < allItems.Count; j++)
                {
                    if (removed[j])
                        continue;
                    IncludeItem item2 = (IncludeItem)allItems[j];

                    if (item1.Current == item2.Current)
                    {
                        List<Item> path1 = item1.Path;
                        List<Item> path2 = item2.Path;

                        for (int k = 0; k < Math.Min(path1.Count, path2.Count); k++)
                        {
                            if (path1[k] != path2[k])
                            {

                                int insertAt = Math.Min(path1[k - 1].Children.IndexOf(path1[k]),
                                                        path2[k - 1].Children.IndexOf(path2[k]));

                                item1.Parent.Children.Remove(item1);
                                LinkedList<IncludeItem> toRemove = new LinkedList<IncludeItem>();
                                toRemove.AddLast(item2);
                                while (toRemove.Count > 0)
                                {
                                    IncludeItem item = toRemove.First.Value;
                                    toRemove.RemoveFirst();
                                    item.Parent.Children.Remove(item);
                                    //allItems.Remove(item);
                                    removedCount++;
                                    removed[item.ListIndex] = true;
                                    foreach (IncludeItem child in item.Children)
                                    {
                                        toRemove.AddLast(child);
                                    }
                                }
                                //j--;

                                path1[k - 1].Children.Insert(insertAt, item1);
                                item1.Parent = path1[k - 1];

                                break;
                            }
                        }
                    }
                }
            }

            List<Item> newAllItems = new List<Item>(allItems.Count - removedCount);
            for (int i = 0; i < allItems.Count; i++)
                if (!removed[i])
                    newAllItems.Add(allItems[i]);
            allItems = newAllItems;

            //Move the null node to nr [0]
            foreach (IncludeItem item in allItems)
            {
                if (item.Current == null)
                {
                    int itemIndex = item.Parent.Children.IndexOf(item);
                    Item item0 = item.Parent.Children[0];
                    item.Parent.Children[0] = item;
                    item.Parent.Children[itemIndex] = item0;
                    break;
                }
            }

            //Insert method decls and move structs & fields up as needed
            ast.Apply(new Phase2(finalTrans, allItems));

            //Insert the headers in the files

            if (Options.Compiler.OneOutputFile)
            {
                //for (int i = 0; i < allItems.Count; i++)
                int i = 0;
                while (allItems.Count > 0)
                {
                    if (allItems[i] is IncludeItem)
                    {
                        IncludeItem includeItem = (IncludeItem) allItems[i];
                        //Dont want the standard lib
                        if (includeItem.Current == null)
                        {
                            i++;
                            continue;
                        }
                        //If it has children with children, then pick another first
                        if (includeItem.Children.Any(child => child.Children.Count > 0))
                        {
                            i++;
                            continue;
                        }
                        if (includeItem.Children.Count == 0)
                        {
                            if (includeItem.Parent == null)
                                break;
                            i++;
                            continue;
                        }
                        i = 0;
                        //Put all children into this
                        while (includeItem.Children.Count > 0)
                        {
                            int childNr = includeItem.Children.Count - 1;
                            allItems.Remove(includeItem.Children[childNr]);
                            if (includeItem.Children[childNr] is FieldItem)
                            {
                                FieldItem aItem = (FieldItem)includeItem.Children[childNr];
                                Node node = aItem.FieldDecl;
                                node.Parent().RemoveChild(node);
                                includeItem.Current.GetDecl().Insert(0, node);
                            }
                            else if (includeItem.Children[childNr] is StructItem)
                            {
                                StructItem aItem = (StructItem)includeItem.Children[childNr];
                                Node node = aItem.StructDecl;
                                node.Parent().RemoveChild(node);
                                includeItem.Current.GetDecl().Insert(0, node);
                            }
                            else if (includeItem.Children[childNr] is MethodDeclItem)
                            {
                                MethodDeclItem aItem = (MethodDeclItem)includeItem.Children[childNr];
                                AMethodDecl aNode = new AMethodDecl();
                                if (aItem.RealDecl.GetStatic() != null) aNode.SetStatic(new TStatic("static"));
                                aNode.SetReturnType(Util.MakeClone(aItem.RealDecl.GetReturnType(), finalTrans.data));
                                aNode.SetName(new TIdentifier(aItem.RealDecl.GetName().Text));
                                foreach (AALocalDecl formal in aItem.RealDecl.GetFormals())
                                {
                                    AALocalDecl clone = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, Util.MakeClone(formal.GetType(), finalTrans.data), new TIdentifier(formal.GetName().Text), null);
                                    aNode.GetFormals().Add(clone);
                                }
                                includeItem.Current.GetDecl().Insert(0, aNode);
                            }
                            else if (includeItem.Children[childNr] is IncludeItem)
                            {
                                IncludeItem aChild = (IncludeItem)includeItem.Children[childNr];
                                if (aChild.Current == null)
                                {
                                    AIncludeDecl node = new AIncludeDecl(new TInclude("include"),
                                                        new TStringLiteral("\"TriggerLibs/NativeLib\""));
                                    includeItem.Current.GetDecl().Insert(0, node);
                                }
                                else
                                {
                                    PDecl[] decls = new PDecl[aChild.Current.GetDecl().Count];
                                    aChild.Current.GetDecl().CopyTo(decls, 0);
                                    for (int k = decls.Length - 1; k >= 0; k--)
                                    {
                                        includeItem.Current.GetDecl().Insert(0, decls[k]);
                                    }
                                    aChild.Current.Parent().RemoveChild(aChild.Current);
                                    //i = -1;
                                }
                            }
                            includeItem.Children.RemoveAt(childNr);
                        }
                    }
                }
            }
            else
                foreach (IncludeItem includeItem in allItems.OfType<IncludeItem>())
                {
                    for (int i = includeItem.Children.Count - 1; i >= 0; i--)
                    {
                        Node node;
                        if (includeItem.Children[i] is IncludeItem)
                        {
                            IncludeItem aItem = (IncludeItem) includeItem.Children[i];
                            node = new AIncludeDecl(new TInclude("include"),
                                                    new TStringLiteral("\"" + (aItem.Current == null ? "TriggerLibs/NativeLib" : aItem.Current.GetName().Text.Replace("\\", "/")) + "\""));
                            if (aItem.Current == null && finalTrans.mainEntry != null)
                            {
                                //Search for user defined initlib
                                bool foundInvoke = false;
                                foreach (ASimpleInvokeExp invokeExp in finalTrans.data.SimpleMethodLinks.Keys)
                                {
                                    if(invokeExp.GetName().Text == "libNtve_InitLib" && invokeExp.GetArgs().Count == 0)
                                    {
                                        /*finalTrans.errors.Add(new ErrorCollection.Error(invokeExp.GetName(),
                                                                                        Util.GetAncestor<AASourceFile>(
                                                                                            invokeExp),
                                                                                        "You are invoking libNtve_InitLib() yourself somewhere. It will not be auto inserted.",
                                                                                        true));*/
                                        foundInvoke = true;
                                        break;
                                    }
                                }

                                if (!foundInvoke)
                                {
                                    //Init the lib
                                    ASimpleInvokeExp initExp = new ASimpleInvokeExp();
                                    initExp.SetName(new TIdentifier("libNtve_InitLib"));
                                    finalTrans.data.ExpTypes[initExp] = new AVoidType(new TVoid("void"));
                                    foreach (AMethodDecl method in finalTrans.data.Libraries.Methods)
                                    {
                                        if (method.GetName().Text == "libNtve_InitLib" && method.GetFormals().Count == 0)
                                        {
                                            finalTrans.data.SimpleMethodLinks[initExp] = method;
                                        }
                                    }
                                    AABlock block = (AABlock) finalTrans.mainEntry.GetBlock();
                                    block.GetStatements().Insert(0, new AExpStm(new TSemicolon(";"), initExp));
                                }
                            }
                        }
                        else if (includeItem.Children[i] is FieldItem)
                        {
                            FieldItem aItem = (FieldItem)includeItem.Children[i];
                            node = aItem.FieldDecl;
                            node.Parent().RemoveChild(node);
                        }
                        else if (includeItem.Children[i] is StructItem)
                        {
                            StructItem aItem = (StructItem)includeItem.Children[i];
                            node = aItem.StructDecl;
                            node.Parent().RemoveChild(node);
                        }
                        else if (includeItem.Children[i] is MethodDeclItem)
                        {
                            MethodDeclItem aItem = (MethodDeclItem)includeItem.Children[i];
                            AMethodDecl aNode = new AMethodDecl();
                            if (aItem.RealDecl.GetStatic() != null) aNode.SetStatic(new TStatic("static"));
                            aNode.SetReturnType(Util.MakeClone(aItem.RealDecl.GetReturnType(), finalTrans.data));
                            aNode.SetName(new TIdentifier(aItem.RealDecl.GetName().Text));
                            foreach (AALocalDecl formal in aItem.RealDecl.GetFormals())
                            {
                                AALocalDecl clone = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, Util.MakeClone(formal.GetType(), finalTrans.data), new TIdentifier(formal.GetName().Text), null);
                                aNode.GetFormals().Add(clone);
                            }
                            node = aNode;
                        }
                        else
                            throw new Exception("FixIncludes.Apply: Unexpected item type");

                        includeItem.Current.GetDecl().Insert(0, node);
                    }
                }
        }
 protected override void When()
 {
     _coreProjection.Start();
     Phase1.Complete();
 }
Exemplo n.º 7
0
        public static void Apply(AAProgram ast, FinalTransformations finalTrans)
        {
            //Build list of file dependacies
            Phase1 phase1 = new Phase1(finalTrans);

            ast.Apply(phase1);
            var dependancies = phase1.dependancies;

            if (dependancies.Keys.Count == 0)
            {
                return;
            }
            AASourceFile root = Util.GetAncestor <AASourceFile>(finalTrans.mainEntry) ??
                                dependancies.Keys.FirstOrDefault(file => !file.GetName().Text.Contains("\\")) ??
                                dependancies.Keys.First(file => true);

            //Remove files unreachable from root
            //On second thought, dont. there might be static refferences the other way which needs to be included

            /*{
             *  List<AASourceFile> reachable = GetReachable(root, dependancies);
             *  AASourceFile[] keys = new AASourceFile[dependancies.Count];
             *  dependancies.Keys.CopyTo(keys, 0);
             *  foreach (AASourceFile key in keys)
             *  {
             *      if (!reachable.Contains(key))
             *          dependancies.Remove(key);
             *  }
             * }*/


            //Push common depancies up

            /*
             * root -> (item1 -> (item3), item2 -> (item4 -> (item3)))
             *
             * root -> (item3, item1, item2 -> (item4))
             */

            //Add unreachable to the root
            while (true)
            {
                List <AASourceFile> reachable = new List <AASourceFile>();
                GetReachable(root, dependancies, ref reachable);
                if (reachable.Count == dependancies.Count + (reachable.Contains(null) ? 1 : 0))
                {
                    break;
                }
                AASourceFile[] keys = new AASourceFile[dependancies.Count];
                dependancies.Keys.CopyTo(keys, 0);
                foreach (AASourceFile key in keys)
                {
                    if (!reachable.Contains(key))
                    {
                        AASourceFile k = key;
                        //See if you can find another unreachable file which need this file
                        Dictionary <AASourceFile, int> decendantCounts = new Dictionary <AASourceFile, int>();
                        decendantCounts.Add(k, CountDecendants(k, dependancies, new List <AASourceFile>()));
                        while (true)
                        {
                            AASourceFile file = null;
                            foreach (KeyValuePair <AASourceFile, List <AASourceFile> > dependancy in dependancies)
                            {
                                if (decendantCounts.ContainsKey(dependancy.Key))
                                {
                                    continue;
                                }
                                if (!dependancy.Value.Contains(k))
                                {
                                    continue;
                                }
                                file = dependancy.Key;
                                break;
                            }

                            //AASourceFile file = dependancies.FirstOrDefault(item => item.Value.Contains(k)).Key;
                            if (file == null)
                            {
                                break;
                            }
                            decendantCounts.Add(file, CountDecendants(file, dependancies, new List <AASourceFile>()));
                            k = file;
                        }
                        foreach (KeyValuePair <AASourceFile, int> decendantItem in decendantCounts)
                        {
                            if (decendantItem.Value > decendantCounts[k])
                            {
                                k = decendantItem.Key;
                            }
                        }

                        dependancies[root].Add(k);
                        break;
                    }
                }
            }
            //It is moved down here because cycles are not removed in unreachable
            RemoveCycles(root, dependancies, new List <AASourceFile> {
                root
            });


            //Convert to tree to make it easier
            List <Item> allItems        = new List <Item>();
            IncludeItem rootIncludeItem = MakeTree(root, dependancies, allItems, null);

            bool[] removed = new bool[allItems.Count];
            for (int i = 0; i < removed.Length; i++)
            {
                removed[i] = false;
            }
            int removedCount = 0;

            //Ensure that each include is only included one place
            for (int i = 0; i < allItems.Count; i++)
            {
                if (removed[i])
                {
                    continue;
                }

                IncludeItem item1 = (IncludeItem)allItems[i];
                for (int j = i + 1; j < allItems.Count; j++)
                {
                    if (removed[j])
                    {
                        continue;
                    }
                    IncludeItem item2 = (IncludeItem)allItems[j];

                    if (item1.Current == item2.Current)
                    {
                        List <Item> path1 = item1.Path;
                        List <Item> path2 = item2.Path;



                        for (int k = 0; k < Math.Min(path1.Count, path2.Count); k++)
                        {
                            if (path1[k] != path2[k])
                            {
                                int insertAt = Math.Min(path1[k - 1].Children.IndexOf(path1[k]),
                                                        path2[k - 1].Children.IndexOf(path2[k]));


                                item1.Parent.Children.Remove(item1);
                                LinkedList <IncludeItem> toRemove = new LinkedList <IncludeItem>();
                                toRemove.AddLast(item2);
                                while (toRemove.Count > 0)
                                {
                                    IncludeItem item = toRemove.First.Value;
                                    toRemove.RemoveFirst();
                                    item.Parent.Children.Remove(item);
                                    //allItems.Remove(item);
                                    removedCount++;
                                    removed[item.ListIndex] = true;
                                    foreach (IncludeItem child in item.Children)
                                    {
                                        toRemove.AddLast(child);
                                    }
                                }
                                //j--;



                                path1[k - 1].Children.Insert(insertAt, item1);
                                item1.Parent = path1[k - 1];



                                break;
                            }
                        }
                    }
                }
            }

            List <Item> newAllItems = new List <Item>(allItems.Count - removedCount);

            for (int i = 0; i < allItems.Count; i++)
            {
                if (!removed[i])
                {
                    newAllItems.Add(allItems[i]);
                }
            }
            allItems = newAllItems;

            //Move the null node to nr [0]
            foreach (IncludeItem item in allItems)
            {
                if (item.Current == null)
                {
                    int  itemIndex = item.Parent.Children.IndexOf(item);
                    Item item0     = item.Parent.Children[0];
                    item.Parent.Children[0]         = item;
                    item.Parent.Children[itemIndex] = item0;
                    break;
                }
            }

            //Insert method decls and move structs & fields up as needed
            ast.Apply(new Phase2(finalTrans, allItems));

            //Insert the headers in the files

            if (Options.Compiler.OneOutputFile)
            {
                //for (int i = 0; i < allItems.Count; i++)
                int i = 0;
                while (allItems.Count > 0)
                {
                    if (allItems[i] is IncludeItem)
                    {
                        IncludeItem includeItem = (IncludeItem)allItems[i];
                        //Dont want the standard lib
                        if (includeItem.Current == null)
                        {
                            i++;
                            continue;
                        }
                        //If it has children with children, then pick another first
                        if (includeItem.Children.Any(child => child.Children.Count > 0))
                        {
                            i++;
                            continue;
                        }
                        if (includeItem.Children.Count == 0)
                        {
                            if (includeItem.Parent == null)
                            {
                                break;
                            }
                            i++;
                            continue;
                        }
                        i = 0;
                        //Put all children into this
                        while (includeItem.Children.Count > 0)
                        {
                            int childNr = includeItem.Children.Count - 1;
                            allItems.Remove(includeItem.Children[childNr]);
                            if (includeItem.Children[childNr] is FieldItem)
                            {
                                FieldItem aItem = (FieldItem)includeItem.Children[childNr];
                                Node      node  = aItem.FieldDecl;
                                node.Parent().RemoveChild(node);
                                includeItem.Current.GetDecl().Insert(0, node);
                            }
                            else if (includeItem.Children[childNr] is StructItem)
                            {
                                StructItem aItem = (StructItem)includeItem.Children[childNr];
                                Node       node  = aItem.StructDecl;
                                node.Parent().RemoveChild(node);
                                includeItem.Current.GetDecl().Insert(0, node);
                            }
                            else if (includeItem.Children[childNr] is MethodDeclItem)
                            {
                                MethodDeclItem aItem = (MethodDeclItem)includeItem.Children[childNr];
                                AMethodDecl    aNode = new AMethodDecl();
                                if (aItem.RealDecl.GetStatic() != null)
                                {
                                    aNode.SetStatic(new TStatic("static"));
                                }
                                aNode.SetReturnType(Util.MakeClone(aItem.RealDecl.GetReturnType(), finalTrans.data));
                                aNode.SetName(new TIdentifier(aItem.RealDecl.GetName().Text));
                                foreach (AALocalDecl formal in aItem.RealDecl.GetFormals())
                                {
                                    AALocalDecl clone = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, Util.MakeClone(formal.GetType(), finalTrans.data), new TIdentifier(formal.GetName().Text), null);
                                    aNode.GetFormals().Add(clone);
                                }
                                includeItem.Current.GetDecl().Insert(0, aNode);
                            }
                            else if (includeItem.Children[childNr] is IncludeItem)
                            {
                                IncludeItem aChild = (IncludeItem)includeItem.Children[childNr];
                                if (aChild.Current == null)
                                {
                                    AIncludeDecl node = new AIncludeDecl(new TInclude("include"),
                                                                         new TStringLiteral("\"TriggerLibs/NativeLib\""));
                                    includeItem.Current.GetDecl().Insert(0, node);
                                }
                                else
                                {
                                    PDecl[] decls = new PDecl[aChild.Current.GetDecl().Count];
                                    aChild.Current.GetDecl().CopyTo(decls, 0);
                                    for (int k = decls.Length - 1; k >= 0; k--)
                                    {
                                        includeItem.Current.GetDecl().Insert(0, decls[k]);
                                    }
                                    aChild.Current.Parent().RemoveChild(aChild.Current);
                                    //i = -1;
                                }
                            }
                            includeItem.Children.RemoveAt(childNr);
                        }
                    }
                }
            }
            else
            {
                foreach (IncludeItem includeItem in allItems.OfType <IncludeItem>())
                {
                    for (int i = includeItem.Children.Count - 1; i >= 0; i--)
                    {
                        Node node;
                        if (includeItem.Children[i] is IncludeItem)
                        {
                            IncludeItem aItem = (IncludeItem)includeItem.Children[i];
                            node = new AIncludeDecl(new TInclude("include"),
                                                    new TStringLiteral("\"" + (aItem.Current == null ? "TriggerLibs/NativeLib" : aItem.Current.GetName().Text.Replace("\\", "/")) + "\""));
                            if (aItem.Current == null && finalTrans.mainEntry != null)
                            {
                                //Search for user defined initlib
                                bool foundInvoke = false;
                                foreach (ASimpleInvokeExp invokeExp in finalTrans.data.SimpleMethodLinks.Keys)
                                {
                                    if (invokeExp.GetName().Text == "libNtve_InitLib" && invokeExp.GetArgs().Count == 0)
                                    {
                                        /*finalTrans.errors.Add(new ErrorCollection.Error(invokeExp.GetName(),
                                         *                                              Util.GetAncestor<AASourceFile>(
                                         *                                                  invokeExp),
                                         *                                              "You are invoking libNtve_InitLib() yourself somewhere. It will not be auto inserted.",
                                         *                                              true));*/
                                        foundInvoke = true;
                                        break;
                                    }
                                }

                                if (!foundInvoke)
                                {
                                    //Init the lib
                                    ASimpleInvokeExp initExp = new ASimpleInvokeExp();
                                    initExp.SetName(new TIdentifier("libNtve_InitLib"));
                                    finalTrans.data.ExpTypes[initExp] = new AVoidType(new TVoid("void"));
                                    foreach (AMethodDecl method in finalTrans.data.Libraries.Methods)
                                    {
                                        if (method.GetName().Text == "libNtve_InitLib" && method.GetFormals().Count == 0)
                                        {
                                            finalTrans.data.SimpleMethodLinks[initExp] = method;
                                        }
                                    }
                                    AABlock block = (AABlock)finalTrans.mainEntry.GetBlock();
                                    block.GetStatements().Insert(0, new AExpStm(new TSemicolon(";"), initExp));
                                }
                            }
                        }
                        else if (includeItem.Children[i] is FieldItem)
                        {
                            FieldItem aItem = (FieldItem)includeItem.Children[i];
                            node = aItem.FieldDecl;
                            node.Parent().RemoveChild(node);
                        }
                        else if (includeItem.Children[i] is StructItem)
                        {
                            StructItem aItem = (StructItem)includeItem.Children[i];
                            node = aItem.StructDecl;
                            node.Parent().RemoveChild(node);
                        }
                        else if (includeItem.Children[i] is MethodDeclItem)
                        {
                            MethodDeclItem aItem = (MethodDeclItem)includeItem.Children[i];
                            AMethodDecl    aNode = new AMethodDecl();
                            if (aItem.RealDecl.GetStatic() != null)
                            {
                                aNode.SetStatic(new TStatic("static"));
                            }
                            aNode.SetReturnType(Util.MakeClone(aItem.RealDecl.GetReturnType(), finalTrans.data));
                            aNode.SetName(new TIdentifier(aItem.RealDecl.GetName().Text));
                            foreach (AALocalDecl formal in aItem.RealDecl.GetFormals())
                            {
                                AALocalDecl clone = new AALocalDecl(new APublicVisibilityModifier(), null, null, null, null, Util.MakeClone(formal.GetType(), finalTrans.data), new TIdentifier(formal.GetName().Text), null);
                                aNode.GetFormals().Add(clone);
                            }
                            node = aNode;
                        }
                        else
                        {
                            throw new Exception("FixIncludes.Apply: Unexpected item type");
                        }

                        includeItem.Current.GetDecl().Insert(0, node);
                    }
                }
            }
        }
Exemplo n.º 8
0
    void Update()
    {
        if (BossClass.instance.Health > 1000)
        {
            switch (currentState)
            {
            case Phase1.Intro:
                if (BossClass.instance.playIntro)
                {
                    if (counter > 0)
                    {
                        counter -= Time.deltaTime;
                    }
                    else
                    {
                        currentState = Phase1.GatlingGun;
                        counter      = gatlingGunTime;
                    }
                }

                break;

            case Phase1.GatlingGun:
                if (counter > 0)
                {
                    counter -= Time.deltaTime;

                    activeSpeed = speedWhenGuntlingGun;

                    transform.position = Vector2.MoveTowards(transform.position, player.transform.position, activeSpeed * Time.deltaTime);

                    if (shootCounter > 0)
                    {
                        shootCounter -= Time.deltaTime;
                    }
                    else
                    {
                        foreach (Transform t in gatlingGunFirePoints)
                        {
                            Instantiate(gatlingGunBullet, t.position, t.rotation);
                        }
                        shootCounter = gatlingGunShootingBreaks;
                    }
                }
                else
                {
                    currentState = Phase1.Idle;
                    counter      = idleTime;
                }
                break;

            case Phase1.Idle:
                if (counter > 0)
                {
                    counter -= Time.deltaTime;

                    waitTimeCounter -= Time.deltaTime;

                    if (waitTimeCounter < 0)
                    {
                        if (hasShootCircle == false)
                        {
                            foreach (Transform t in allFirePoints)
                            {
                                Instantiate(gatlingGunBullet, t.position, t.rotation);
                            }
                            hasShootCircle = true;
                        }
                    }
                }
                else
                {
                    waitTimeCounter = waitTimeBeforeShooting;
                    hasShootCircle  = false;
                    currentState    = Phase1.Dash;
                    counter         = dashTime;
                }
                break;

            case Phase1.Dash:

                if (counter > 0)
                {
                    counter -= Time.deltaTime;

                    if (dashBreaksCounter > 0)
                    {
                        if (dashCircle == false)
                        {
                            foreach (Transform t in allFirePoints)
                            {
                                Instantiate(bulletRight, t.position, t.rotation);
                            }
                            dashCircle = true;
                        }

                        dashBreaksCounter -= Time.deltaTime;
                    }
                    else
                    {
                        activeSpeed = dashSpeed;

                        if (hasPickedPoint == false)
                        {
                            randomMovePoint = Random.Range(0, dashMovePoints.Length);
                            hasPickedPoint  = true;
                        }


                        transform.position = Vector2.MoveTowards(transform.position, dashMovePoints[randomMovePoint].position, activeSpeed * Time.deltaTime);
                        if (Vector2.Distance(transform.position, dashMovePoints[randomMovePoint].position) < 0.1f)
                        {
                            Debug.Log("okay");
                            dashBreaksCounter = dashBreaks;
                            hasPickedPoint    = false;
                            dashCircle        = false;
                        }
                    }
                }
                else
                {
                    currentState = Phase1.GatlingGun;
                    counter      = gatlingGunTime;
                }

                break;
            }
        }
        else
        {
            if (hasCounterBeenSet == false)
            {
                counter           = phase2introTime;
                hasCounterBeenSet = true;
            }

            switch (phase2CurrentState)
            {
            case Phase2.Intro:
                if (counter > 0)
                {
                    counter -= Time.deltaTime;
                    if (shouldFade)
                    {
                        book.color = new Color(book.color.r, book.color.g, book.color.b, Mathf.MoveTowards(book.color.a, 1f, bookVisibleSpeed * Time.deltaTime));
                        if (book.color.a == 1f)
                        {
                            shouldFade = false;
                        }
                    }
                }
                else
                {
                    hasPickedPoint          = false;
                    dashCircle              = false;
                    dashBreaksCounter       = phase2DashBreaks;
                    phase2NightShootCounter = nightShootAttackBreaks;
                    counter            = phase2NightStartTime;
                    phase2CurrentState = Phase2.NightStart;
                    shouldFade         = true;
                }
                break;

            case Phase2.Idle:

                break;

            case Phase2.NightStart:

                if (counter > 0)
                {
                    counter -= Time.deltaTime;

                    if (shouldFade)
                    {
                        book.color   = new Color(book.color.r, book.color.g, book.color.b, Mathf.MoveTowards(book.color.a, 0f, bookVisibleSpeed * Time.deltaTime));
                        bodySR.color = new Color(bodySR.color.r, bodySR.color.g, bodySR.color.b, Mathf.MoveTowards(bodySR.color.a, 0f, bookVisibleSpeed * Time.deltaTime));

                        if (bodySR.color.a == 0f)
                        {
                            shouldFade = false;
                        }
                    }
                }
                else
                {
                    collider.enabled   = false;
                    shouldFade         = true;
                    counter            = phase2NightAttackTime;
                    phase2CurrentState = Phase2.NightAttack;
                }
                break;


            case Phase2.NightAttack:

                if (counter > 0)
                {
                    counter -= Time.deltaTime;

                    Vector2 tempPos = nightPhaseFirePointLeft.transform.position;

                    tempPos.y = Mathf.MoveTowards(nightPhaseFirePointLeft.transform.position.y, player.transform.position.y, speedToMoveFirePoint * Time.deltaTime);

                    Vector2 tempPosRight = nightPhaseFirePointRight.transform.position;

                    tempPosRight.y = Mathf.MoveTowards(nightPhaseFirePointRight.transform.position.y, player.transform.position.y, speedToMoveFirePoint * Time.deltaTime);

                    nightPhaseFirePointLeft.transform.position  = tempPos;
                    nightPhaseFirePointRight.transform.position = tempPosRight;

                    if (phase2NightShootCounter > 0)
                    {
                        phase2NightShootCounter -= Time.deltaTime;
                    }
                    else
                    {
                        Instantiate(bulletRight, nightPhaseFirePointLeft.transform.position, nightPhaseFirePointLeft.transform.rotation);
                        Instantiate(bossBulletLeft, nightPhaseFirePointRight.transform.position, nightPhaseFirePointLeft.transform.rotation);

                        phase2NightShootCounter = nightShootAttackBreaks;
                    }
                }
                else
                {
                    counter            = phase2GoVisible;
                    phase2CurrentState = Phase2.GoVisible;
                }

                break;

            case Phase2.GoVisible:

                if (counter > 0)
                {
                    collider.enabled = true;

                    counter -= Time.deltaTime;

                    if (shouldFade)
                    {
                        book.color   = new Color(book.color.r, book.color.g, book.color.b, Mathf.MoveTowards(book.color.a, 1f, bookVisibleSpeed * Time.deltaTime));
                        bodySR.color = new Color(bodySR.color.r, bodySR.color.g, bodySR.color.b, Mathf.MoveTowards(bodySR.color.a, 1f, bookVisibleSpeed * Time.deltaTime));

                        if (bodySR.color.a == 1f)
                        {
                            shouldFade = false;
                        }
                    }
                }
                else
                {
                    counter            = phase2DashTime;
                    phase2CurrentState = Phase2.Dash;
                    shouldFade         = true;
                }


                break;

            case Phase2.Dash:

                if (counter > 0)
                {
                    counter -= Time.deltaTime;

                    if (dashBreaksCounter > 0)
                    {
                        if (dashCircle == false)
                        {
                            foreach (Transform t in allFirePoints)
                            {
                                Instantiate(bulletRight, t.position, t.rotation);
                            }

                            Instantiate(bigBall, transform.position, transform.rotation);

                            dashCircle = true;
                        }

                        dashBreaksCounter -= Time.deltaTime;
                    }
                    else
                    {
                        activeSpeed = phase2DashSpeed;

                        if (hasPickedPoint == false)
                        {
                            randomMovePoint = Random.Range(0, dashMovePoints.Length);
                            hasPickedPoint  = true;
                        }


                        transform.position = Vector2.MoveTowards(transform.position, dashMovePoints[randomMovePoint].position, activeSpeed * Time.deltaTime);
                        if (Vector2.Distance(transform.position, dashMovePoints[randomMovePoint].position) < 0.1f)
                        {
                            Debug.Log("okay");
                            dashBreaksCounter = dashBreaks;
                            hasPickedPoint    = false;
                            dashCircle        = false;
                        }
                    }
                }
                else
                {
                    phase2CurrentState = Phase2.NightStart;
                    counter            = phase2NightStartTime;
                }

                break;
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (BossClass.instance.Health > 1250)
        {
            switch (currentState)
            {
            case Phase1.Intro:

                if (BossClass.instance.playIntro)
                {
                    ChangeAnimationState("SpookyWood_Intro");

                    if (counter > 0)
                    {
                        counter -= Time.deltaTime;
                    }
                    else
                    {
                        currentState = Phase1.Stay;
                        counter      = stayTime;
                    }
                }

                break;



            case Phase1.Stay:

                ChangeAnimationState("SpookyWood_Idle");

                if (counter > 0)
                {
                    counter -= Time.deltaTime;
                }
                else
                {
                    currentState = Phase1.ChaseWithBothHandsShooting;
                    counter      = chaseWithBothHandsShootingTime;
                }

                break;

            case Phase1.ChaseWithBothHandsShooting:

                ChangeAnimationState("SpookyWood_Walk");

                if (counter > 0)
                {
                    counter -= Time.deltaTime;

                    transform.position = Vector2.MoveTowards(transform.position, player.transform.position, activeSpeed * Time.deltaTime);

                    leftHand.Rotate(Vector3.forward * rotateSpeedBothHandsPhase1 * Time.deltaTime);
                    rightHand.Rotate(Vector3.back * rotateSpeedBothHandsPhase1 * Time.deltaTime);

                    if (shootCounter > 0)
                    {
                        shootCounter -= Time.deltaTime;
                    }
                    else
                    {
                        Instantiate(bulletGoesRightPrefab, leftHand.position, leftHand.rotation);
                        Instantiate(bulletGoesRightPrefab, rightHand.position, rightHand.rotation);

                        shootCounter = breakBetweenShotsBothHandsPhase1;
                    }
                }
                else
                {
                    leftHand.rotation  = Quaternion.identity;
                    rightHand.rotation = Quaternion.identity;
                    currentState       = Phase1.StayAndShootBombs;
                    counter            = stayAndShootBombsTime;
                    shootCounter       = breaksBetweenBombsPhase1;
                }

                break;

            case Phase1.StayAndShootBombs:

                ChangeAnimationState("SpookyWood_Idle");

                if (counter > 0)
                {
                    counter -= Time.deltaTime;

                    if (shootCounter > 0)
                    {
                        shootCounter -= Time.deltaTime;
                    }
                    else
                    {
                        Instantiate(bombBullet, transform.position, Quaternion.identity);
                        shootCounter = breaksBetweenBombsPhase1;
                    }
                }
                else
                {
                    shootCounter = breakBetweenShotsBothHandsPhase1;

                    counter      = breakTime;
                    currentState = Phase1.Break;
                }

                break;

            case Phase1.SpawnEnemies:

                ChangeAnimationState("SpookyWood_Walk");

                if (spawnersList.Count <= 0 || canSpawnSpawners)
                {
                    activeSpeed = goingToSpawnPointsSpeed;

                    switch (currentSpawnPoint)
                    {
                    case 0:
                        canSpawnSpawners   = true;
                        transform.position = Vector2.MoveTowards(transform.position, spawnPoints[0].position, activeSpeed * Time.deltaTime);

                        if (transform.position == spawnPoints[0].position)
                        {
                            Instantiate(spawner, transform.position, Quaternion.identity);
                            currentSpawnPoint = 1;
                        }

                        break;

                    case 1:
                        canSpawnSpawners   = true;
                        transform.position = Vector2.MoveTowards(transform.position, spawnPoints[1].position, activeSpeed * Time.deltaTime);

                        if (transform.position == spawnPoints[1].position)
                        {
                            Instantiate(spawner, transform.position, Quaternion.identity);
                            currentSpawnPoint = 2;
                        }

                        break;

                    case 2:
                        canSpawnSpawners   = true;
                        transform.position = Vector2.MoveTowards(transform.position, spawnPoints[2].position, activeSpeed * Time.deltaTime);

                        if (transform.position == spawnPoints[2].position)
                        {
                            Instantiate(spawner, transform.position, Quaternion.identity);
                            currentSpawnPoint = 3;
                        }

                        break;

                    case 3:
                        transform.position = Vector2.MoveTowards(transform.position, spawnPoints[3].position, activeSpeed * Time.deltaTime);

                        if (transform.position == spawnPoints[3].position)
                        {
                            Instantiate(spawner, transform.position, Quaternion.identity);
                            currentSpawnPoint = 0;
                            activeSpeed       = speed;
                            currentState      = Phase1.Chase;
                            counter           = chaseTIme;
                            canSpawnSpawners  = false;
                        }

                        break;
                    }
                }
                else
                {
                    currentState = Phase1.Chase;
                    counter      = chaseTIme;
                }

                break;

            case Phase1.Break:

                ChangeAnimationState("SpookyWood_Idle");

                if (counter > 0)
                {
                    counter -= Time.deltaTime;
                }
                else
                {
                    currentState = Phase1.SpawnEnemies;
                }

                break;

            case Phase1.Chase:

                ChangeAnimationState("SpookyWood_Walk");

                if (counter > 0)
                {
                    counter           -= Time.deltaTime;
                    transform.position = Vector2.MoveTowards(transform.position, player.transform.position, activeSpeed * Time.deltaTime);
                }
                else
                {
                    counter      = chaseWithBothHandsShootingTime;
                    currentState = Phase1.ChaseWithBothHandsShooting;
                }

                break;
            }
        }

        else
        {
            if (hasCounterBeenSet == false)
            {
                counter           = phase2IntroTime;
                shootCounter      = breakBetweenBigBallsPhase2;
                activeSpeed       = phase2Speed;
                hasCounterBeenSet = true;
            }

            switch (currentPhase2State)
            {
            case Phase2.Intro:

                ChangeAnimationState("SpookyWood_Phase2Intro");

                if (counter > 0)
                {
                    counter -= Time.deltaTime;
                }
                else
                {
                    currentPhase2State = Phase2.Stay;
                    counter            = phase2StayTime;
                }

                break;

            case Phase2.Stay:

                ChangeAnimationState("SpookyWood_Phase2Idle");

                if (counter > 0)
                {
                    counter -= Time.deltaTime;
                }
                else
                {
                    currentPhase2State = Phase2.ChaseWithBigBall;
                    counter            = phase2ChaseBigBallTime;
                }

                break;

            case Phase2.ChaseWithBigBall:

                ChangeAnimationState("SpookyWood_Phase2Walk");

                transform.position = Vector2.MoveTowards(transform.position, player.transform.position, activeSpeed * Time.deltaTime);

                if (counter > 0)
                {
                    counter -= Time.deltaTime;

                    if (hasShootBigBall == false)
                    {
                        Instantiate(bigBallPrefab, transform.position, Quaternion.identity);
                        hasShootBigBall = true;
                    }

                    if (shootCounter > 0)
                    {
                        shootCounter -= Time.deltaTime;
                    }
                    else
                    {
                        hasShootBigBall = false;
                        shootCounter    = breakBetweenBigBallsPhase2;
                    }
                }
                else
                {
                    hasShootBigBall    = false;
                    leftHand.rotation  = Quaternion.identity;
                    rightHand.rotation = Quaternion.identity;
                    currentPhase2State = Phase2.StayAndShootBombs;
                    counter            = phase2StayAndShootBombsTime;
                    shootCounter       = breaksBetweenBombsPhase2;
                }

                break;

            case Phase2.StayAndShootBombs:

                ChangeAnimationState("SpookyWood_Phase2Idle");

                if (counter > 0)
                {
                    counter -= Time.deltaTime;

                    if (shootCounter > 0)
                    {
                        shootCounter -= Time.deltaTime;
                    }
                    else
                    {
                        Instantiate(phase2Bomb, transform.position, Quaternion.identity);
                        shootCounter = breaksBetweenBombsPhase2;
                    }
                }
                else
                {
                    shootCounter = breakBetweenBigBallsPhase2;

                    counter            = phase2BreakTime;
                    currentPhase2State = Phase2.Break;
                }

                break;

            case Phase2.SpawnEnemies:

                ChangeAnimationState("SpookyWood_Phase2Walk");

                if (spawnersList.Count <= 0 || canSpawnSpawners)
                {
                    activeSpeed = phase2GoingToSpawnPointsSpeed;

                    switch (currentSpawnPoint)
                    {
                    case 0:
                        canSpawnSpawners   = true;
                        transform.position = Vector2.MoveTowards(transform.position, spawnPoints[0].position, activeSpeed * Time.deltaTime);

                        if (transform.position == spawnPoints[0].position)
                        {
                            Instantiate(spawner, transform.position, Quaternion.identity);
                            currentSpawnPoint = 1;
                        }

                        break;

                    case 1:
                        canSpawnSpawners   = true;
                        transform.position = Vector2.MoveTowards(transform.position, spawnPoints[1].position, activeSpeed * Time.deltaTime);

                        if (transform.position == spawnPoints[1].position)
                        {
                            Instantiate(spawner, transform.position, Quaternion.identity);
                            currentSpawnPoint = 2;
                        }

                        break;

                    case 2:
                        canSpawnSpawners   = true;
                        transform.position = Vector2.MoveTowards(transform.position, spawnPoints[2].position, activeSpeed * Time.deltaTime);

                        if (transform.position == spawnPoints[2].position)
                        {
                            Instantiate(spawner, transform.position, Quaternion.identity);
                            currentSpawnPoint = 3;
                        }

                        break;

                    case 3:
                        transform.position = Vector2.MoveTowards(transform.position, spawnPoints[3].position, activeSpeed * Time.deltaTime);

                        if (transform.position == spawnPoints[3].position)
                        {
                            Instantiate(spawner, transform.position, Quaternion.identity);
                            currentSpawnPoint  = 0;
                            activeSpeed        = phase2Speed;
                            currentPhase2State = Phase2.BowAttack;
                            counter            = phase2BowAttackTime;
                            canSpawnSpawners   = false;
                            shootCounter       = breaksBetweenBowAttacksPhase2;
                        }

                        break;
                    }
                }
                else
                {
                    currentPhase2State = Phase2.BowAttack;
                    counter            = phase2BowAttackTime;
                    shootCounter       = breaksBetweenBowAttacksPhase2;
                }

                break;

            case Phase2.Break:

                ChangeAnimationState("SpookyWood_Phase2Idle");

                if (counter > 0)
                {
                    counter -= Time.deltaTime;
                }
                else
                {
                    currentPhase2State = Phase2.SpawnEnemies;
                }

                break;

            case Phase2.Chase:

                ChangeAnimationState("SpookyWood_Phase2Walk");

                if (counter > 0)
                {
                    counter           -= Time.deltaTime;
                    transform.position = Vector2.MoveTowards(transform.position, player.transform.position, activeSpeed * Time.deltaTime);
                }
                else
                {
                    counter            = phase2ChaseBigBallTime;
                    currentPhase2State = Phase2.ChaseWithBigBall;
                }

                break;

            case Phase2.BowAttack:

                Vector2 direction = player.transform.position - transform.position;
                direction.Normalize();

                float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
                BowAttackPoint.rotation = Quaternion.Euler(0, 0, angle);

                transform.position = Vector2.MoveTowards(transform.position, player.transform.position, activeSpeed * Time.deltaTime);

                if (counter > 0)
                {
                    counter -= Time.deltaTime;
                    if (shootCounter > 0)
                    {
                        shootCounter -= Time.deltaTime;
                    }
                    else
                    {
                        foreach (Transform t in AllBowAttacksFirePoints)
                        {
                            Instantiate(bowAttackBullet, t.position, t.rotation);
                        }

                        shootCounter = breaksBetweenBowAttacksPhase2;
                    }
                }
                else
                {
                    shootCounter       = breakBetweenBigBallsPhase2;
                    counter            = phase2ChaseBigBallTime;
                    currentPhase2State = Phase2.ChaseWithBigBall;
                }



                break;
            }
        }
    }