/// <summary>
    /// Missile Hit something - an enemy or a player
    /// If the the game over condition exists, just return
    /// </summary>
    public void MissileHit(GameObject hitObject)
    {
        if (IsGameOver())
        {
            return;
        }

        if (hitObject.tag == "Player")
        {
            PlayerHit();
        }
        else if (hitObject.tag == "Enemy" || gameMode == GAME_MODE.WAVE_ACTIVE)
        {
            EnemyLogicController elc = hitObject.GetComponent <EnemyLogicController>();
            if (elc && elc.isActiveAndEnabled)
            {
                // Check to see if the enemy is dead
                if (elc.ReduceLife())
                {
                    score += elc.ScoreValue;
                    if (score > highestScore)
                    {
                        HighScoreLabelValue.SetValue(score);
                    }
                    ScoreLabelValue.SetValue(score);
                    EnemiesContainerLogic.UpdateContainerValues(true);
                }
            }

            if (EnemyContainer.childCount <= 0)
            {
                StartNextWave();
            }
        }
    }
Example #2
0
 /// <summary>
 /// Activates the enemies.
 /// * Called by GamePlayLogic
 /// </summary>
 /// <param name="wave">Current Wave</param>
 public void ActivateEnemies(int wave)
 {
     // Activate all enemies!
     for (int cnt = 0; cnt < transform.childCount; cnt++)
     {
         Transform            t   = transform.GetChild(cnt);
         EnemyLogicController elc = t.GetComponent <EnemyLogicController>();
         if (elc)
         {
             elc.BeginLogic(wave);
             elc.enabled = true;
         }
     }
 }
Example #3
0
    /// <summary>
    /// Moves the delay c.
    /// </summary>
    /// <param name="gobject">Enemy Game Object</param>
    void MoveDelayC(GameObject gobject)
    {
        EnemyLogicController enemyLogic = gobject.GetComponent <EnemyLogicController>();

        if (enemyLogic != null)
        {
            Vector3 pos = gobject.transform.position;
            if (pos.x < 0)
            {
                enemyLogic.MirrorX = true;
            }
            float waitStart = Mathf.Floor(Mathf.Abs(pos.x));
            if (waitStart % 2 != 0)
            {
                waitStart -= 1;
            }

            enemyLogic.MoveDelay = (waitStart + (Math.Abs(pos.y) * 3));
        }
    }
Example #4
0
    /// <summary>
    /// Moves delay function A.
    /// </summary>
    /// <param name="gobject">Enemy Game Object</param>
    void MoveDelayA(GameObject gobject)
    {
        EnemyLogicController enemyLogic = gobject.GetComponent <EnemyLogicController>();

        if (enemyLogic != null)
        {
            Vector3 pos  = gobject.transform.position;
            float   absx = Mathf.Abs(pos.x);

            if (pos.x > 0)
            {
                enemyLogic.MirrorX = true;
            }

            float waitStart = Mathf.Floor(7 - absx);

            waitStart *= 3;

            enemyLogic.MoveDelay = waitStart;
        }
    }
    /// <summary>
    /// Perform game over logic.
    ///  - Clean up enemies on screen (send them offscreen to be destroyed)
    ///  - Check to see if the player got a high score; if so, go into score collect
    ///    mode
    ///  - otherwise, wait a couple sends, then set state to provide "restart" of game
    /// </summary>

    IEnumerator DoGameOver()
    {
        player.SetActive(false);

        for (int cnt = 0; cnt < EnemyContainer.childCount; cnt++)
        {
            EnemyLogicController elc = EnemyContainer.GetChild(cnt).GetComponent <EnemyLogicController>();
            if (elc)
            {
                elc.FlitAway();
            }
        }

        //Activate game over text; (will fade and disable itself)
        GameOverText.SetActive(true);

        while (EnemyContainer.childCount > 0)
        {
            yield return(null);
        }


        highScoreViewer.gameObject.SetActive(true);
        yield return(new WaitForEndOfFrame());

        // If it is a high score..
        if (highScoreViewer.AddScore(score))
        {
            gameMode = GAME_MODE.COLLECING_SCORE;
        }
        else
        {
            // Force display of scores for a few seconds
            yield return(new WaitForSeconds(2.0f));

            StartCoroutine(AllowOrAutoRestart());
        }
        yield return(null);
    }
Example #6
0
    /// <summary>
    /// When an enemy dies, update the min/max extents and speed in which the
    /// container moves left / right
    /// </summary>
    /// <param name="speedOnly">If set to <c>true</c> speed only.</param>
    public void UpdateContainerValues(bool speedOnly = false)
    {
        if (!speedOnly)
        {
            float minX = 0;
            float maxX = 0;

            // Update MinX / MaxX to then figure out horizontal changes
            for (int cnt = 0; cnt < transform.childCount; cnt++)
            {
                Transform            t   = transform.GetChild(cnt);
                EnemyLogicController elc = t.GetComponent <EnemyLogicController>();
                if (elc)
                {
                    Vector3 pos = elc.StartPosition;
                    if (pos.x < minX)
                    {
                        minX = pos.x;
                    }
                    if (pos.x > maxX)
                    {
                        maxX = pos.x;
                    }
                }
            }
            horizontalMinX = -7.5f - minX;
            horizontalMaxX = 7.5f - maxX;
        }

        float childCountDeltaPct = 0.95f - ((float)transform.childCount) / ((float)startChildCount);

        horizontalSpeed = 0.5f + (childCountDeltaPct * 0.5f);


//		Debug.Log( "Min/Max X: " + minX.ToString() + " " + maxX.ToString() );
    }