Ejemplo n.º 1
0
    /// <summary>
    /// Call this when the game is over.
    /// </summary>
    public void EndGame()
    {
        // if game is already over,
        // exit function call.
        if (GAME_IS_OVER)
        {
            return;
        }

        GAME_IS_OVER = true;

        if (mHealthTarget != null)
        {
            mHealthTarget.LiveObject.CanDamage = false;
        }
        else
        {
            JCS_Debug.LogReminders(
                "No health object in the assign...");
        }

        if (GAME_OVER_PANEL == null)
        {
            JCS_Debug.LogError(
                "No game over panel have been set.");

            return;
        }

        // active the game over panel.
        GAME_OVER_PANEL.Active();

        // Destroy all the live object in the scene.
        JCS_2DLiveObjectManager.instance.DestroyAllLiveObject();
    }
Ejemplo n.º 2
0
    //========================================
    //      Self-Define
    //------------------------------
    //----------------------
    // Public Functions

    /// <summary>
    /// Spawn a wave by passing in wave count.
    /// </summary>
    /// <param name="spawnIndex"> spawn wave index. </param>
    public void SpawnAWave(int spawnIndex)
    {
        // if the enemy we assign is null, will cause errors.
        if (this.mLevelEnemy[spawnIndex] == null)
        {
            JCS_Debug.LogReminders(
                "Make sure all the enemy in handler are assigned.");

            return;
        }


        for (int count = 0;
             count < mEnemyPerWave;
             ++count)
        {
            if (BF_GameManager.instance.MOB_CURRENT_IN_SCENE >= BF_GameSettings.instance.TOTAL_MOB_IN_SCENE)
            {
                // don't spawn any more monster if there are too many monster in the scene.
                break;
            }

            // Spawn a monster.
            // add monster count in scene.
            ++BF_GameManager.instance.MOB_CURRENT_IN_SCENE;

            BF_LiveObject bf_liveObject = (BF_LiveObject)JCS_Utility.SpawnGameObject(
                this.mLevelEnemy[spawnIndex],
                this.mSpawnTransform.position);

            // Set live object in the scene layer.
            JCS_OrderLayerObject jcsolo = bf_liveObject.GetComponent <JCS_OrderLayerObject>();
            JCS_2DDynamicSceneManager.instance.SetObjectParentToOrderLayerByOrderLayerIndex(ref jcsolo, mOrderLayer);
        }
    }
Ejemplo n.º 3
0
    /// <summary>
    /// Spawn one wave enemies base on the game's level.
    /// </summary>
    private void SpawnAWaveByLevel()
    {
        // check the length of the enemy array prevent errors.
        if (mLevelEnemy.Length == 0)
        {
            JCS_Debug.LogReminders(
                "Could not spawn the enemy without enemy object assign...");

            return;
        }

        // 1) Check if the wave is ready to spawn.

        // get the current level
        int currentLevel = BF_GameManager.instance.CURRENT_LEVEL;

        // check if the current level reach to the starting level
        if (currentLevel < mStartingWave)
        {
            return;
        }

        // 2) check to see we can spawn enemies or not.

        // get spawning index.
        // current spawning index = current level - starting level
        int spawnIndex = (currentLevel - mStartingWave);

        // make sure the spawning index lower than
        // the length to prevent error.
        if (mLevelEnemy.Length <= spawnIndex)
        {
            return;
        }

        // if spawn check successfully than record down
        // the current spawn index.
        mCurrentSpawnIndex = spawnIndex;

        // 3) Spawn a wave.
        SpawnAWave(spawnIndex);

        // Update collision after spawn,
        // so the player and enemy will ignore each other
        // if this does not work, check the setting from
        // 'JCS_Settings' object's setting variables.
        JCS_CollisionManager.instance.SetCollisionMode();
    }
    //========================================
    //      Self-Define
    //------------------------------
    //----------------------
    // Public Functions

    //----------------------
    // Protected Functions

    //----------------------
    // Private Functions

    /// <summary>
    /// Spawn the player according to the pointed position.
    /// </summary>
    private void SpawnPlayers()
    {
        BF_GameSettings bfgs = BF_GameSettings.instance;

        BF_Player[] bfPlayers = bfgs.CHARACTERS_IN_GAME;

        for (int index = 0;
             index < bfgs.CHARACTERS_IN_TEAM;
             ++index)
        {
            if (mSpawnPos[index] == null)
            {
                JCS_Debug.LogReminders(
                    "No Spawn position references, plz check the transform in the array...");
                break;
            }

            if (bfPlayers[index] == null)
            {
                JCS_Debug.LogError(
                    "Character you want to spawn does not exist...");
                break;
            }


            // Spawn the player, and get the
            // player we just spawned, in order
            // to set facing.
            BF_Player bfp = (BF_Player)JCS_Utility.SpawnGameObject(
                bfPlayers[index],
                mSpawnPos[index].transform.position);

            // set the starting faceing
            bfp.TurnFace(mSpawnPos[index].Facing);

            // Set player in the order layer (scene layer).
            JCS_OrderLayerObject jcsolo = bfp.GetComponent <JCS_OrderLayerObject>();
            JCS_2DDynamicSceneManager.instance.SetObjectParentToOrderLayerByOrderLayerIndex(ref jcsolo, mOrderLayer);
        }
    }