Ejemplo n.º 1
0
 void Start()
 {
     if (instance == null)
     {
         instance = this;
     }
     // Initialization of difficulty and factors
     fHealthDiff           = 1f;
     fHealthWeight         = 1f;
     fNutrientDiff         = 1f;
     fNutrientWeight       = 1f;
     fLevelDiff            = 1f;
     fLevelWeight          = 1f;
     fCurrentDiff          = 1f;
     fMaxHealthInfluence   = .5f;
     fMaxNutrientInfluence = .5f;
     // Initialization of current health and num of nutrient
     if (EnemyMainFSM.Instance().Health != 0)
     {
         nCurrentHealth = EnemyMainFSM.Instance().Health;
     }
     if (EMController.Instance().NutrientNum != 0)
     {
         nCurrentNutrient = EMController.Instance().NutrientNum;
     }
 }
    // Enemy main nutrient getting absorbed and provide nutrient(child cell) to enemy main cell
    void Absorb()
    {
        Vector2 vectorToTarget = EMHelper.Instance().Position - (Vector2)transform.position;

        transform.position   = Vector2.MoveTowards(transform.position, EMHelper.Instance().Position, (vectorToTarget.magnitude * fAbsorbTime + fAbsorbSpeed) * Time.deltaTime);
        transform.localScale = Vector3.one *
                               (Vector2.Distance((Vector2)transform.position, EMHelper.Instance().Position)) / EMHelper.Instance().Radius *
                               Random.Range(.5f, 1f);
        if (Vector2.Distance((Vector2)transform.position, EMHelper.Instance().Position) < .1f || transform.localScale.x < .1f)
        {
            if (Level_Manager.LevelID < 4)
            {
                EMController.Instance().AddFewNutrient((int)(Random.Range(2, 6) * EMDifficulty.Instance().CurrentDiff));
            }
            else
            {
                EMController.Instance().AddFewChildCells((int)(Random.Range(2, 6) * EMDifficulty.Instance().CurrentDiff));
            }
            if (!EMAnimation.Instance().IsExpanding)
            {
                EMAnimation.Instance().IsExpanding = true;
            }
            Destroy(this.gameObject);
        }
    }
Ejemplo n.º 3
0
    void OnCollisionEnter2D(Collision2D col)
    {
        // Ignore collisions if is being scrificed for squad captain.
        if (m_bSacrificeToSquadCpt == true)
        {
            return;
        }

        // Hit Enemy Child
        if (col.gameObject.tag == Constants.s_strEnemyChildTag)
        {
            // Kill Enemy.
            col.gameObject.GetComponent <EnemyChildFSM>().KillChildCell();
            // Kill Self.
            KillPlayerChildCell();

            AudioManager.PlayPMSoundEffect(PlayerMainSFX.KillChild);
        }
        // Hit Enemy Main.
        else if (col.gameObject.tag == Constants.s_strEnemyTag)
        {
            // Damage Enemy.
            EMController.Instance().CauseDamageOne();
            MainCamera.CameraShake();

            KillPlayerChildCell();
        }
    }
Ejemplo n.º 4
0
    // Used to handle everything happens when spawns a child cell
    public IEnumerator ProduceChild()
    {
        if (bCanSpawn)
        {
            bCanSpawn = false;

            // Calling the Animate class for spawn animation
            Animate mAnimate;
            mAnimate = new Animate(this.transform);
            mAnimate.ExpandContract(0.1f, 1, 1.1f);

            if (Level_Manager.LevelID < 4)
            {
                EMController.Instance().ReduceNutrient();
            }
            // Randomize the interval time between spawns of child cells in terms of current difficulty
            float intervalTime = UnityEngine.Random.Range(
                1.25f / EMDifficulty.Instance().CurrentDiff,
                1.75f / EMDifficulty.Instance().CurrentDiff
                );

            if (Level_Manager.LevelID > 2)
            {
                intervalTime /= 1.2f;
            }
            yield return(new WaitForSeconds(intervalTime));

            if (m_EMFSM.AvailableChildNum < 100)
            {
                bCanSpawn = true;
            }
        }
    }
Ejemplo n.º 5
0
 // Update nutrient factor
 void NutrientDiffUpdate()
 {
     // Max fNutrientDiff = 1f + fMaxNutrientInfluence
     if (EMController.Instance().NutrientNum != 0)
     {
         fNutrientDiff = 1f + fMaxNutrientInfluence / Mathf.Sqrt(Mathf.Sqrt((float)nCurrentNutrient) * 2f) / Mathf.Sqrt(Mathf.Sqrt((2f)));
     }
 }
Ejemplo n.º 6
0
    public override void Enter()
    {
        // Reset transition availability
        EMTransition.Instance().CanTransit = true;
        // Reset spawn availability

        // Pause the transition for randomized time based on num of available nutrient
        float fPauseTime = Random.Range(Mathf.Sqrt(Mathf.Sqrt(EMController.Instance().NutrientNum + 1f) * 2f) / EMDifficulty.Instance().CurrentDiff,
                                        Mathf.Sqrt(Mathf.Sqrt(EMController.Instance().NutrientNum + 1f) * 10f) / EMDifficulty.Instance().CurrentDiff);

        helper.StartPauseTransition(fPauseTime);
    }
Ejemplo n.º 7
0
 void Update()
 {
     // Update enemy main cell's position
     if (EMHelper.Instance() != null)
     {
         targetPosition = EMHelper.Instance().Position;
     }
     // Update seek weight
     if (fSeekWeight != .24f / Mathf.Sqrt(Mathf.Sqrt(Mathf.Sqrt(EMController.Instance().NutrientNum + 50f))))
     {
         fSeekWeight = .24f / Mathf.Sqrt(Mathf.Sqrt(Mathf.Sqrt(EMController.Instance().NutrientNum + 50f)));
     }
 }
Ejemplo n.º 8
0
 void Start()
 {
     // Initialization
     fFlockWeight = 1f;
     // Number behind makes sure the seek weight is so small that the nutrient never mve away from the main cell
     fSeekWeight       = .24f / Mathf.Sqrt(Mathf.Sqrt(Mathf.Sqrt((float)EMController.Instance().NutrientNum + 50f)));
     fNeighbourRadius  = 1f;
     fAlignmentWeight  = .6f;
     fCohesionWeigth   = .6f;
     fSeperationWeight = .8f;
     // Add this behavior to the agent
     agent = GetComponent <EMNutrientMainAgent>();
     agent.AddBehaviour(this);
 }
Ejemplo n.º 9
0
    // Make sure the enemy main cell do not go outside the screen
    void PositionLimit()
    {
        if (transform.position.x <= EMHelper.leftLimit + width || transform.position.x >= EMHelper.rightLimit - width)
        {
            // Make sure the enemy main cell is cannot go out of the camera
            if (transform.position.x < EMHelper.leftLimit + width)
            {
                transform.position = new Vector2(EMHelper.leftLimit + width, transform.position.y);
            }
            else if (transform.position.x > EMHelper.rightLimit - width)
            {
                transform.position = new Vector2(EMHelper.rightLimit - width, transform.position.y);
            }

            EMController.Instance().ChangeDirection();
        }

        if (transform.position.y < Constants.s_fEnemyMainMinY)
        {
            transform.position = new Vector2(transform.position.x, Constants.s_fEnemyMainMinY);
        }
    }
Ejemplo n.º 10
0
 void Update()
 {
     #region Update of health and num of nutrient, and difficulty factors
     if (EnemyMainFSM.Instance() != null)
     {
         // Health Update
         if (nCurrentHealth != EnemyMainFSM.Instance().Health)
         {
             nCurrentHealth = EnemyMainFSM.Instance().Health;
         }
         // Nutrient Update
         if (nCurrentNutrient != EMController.Instance().NutrientNum)
         {
             nCurrentNutrient = EMController.Instance().NutrientNum;
         }
         HealthDiffUpdate();
         NutrientDiffUpdate();
         LevelDiffUpdate();
     }
     #endregion
     // Update current difficulty
     CurrentDiffUpdate();
 }