Пример #1
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);
    }
Пример #2
0
    //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);
    }
Пример #3
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);
    }