void invaderSrow()
    {
        InvaderController F = new InvaderController();
        //F.newX = newPos2.x;

        if (secondrow)
        {
            if (add2Invader < 1f)
            {
                newPos.x = -800f;
                newPos.y = 0f;
                newPos.z = 500f;
                roto.z = 180f;
                //Instantiate (invaders2, newPos, roto);
                add2Invader++; //add2Invader should be 1 now....
                //secondrow = false;
            }

            if (add2Invader == 1f)
            {
                newPos2 = transform.position;
                newPos2.x = -800f + 200f;
                //F.newX = -800f;
                //F.newX = newPos2.x + 200f;
                newPos2.y = 0f;
                newPos2.z = 500f;
                roto2.z = 180f;
                //Instantiate (invaders3, newPos2, roto2);
                add2Invader++;
            }

        }
        return;
    }
Example #2
0
    public void DecreaseEnemyCount(InvaderController invader, bool shotByPlayer)
    {
        invaders.Remove(invader);

        if (invaders.Count == 0 && shotByPlayer)
        {
            waveSize += waveNum * 2;
            gameManager.IncreaseScore(100 * waveNum);
        }

        int randomUFO = Random.Range(spawnChance, 100);
        if (randomUFO <= spawnChance)
        {
            int randomLeftOrRight = Random.Range(0, 100);
            if (randomLeftOrRight < 50)
            {
                Instantiate(UFOPrefab, new Vector3(-9, 4, 0), Quaternion.identity);
            }
            else
            {
                Instantiate(UFOPrefab, new Vector3(9, 4, 0), Quaternion.identity);
            }
            spawnChance = 0;
        }
        spawnChance++;
    }
Example #3
0
 public void Initialize(InvaderController AttachedInvaderController, float UpdateRate)
 {
     this.UpdateRate = UpdateRate;
     this.AttachedInvaderController = AttachedInvaderController;
     gameObject.SetActive(true);
     AttachedInvaderController.OnDeath += OnCharacterDeath; // TODO: Remove & use update
     BGImage.color = NormalBGColor;
 }
    // given sub army blueprints, find corresponding controllers in the current army and assign to a sub army controller
    public List <Dictionary <InvaderType, List <InvaderController> > > SplitIntoSubArmies(List <ArmyBlueprint> armyCompositions)
    {
        List <Dictionary <InvaderType, List <InvaderController> > > subArmyControllers = new List <Dictionary <InvaderType, List <InvaderController> > >();

        foreach (ArmyBlueprint subarmy in armyCompositions)
        {
            Dictionary <InvaderType, List <InvaderController> > controllers = new Dictionary <InvaderType, List <InvaderController> >();
            List <InvaderController> invaderControllers = new List <InvaderController>();
            foreach (ushort archer in subarmy.Archers)
            {
                InvaderController match = mInvaderControllers[InvaderType.Archer].Find((x) =>
                                                                                       { return(x.CurrentHealth == archer && x.CanBeUsed); });
                Debug.Assert(match != null);
                match.CanBeUsed = false;
                invaderControllers.Add(match);
            }
            controllers.Add(InvaderType.Archer, invaderControllers);

            invaderControllers = new List <InvaderController>();
            foreach (ushort healer in subarmy.Healers)
            {
                InvaderController match = mInvaderControllers[InvaderType.Healer].Find((x) =>
                                                                                       { return(x.CurrentHealth == healer && x.CanBeUsed); });
                Debug.Assert(match != null);
                match.CanBeUsed = false;
                invaderControllers.Add(match);
            }
            controllers.Add(InvaderType.Healer, invaderControllers);

            invaderControllers = new List <InvaderController>();
            foreach (ushort soldier in subarmy.Soldiers)
            {
                InvaderController match = mInvaderControllers[InvaderType.Soldier].Find((x) =>
                                                                                        { return(x.CurrentHealth == soldier && x.CanBeUsed); });
                Debug.Assert(match != null);
                match.CanBeUsed = false;
                invaderControllers.Add(match);
            }
            controllers.Add(InvaderType.Soldier, invaderControllers);
            subArmyControllers.Add(controllers);
        }
        // assert
        foreach (List <InvaderController> controllers in mInvaderControllers.Values)
        {
            foreach (InvaderController controller in controllers)
            {
                Debug.Assert(!controller.CanBeUsed);
            }
        }
        return(subArmyControllers);
    }
Example #5
0
    void Start()
    {
        if (invaderControllerObject == null || playerControllerObject == null)
        {
            Debug.LogError("Missing player and invader controller prefab references");
        }

        invaderController = invaderControllerObject.GetComponent <InvaderController>();
        playerController  = playerControllerObject.GetComponent <PlayerController>();

        if (invaderController == null || playerController == null)
        {
            Debug.LogError("Missing player or invader controller");
        }
    }
Example #6
0
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("AlienSaveSpot"))
        {
            SaveControllingAlien();

            foreach (PlayerCharacter p in GameSceneManager.Instance.GameState.Invaders)
            {
                p.SaveControllingAlien();
            }
        }

        if (other.CompareTag("AlienControlTrigger"))                                     // Collision with alien
        {
            AlienController a = other.transform.parent.GetComponent <AlienController>(); // Get alien component

            if (a != null)                                                               // Check if alien component is ok
            {
                if (!IsControllingAlien())                                               // Player is not controlling alien
                {
                    SetControllingAlien(a);
                }
                else // Player is controlling alien, find an invader available
                {
                    List <InvaderController> availableInvaders = GameSceneManager.Instance.GameState.Invaders.Where(i => !i.IsDead && !i.IsControllingAlien()).ToList();
                    if (availableInvaders.Count > 0)
                    {
                        InvaderController first = availableInvaders.First();
                        first.SetControllingAlien(a); // Give alien controll to the first invader found
                    }
                }
            }
        }

        if (GM.GameState.IsEnergyStateActive)
        {
            if (other.CompareTag("Soldier"))
            {
                SoldierController soldier = other.GetComponent <SoldierController>();
                if (soldier != null && !soldier.IsDead)
                {
                    HitSoldierParticles.Play();
                    soldier.DoDeath();
                }
            }
        }
    }
    public void UpdateHealth(ArmyBlueprint afterAssault, float overSeconds)
    {
        for (int i = 0; i < afterAssault.Archers.Count; ++i)
        {
            InvaderController controller = mInvaderControllers[InvaderType.Archer][i];
            controller.UpdateHealth(afterAssault.Archers[i], overSeconds);
        }

        for (int i = 0; i < afterAssault.Healers.Count; ++i)
        {
            mInvaderControllers[InvaderType.Healer][i].UpdateHealth(afterAssault.Healers[i], overSeconds);
        }

        for (int i = 0; i < afterAssault.Soldiers.Count; ++i)
        {
            mInvaderControllers[InvaderType.Soldier][i].UpdateHealth(afterAssault.Soldiers[i], overSeconds);
        }
    }
 // Should only be called once when army is first being created
 public void Initialize(ArmyBlueprint army)
 {
     Initialize();
     foreach (ushort archer in army.Archers)
     {
         InvaderController controller = Instantiate(InvaderPrefab, transform.parent);
         controller.Initialize(archer, InvaderType.Archer);
         mInvaderControllers[InvaderType.Archer].Add(controller);
     }
     foreach (ushort healer in army.Healers)
     {
         InvaderController controller = Instantiate(InvaderPrefab, transform.parent);
         controller.Initialize(healer, InvaderType.Healer);
         mInvaderControllers[InvaderType.Healer].Add(controller);
     }
     foreach (ushort soldier in army.Soldiers)
     {
         InvaderController controller = Instantiate(InvaderPrefab, transform.parent);
         controller.Initialize(soldier, InvaderType.Soldier);
         mInvaderControllers[InvaderType.Soldier].Add(controller);
     }
     LayoutArmy(); // create at position in army
 }
Example #9
0
 protected virtual void OnHitEnemy(InvaderController vAH)
 {
 }
Example #10
0
    public void Initialize() // Called by GameSceneManager
    {
        Debug.LogError("Initializing SpawnManager...");

        if (PredefinedPositions.Count <= 1)
        {
            Debug.LogError("IMPORTANT: SpawnManager needs more Predefined Positions!");
            return;
        }

        Debug.LogError("Spawning dynamic prefabs");
        var watch = System.Diagnostics.Stopwatch.StartNew();

        foreach (SpawnableObject prefab in SpawnablePrefabs)
        {
            if (prefab.SpawnType == SpawnType.MANUAL_PLACEMENT)
            {
                continue;
            }

            for (int i = 0; i < prefab.MaxInstances; i++)
            {
                SpawnableObject n = null;

                switch (prefab.SpawnType)
                {
                case SpawnType.RANDOM_PREDEFINED_POSITION:
                    n = Instantiate(prefab, GetRandomPredefinedPosition(), Quaternion.identity);
                    break;

                case SpawnType.RANDOM_MAP_POSITION:
                    n = Instantiate(prefab, GetRandomMapPosition(), Quaternion.identity);
                    break;

                case SpawnType.PLAYER_FORWARD:
                    n = Instantiate(prefab);
                    break;
                }

                if (n.AddRespawnTimeOnStart)
                {
                    n.SetRespawnTime();
                }
                if (n.ShouldStartInactive)
                {
                    n.gameObject.SetActive(false);
                }

                if (n != null)
                {
                    ObjectPool.Add(n);
                }
            }
        }
        watch.Stop();
        var elapsedMs = watch.ElapsedMilliseconds;

        Debug.LogError("Spawning dynamic prefabs took " + elapsedMs + " ms");

        // Spawn Invaders
        Queue <Transform> q = new Queue <Transform>(InvaderSpawnPoints);

        for (int i = 0; i < RemoteSettings.Instance.MAX_INVADERS; i++)
        {
            var s = q.Dequeue();
            InvaderController b = Instantiate(InvaderPrefab, s.position, Quaternion.identity);
            GameSceneManager.Instance.GameState.Invaders.Add(b);
            GameSceneManager.Instance.GameState.CurrentAliveInvaders++;
            GameUIController.Instance.RegisterInvader(b);
            q.Enqueue(s);
        }

        // Spawn player
        GameSceneManager.Instance.GameState.Player = Instantiate(PlayerPrefab, PlayerSpawnPoint.position, Quaternion.identity);

        // Initialize invaders target
        foreach (InvaderController i in GameSceneManager.Instance.GameState.Invaders)
        {
            i.target = GameSceneManager.Instance.GameState.Player.transform;
        }

        // Start update interval

        InvokeRepeating("UpdateInterval", UpdateRate, UpdateRate);

        Debug.LogError("SpawnManager is ready");
    }
Example #11
0
 protected override void OnHitEnemy(InvaderController vAH)
 {
     vAH.Explode();                  //Tell Enemy to explode
 }
    void SpawnInvaders()
    {
        InvaderController G = new InvaderController ();

        if (spawnInvader)
        {
            if (addInvader < 1f)
            {
                newPos.x = 900f;
                newPos.y = 0f;
                newPos.z = 800f;
                roto.z = 180f;
                Instantiate (invaders, newPos, roto);
                addInvader++;
         	}

            if (addInvader == 1f)
            {
                newPos.x = newPos.x - 200f;
                newPos.y = 0f;
                newPos.z = 800f;
                roto.z = 180f;
                Instantiate (invaders, newPos, roto);
                addInvader++;
            }

            if (addInvader == 2f)
            {
                newPos.x = newPos.x - 200f;
                newPos.y = 0f;
                newPos.z = 800f;
                roto.z = 180f;
                Instantiate (invaders, newPos, roto);
                addInvader++;
            }

            if (addInvader == 3f)
            {
                newPos.x = newPos.x - 200f;
                newPos.y = 0f;
                newPos.z = 800f;
                roto.z = 180f;
                Instantiate (invaders, newPos, roto);
                addInvader++;
            }

            if (addInvader == 4f)
            {
                newPos.x = newPos.x - 200f;
                newPos.y = 0f;
                newPos.z = 800f;
                roto.z = 180f;
                Instantiate (invaders, newPos, roto);
                addInvader++;
            }

            if (addInvader == 5f)
            {
                newPos.x = -800f;
                newPos.y = 0f;
                newPos.z = 500f;
                roto.z = 180f;
                Instantiate (invaders, newPos, roto);
                addInvader++;
            }

            if (addInvader == 6f)
            {
                newPos.x = -600f;
                newPos.y = 0f;
                newPos.z = 500f;
                roto.z = 180f;
                Instantiate (invaders, newPos, roto);
                addInvader++;
            }

            if (addInvader == 7f)
            {
                newPos.x = -400f;
                newPos.y = 0f;
                newPos.z = 500f;
                roto.z = 180f;
                Instantiate (invaders, newPos, roto);
                addInvader++;
            }

            if (addInvader == 8f)
            {
                newPos.x = -200f;
                newPos.y = 0f;
                newPos.z = 500f;
                roto.z = 180f;
                Instantiate (invaders, newPos, roto);
                addInvader++;
            }

            if (addInvader == 9f)
            {
                newPos.x = 0f;
                newPos.y = 0f;
                newPos.z = 500f;
                roto.z = 180f;
                Instantiate (invaders, newPos, roto);
                addInvader++;
            }

            if (addInvader == 10f)
            {
                newPos.x = 800f;
                newPos.y = 0f;
                newPos.z = 200f;
                roto.z = 180f;
                Instantiate (invaders2, newPos, roto);
                addInvader++;
            }

            if (addInvader == 11f)
            {
                newPos.x = newPos.x - 200f;
                newPos.y = 0f;
                newPos.z = 200f;
                roto.z = 180f;
                Instantiate (invaders2, newPos, roto);
                addInvader++;
            }

            if (addInvader == 12f)
            {
                newPos.x = newPos.x - 200f;
                newPos.y = 0f;
                newPos.z = 200f;
                roto.z = 180f;
                Instantiate (invaders2, newPos, roto);
                addInvader++;
            }

            if (addInvader == 13f)
            {
                newPos.x = newPos.x - 200f;
                newPos.y = 0f;
                newPos.z = 200f;
                roto.z = 180f;
                Instantiate (invaders2, newPos, roto);
                addInvader++;
            }

            if (addInvader == 14f)
            {
                newPos.x = newPos.x - 200f;
                newPos.y = 0f;
                newPos.z = 200f;
                roto.z = 180f;
                Instantiate (invaders2, newPos, roto);
                addInvader++;
            }
        }

        return;
    }
Example #13
0
    public void RegisterInvader(InvaderController i)
    {
        InvaderHealthDisplayUI n = Instantiate(_InvaderHealthDisplayUI, InvadersHealthDisplayParent, false);

        n.Initialize(i, InvaderHealthDisplayUpdateRate);
    }