Example #1
0
    private void OnTriggerEnter(Collider collision)
    {
        if (isWinned || isLoosed)
        {
            return;
        }

        if (collision.gameObject.CompareTag(GameData.Layers.Cucaracha.ToString()))
        {
            CucarachaController cuca = collision.gameObject.GetComponent <CucarachaController>();
            if (!cuca)
            {
                cuca = collision.transform.parent.GetComponent <CucarachaController>();
            }

            if (cuca.IsDying)
            {
                return;
            }
            animator.SetTrigger("RoachCollision");
            CameraShake.Shake(0.1f, 0.05f);

            CucarachaManager.Instance.AddJuice();
            ChangeSlider();
            source.volume = .6f;

            Debug.Log("Juice quantity : " + CucarachaManager.Instance.GetJuice());

            cuca.Kill(false);
        }
    }
Example #2
0
    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.CompareTag(GameData.Layers.Cucaracha.ToString()) && realLifeFood >= 0)
        {
            CucarachaController cuca = other.gameObject.GetComponent <CucarachaController>();
            if (!cuca)
            {
                cuca = other.gameObject.transform.parent.GetComponent <CucarachaController>();
            }

            //GameData
            if (cuca.Eat())
            {
                soundVolume = .5f;
                realLifeFood--;
                if (Random.Range(0, 10) < 1)
                {
                    GameObject bump = ObjectsPooler.Instance.SpawnFromPool(GameData.PoolTag.Bump, transform.position, Quaternion.identity, ObjectsPooler.Instance.transform);
                }

                //Debug.Log("life food : " + realLifeFood);
            }

            if (realLifeFood <= 0)
            {
                realLifeFood = 0;
                Kill();
            }
        }
    }
 public void AddCucaracha(CucarachaController cuca)
 {
     if (!cucarachas.Contains(cuca))
     {
         cucarachas.Add(cuca);
     }
 }
 public void ChangeDirectionCuca()
 {
     for (int i = 0; i < cucarachas.Count; i++)
     {
         CucarachaController cuca = cucarachas[i];
         //cuca.GetIA().
         Vector2 dir = new Vector2(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f));
         cuca.ChangeDirectionIA(dir);
     }
 }
Example #5
0
 /// <summary>
 /// when cuca exit the food (OR FOOD is destroyed ??)
 /// </summary>
 private void OnTriggerExit(Collider other)
 {
     if (other.gameObject.CompareTag(GameData.Layers.Cucaracha.ToString()))
     {
         CucarachaController cuca = other.gameObject.GetComponent <CucarachaController>();
         if (cuca == null)
         {
             cuca = other.transform.parent.GetComponent <CucarachaController>();
         }
         cuca.SetInsideFood(false, null);
         cucaInside.Remove(cuca);
     }
 }
Example #6
0
    private void OnTriggerEnter(Collider collision)
    {
        if (collision.gameObject.CompareTag(GameData.Layers.Cucaracha.ToString()))
        {
            CucarachaController cuca = collision.gameObject.GetComponent <CucarachaController>();
            if (!cuca)
            {
                cuca = collision.transform.parent.GetComponent <CucarachaController>();
            }

            //Debug.Log("Cucaracha is dead with Trap");

            cuca.Kill();
        }
    }
Example #7
0
 private void OnTriggerStay(Collider other)
 {
     if (other.gameObject.CompareTag(GameData.Layers.Cucaracha.ToString()) && lightOn)
     {
         CucarachaController cuca = other.gameObject.GetComponent <CucarachaController>();
         if (cuca == null)
         {
             cuca = other.transform.parent.GetComponent <CucarachaController>();
         }
         cuca.SetInsideLamp(true, this);
         if (!cucaInside.Contains(cuca))
         {
             cucaInside.Add(cuca);
         }
     }
 }
Example #8
0
    private void OnTriggerStay(Collider other)
    {
        if (other.gameObject.CompareTag(GameData.Layers.Cucaracha.ToString()))
        {
            CucarachaController cuca = other.gameObject.GetComponentInParent <CucarachaController>();
            if (cuca == null)
            {
                cuca = other.transform.parent.GetComponent <CucarachaController>();
            }

            if (cuca.isInsideFood)
            {
                return;
            }

            //if ()
            //Debug.Log("Cucaracha follow the food");
            cuca.SetInsideFood(true, this);
            if (!cucaInside.Contains(cuca))
            {
                cucaInside.Add(cuca);
            }
        }
    }
Example #9
0
    /// <summary>
    /// STATE MACHINE FOR CUCA AI
    /// </summary>
    public void Machine()
    {
        List <CucarachaController> cucarachas = CucarachaManager.Instance.GetCurarachaList();


        Food    foodInfo;
        Lamp    lightInfo;
        Vector3 vectDir;
        Vector2 stopVect;
        int     count = 0;
        int     state;
        float   x, y;



        for (int i = 0; i < cucarachas.Count; i++)
        {
            CucarachaController cuca = cucarachas[i];
            state = cuca.GetIA().State;

            int randInt = 0;

            if (cuca.IsDying)
            {
                continue;
            }

            switch (state)
            {
            // IDLE
            //===---
            case 0:             //Don't move
            {
                stopVect = new Vector2(cuca.rb.transform.forward.x, cuca.rb.transform.forward.z);
                cuca.ChangeDirectionIA(new Vector2(stopVect.x * 0.0001f, stopVect.y * 0.0001f));

                if (cuca.isInsideLight)
                {
                    state = 4;
                    break;
                }
                else if (cuca.isInsideFood)
                {
                    state = 2;
                    break;
                }
                else
                {
                    randInt = Random.Range(0, 5);

                    if (randInt == 1)
                    {
                        state = 1;
                        break;
                    }
                }
                break;
            }

            case 1:             //Crawl
            {
                stopVect = new Vector2(cuca.rb.transform.forward.x, cuca.rb.transform.forward.z);
                x        = generateNormalRandom(0.0f, 0.5f);
                y        = generateNormalRandom(0.0f, 0.5f);



                if (Random.Range(0, 100) == 1)
                {
                    cuca.ChangeDirectionIA(new Vector2(stopVect.x + x + 5.0f, stopVect.y + y + 5.0f));
                }
                else
                {
                    cuca.ChangeDirectionIA(new Vector2(stopVect.x + x, stopVect.y + y));
                }

                if (cuca.isInsideLight)
                {
                    state = 4;
                    break;
                }
                else if (cuca.isInsideFood)
                {
                    state = 2;
                    break;
                }

                state = 0;
                break;
            }
            //===---

            // FOOD
            case 2:                        // Forward food
            {
                foodInfo = cuca.GetFood(); //Get food info
                if (!foodInfo)
                {
                    state = 0;
                    break;
                }


                vectDir = -(cuca.rb.transform.position - foodInfo.transform.position);         // Create vector for direction
                vectDir.Normalize();

                cuca.ChangeDirectionIA(new Vector2(vectDir.x * foodInfo.weight, vectDir.z * foodInfo.weight));         // change dir

                if (cuca.isInsideLight)
                {
                    state = 4;
                    break;
                }
                else if (!cuca.isInsideFood)
                {
                    state = 0;
                    break;
                }
                else
                {
                    randInt = Random.Range(0, 2);
                    if (randInt == 1)
                    {
                        state = 3;
                        break;
                    }
                }
                break;
            }

            case 3:     // Forward food with variations in direction
            {
                foodInfo = cuca.GetFood();
                if (!foodInfo)
                {
                    state = 0;
                    break;
                }

                vectDir = -(cuca.rb.transform.position - foodInfo.transform.position);
                vectDir.Normalize();
                x = generateNormalRandom(0.0f, 0.3f);
                y = generateNormalRandom(0.0f, 0.3f);

                cuca.ChangeDirectionIA(new Vector2((vectDir.x + x) * foodInfo.weight, (vectDir.y + y) * foodInfo.weight));

                if (cuca.isInsideLight)
                {
                    state = 4;
                    break;
                }
                else if (!cuca.isInsideFood)
                {
                    state = 0;
                    break;
                }
                else
                {
                    state = 2;
                    break;
                }
            }

            //======-----


            // LIGHT
            //===---
            case 4:      // Flee the light
            {
                lightInfo = cuca.GetLamp();
                if (!lightInfo)
                {
                    state = 0;
                    break;
                }

                vectDir = (cuca.rb.transform.position - lightInfo.transform.position);
                vectDir.Normalize();

                cuca.ChangeDirectionIA(new Vector2(vectDir.x * lightInfo.weight, vectDir.z * lightInfo.weight));


                if (!cuca.isInsideLight && cuca.isInsideFood)
                {
                    state = 2;
                    break;
                }
                else if (!cuca.isInsideLight && !cuca.isInsideFood)
                {
                    state = 6;
                    break;
                }
                else
                {
                    randInt = Random.Range(0, 2);
                    if (randInt == 1)
                    {
                        state = 5;
                        break;
                    }
                }
                break;
            }

            case 5:     // Flee the light but with variations
            {
                lightInfo = cuca.GetLamp();
                if (!lightInfo)
                {
                    state = 0;
                    break;
                }
                vectDir = (cuca.rb.transform.position - lightInfo.transform.position);
                vectDir.Normalize();
                x = generateNormalRandom(0.0f, 0.5f);
                y = generateNormalRandom(0.0f, 0.5f);

                cuca.ChangeDirectionIA(new Vector2((vectDir.x + x) * lightInfo.weight, (vectDir.y + y) * lightInfo.weight));

                if (!cuca.isInsideLight && cuca.isInsideFood)
                {
                    state = 2;
                    break;
                }
                else if (!cuca.isInsideLight && !cuca.isInsideFood)
                {
                    state = 6;
                    break;
                }
                else
                {
                    state = 4;
                    break;
                }
            }

            case 6:     // Keep the direction for one more step to be sure to not stay near the light
            {
                if (count <= 5)
                {
                    count++;

                    break;
                }
                else
                {
                    count = 0;
                    state = 0;
                    break;
                }
            }
                //====----
            }

            cuca.GetIA().State = state;
        }
    }
Example #10
0
 public void RemoveCuca(CucarachaController cuca)
 {
     cucarachas.Remove(cuca);
 }