Esempio n. 1
0
    public IEstadoHormiga Update(Hormiga h)
    {
        Collider closestEnemy = null;

        //Recorre los objetivos en su vision y se queda con el mas cercano
        foreach (Collider col in h.sonarList)
        {
            if (col != null)
            {
                if (closestEnemy == null)
                {
                    closestEnemy = col;
                }
                else
                {
                    if (Vector3.Distance(col.transform.position, h.transform.position) < Vector3.Distance(closestEnemy.transform.position, h.transform.position))
                    {
                        closestEnemy = col;
                    }
                }
            }
        }

        //Si ha encontrado un enemigo lo ataca
        if (closestEnemy != null)
        {
            h.ePerseguir.target = closestEnemy.transform;
            return(h.ePerseguir);
        }
        else
        {
            return(h.eRandom);
        }
    }
Esempio n. 2
0
    //Atacar solo si ha pasado 1s desde el anterior ataque
    public IEstadoHormiga Update(Hormiga h)
    {
        //Si el objetivo esta muerto vamos al estado de muerte, ya que la hormiga ya ha comenzado su ataque suicida aunque no haga daño a ningun enemigo
        if (target == null)
        {
            return(h.eMuerta);
        }

        //Comprobamos que tipo de enemigo es para hacerle daño correctamente
        if (target.gameObject.CompareTag("Gallina"))
        {
            Gallina g = target.gameObject.GetComponent <Gallina>();
            g.GetHit(h.fuerza);
        }

        if (target.gameObject.CompareTag("Pulpo"))
        {
            Octopus o = target.gameObject.GetComponent <Octopus>();
            o.GetHit(h.fuerza);
        }

        if (target.gameObject.CompareTag("TRex"))
        {
            TRex t = target.gameObject.GetComponent <TRex>();
            t.GetHit(h.fuerza);
        }

        return(h.eMuerta);
    }
    //Atacar solo si ha pasado 1s desde el anterior ataque
    public IEstadoGallina Update(Gallina g)
    {
        if (Time.time - time > 1)
        {
            time = Time.time;

            //Si el objetivo esta muerto volvemos a buscar
            if (target == null)
            {
                return(g.eBuscar);
            }

            //Comprobamos que tipo de enemigo es para hacerle daño correctamente
            if (target.gameObject.CompareTag("Hormiga"))
            {
                Hormiga h = target.gameObject.GetComponent <Hormiga>();
                if (h == null)
                {
                    HormigaReina hr = target.gameObject.GetComponent <HormigaReina>();
                    hr.GetHit(g.berserk ? g.fuerza * 3 : g.fuerza);
                }
                else
                {
                    h.GetHit();
                }
            }

            if (target.gameObject.CompareTag("Pulpo"))
            {
                Octopus o = target.gameObject.GetComponent <Octopus>();
                o.GetHit(g.berserk ? g.fuerza * 3 : g.fuerza);
            }

            if (target.gameObject.CompareTag("TRex"))
            {
                TRex t = target.gameObject.GetComponent <TRex>();
                t.GetHit(g.berserk ? g.fuerza * 3 : g.fuerza);
            }

            //Cada ataque reduce un poco la fuerza de la gallina
            if (g.fuerza > 10)
            {
                g.fuerza -= 1;
            }

            //Si el ataque acabo con su objetivo, la gallina se lo come para restaurar sus estadisticas
            if (target == null)
            {
                g.vida      = g.vidaInicial;
                g.fuerza    = g.fuerzaInicial;
                g.velocidad = g.velocidadInicial;
                g.berserk   = false;
            }
        }

        return(g.eAtacar);
    }
Esempio n. 4
0
    public IStatesTRex Update(TRex t)
    {
        //Calcula la fuerza en función del tamaño y de si hay aliados.
        force = Settings.tamTrex * 7.5f;
        if (t.grouped > 0)
        {
            force *= 2;
        }

        //Dependiendo del enemigo y de sus características ve si debe atacar o huir.
        if (t.enemy.gameObject.CompareTag("Pulpo"))
        {
            int rand = Random.Range((int)(force * 0.75f), (int)(force * 1.25f));
            if (rand < Settings.tamPulpos * 10)
            {
                return(t.runState);
            }
            else
            {
                return(t.attackState);
            }
        }
        else if (t.enemy.gameObject.CompareTag("Hormiga"))
        {
            Hormiga rival = t.enemy.GetComponent <Hormiga>();
            if (rival == null)
            {
                int rand = Random.Range((int)(force * 0.75f), (int)(force * 1.25f));
                if (rand < Settings.tamHormigas * 5)
                {
                    return(t.runState);
                }
                else
                {
                    return(t.attackState);
                }
            }
            else
            {
                return(t.attackState);
            }
        }
        else
        {
            int rand = Random.Range((int)(force * 0.75f), (int)(force * 1.25f));
            if (rand < Settings.tamGallinas)
            {
                return(t.runState);
            }
            else
            {
                return(t.attackState);
            }
        }
    }
 public IEstadoHormiga Update(Hormiga h)
 {
     //Si la hormiga esta viva reaparecer en ella. De lo contrario, morir.
     if (h.reinaViva)
     {
         h.nma.Warp(h.reina.position - h.reina.forward * 2 * Settings.tamHormigas);
         return(h.eBuscar);
     }
     else
     {
         Object.DestroyImmediate(h.gameObject);
         return(h.eMuerta);
     }
 }
    public IEstadoHormiga Update(Hormiga h)
    {
        //Espera hasta que pasan 2 segundos. Despues realiza un movimiento aleatorio
        if (isWaiting)
        {
            if (Time.time - time > 2)
            {
                isWaiting = false;
            }
        }
        else
        {
            h.nma.destination = h.transform.position + new Vector3((Random.value - 0.5f) * 4, (Random.value - 0.5f) * 4, (Random.value - 0.5f) * 4);

            time      = Time.time;
            isWaiting = true;
        }

        return(h.eBuscar);
    }
Esempio n. 7
0
    void Start()
    {
        HormigaReina hr = Instantiate(hormigaReinaPrefab).GetComponent <HormigaReina>();

        hr.transform.parent   = transform;
        hr.transform.position = transform.position;

        Hormiga[] hormigas = new Hormiga[Settings.numHormigas];

        for (int i = 0; i < hormigas.Length; i++)
        {
            hormigas[i] = Instantiate(hormigaPrefab).GetComponent <Hormiga>();
            hormigas[i].transform.parent   = transform;
            hormigas[i].transform.position = transform.position;

            hormigas[i].reina     = hr.transform;
            hormigas[i].reinaViva = true;
        }

        hr.hormigas = hormigas;
    }
Esempio n. 8
0
    public IEstadoHormiga Update(Hormiga h)
    {
        //Si ha muerto el objetivo, volver a buscar
        if (target == null)
        {
            return(h.eBuscar);
        }

        //Mientras no estamos cerca mantener el objetivo
        if (!colision)
        {
            h.nma.destination = target.position;
            return(h.ePerseguir);
        }
        else
        {
            //Si se alcanza al objetivo se le ataca
            h.eAtacar.target = target;
            colision         = false;
            target           = null;
            return(h.eAtacar);
        }
    }
Esempio n. 9
0
    public IStatesTRex Update(TRex t)
    {
        //Si el enemigo desaparece, el TRex vaga.
        if (t.enemy == null)
        {
            return(t.wanderState);
        }

        t.agent.speed = attackSpeed;
        force         = Settings.tamTrex * 20;

        //Si no hay colisión, sigue persiguiendo.
        if (!colision)
        {
            t.agent.isStopped = false;
            if (t.enemy == null)
            {
                return(t.wanderState);
            }
            else
            {
                t.agent.destination = t.enemy.transform.position;
                return(t.attackState);
            }

            //Si hay colisión, ataca.
        }
        else
        {
            colision = false;

            if (Time.time - time > 1f)
            {
                time = Time.time;

                //Se para.
                t.agent.isStopped = true;

                //Si es un pulpo, ataca hasta morir o matar, si lo mata puede comer.
                if (t.enemy.gameObject.CompareTag("Pulpo"))
                {
                    Octopus rival = t.enemy.GetComponent <Octopus>();
                    rival.GetHit((int)force);
                    if (t.enemy == null)
                    {
                        t.health += 20;
                    }

                    //Si es una hormiga, ataca hasta matar o morir.
                }
                else if (t.enemy.gameObject.CompareTag("Hormiga"))
                {
                    Hormiga rival = t.enemy.GetComponent <Hormiga>();
                    if (rival == null)
                    {
                        HormigaReina rivalHR = t.enemy.GetComponent <HormigaReina>();
                        rivalHR.GetHit((int)force);
                    }
                    else
                    {
                        rival.GetHit();
                    }

                    //Si es una gallina, ataca hasta morir o matar, si lo mata puede comer.
                }
                else if (t.enemy.gameObject.CompareTag("Gallina"))
                {
                    Gallina rival = t.enemy.GetComponent <Gallina>();
                    rival.GetHit((int)force);
                    if (t.enemy == null)
                    {
                        t.health += 20;
                    }
                }
            }
        }

        return(t.attackState);
    }
Esempio n. 10
0
    public IStatesOctopus Update(Octopus o)
    {
        //Si no hay enemigo, vaga.
        if (o.enemy == null)
        {
            return(o.wanderState);
        }

        //Si está en el agua, es más rápido y más fuerte.
        if (o.water)
        {
            force         = Settings.tamPulpos * 15f;
            o.agent.speed = speed * 2;
        }
        else
        {
            //Si su vida es baja, huye.
            if (o.health < Settings.tamPulpos * 15)
            {
                return(o.runState);
            }

            force         = Settings.tamPulpos * 5f;
            o.agent.speed = speed;
        }

        //Si no hay colisión, sigue persiguiendo.
        if (!colision)
        {
            o.agent.isStopped = false;
            if (o.enemy == null)
            {
                return(o.wanderState);
            }
            else
            {
                o.agent.destination = o.enemy.transform.position;
                return(o.attackState);
            }

            //Si la hay, ataca.
        }
        else
        {
            colision = false;
            if (Time.time - time > 1f)
            {
                time = Time.time;

                //Se para.
                o.agent.isStopped = true;

                //Llama a las funciones de recibir daño del rival.
                if (o.enemy.gameObject.CompareTag("TRex"))
                {
                    TRex rival = o.enemy.GetComponent <TRex>();
                    rival.GetHit((int)force);
                }
                else if (o.enemy.gameObject.CompareTag("Hormiga"))
                {
                    Hormiga rival = o.enemy.GetComponent <Hormiga>();
                    if (rival == null)
                    {
                        HormigaReina rivalHR = o.enemy.GetComponent <HormigaReina>();
                        rivalHR.GetHit((int)force);
                    }
                    else
                    {
                        rival.GetHit();
                    }
                }
                else if (o.enemy.gameObject.CompareTag("Gallina"))
                {
                    Gallina rival = o.enemy.GetComponent <Gallina>();
                    rival.GetHit((int)force);
                }
            }
        }

        return(o.attackState);
    }