Example #1
0
    void OnCollisionEnter2D(Collision2D col)
    {
        //si es que el enemigo ejecuta daño a Joe a este se le reducira la vida
        if (col.gameObject.tag == "Enemy" || col.gameObject.tag == "EnemigoVolador" && vidajoe > 0)
        {
            enemigo       = col.gameObject;
            scriptenemigo = enemigo.GetComponent <Enemigo>();
            au.clip       = efectos[0];
            au.Play();
            anim.SetTrigger("daño");

            Physics2D.IgnoreLayerCollision(0, 0);
            sprite.color = new Color(1f, 1f, 1f, .5f);


            if (sprite.flipX == false)
            {
                rigid.AddForce(new Vector2(-16f, 6f), ForceMode2D.Impulse);
            }
            else
            {
                rigid.AddForce(new Vector2(16f, 6f), ForceMode2D.Impulse);
            }

            if (scriptenemigo != null)
            {
                vidajoe -= scriptenemigo.getdaño();
            }
        }
        //la barra de vida será reducida según el daño
        if (col.gameObject.tag == "Barrera" && vidajoe > 0)
        {
            barrera       = col.gameObject;
            barreramuerte = barrera.GetComponent <Barrera>();
            vidajoe      -= barreramuerte.getdaño();
        }

        if (col.gameObject.name == "Proyectil(Clone)")
        {
            GameObject proyectil       = col.gameObject;
            Proyectil  scriptproyectil = proyectil.GetComponent <Proyectil>();
            vidajoe -= scriptproyectil.getdaño();
        }

        if (col.gameObject.name == "Hueso")
        {
            GameObject    proyectil = col.gameObject;
            VidaJefeFinal script    = proyectil.GetComponentInParent <VidaJefeFinal>();
            vidajoe -= script.getDañoHueso();
        }
    }
Example #2
0
    public void UsarHabilidad(int index)
    {
        switch (index)
        {
        case 0:
            GameObject p = GameObject.FindWithTag("Player");
            Component  c = p.GetComponent <Berserk>();
            c = p.AddComponent(typeof(Berserk));


            break;

        case 1:
            GameObject a  = GameObject.FindWithTag("Player");
            Component  co = a.GetComponent <Barrido>();
            co = a.AddComponent(typeof(Barrido));

            if (barrDisponible = true && Tespera >= tiempoMaximoEsperaBarrido)
            {
                player.ShotBarrido();
                barrDisponible = false;
                Tespera        = 0f;
            }

            if (Tespera <= tiempoMaximoEsperaBarrido)
            {
                barrDisponible = true;
            }



            break;

        case 2:
            GameObject b   = GameObject.FindWithTag("Player");
            Component  com = b.GetComponent <Barrera>();
            com = b.AddComponent(typeof(Barrera));
            Barrera defensa = GetComponent <Barrera>();
            player.ActivarBarrera();

            break;

        default:
            break;
        }
    }
        private void Tick()
        {
            Debug.Print("N1: Entrando a Tick()...\n" +
                        "Fase de h: " + h.Fase + "\n");

            //aumentar ciclos
            h.Ciclos++;

            //tabla
            if (h.Fase == Hilillo.FaseDeHilillo.V)
            {
                lock (ColaHilillos)
                {
                    if (ColaHilillos.Count != 0)
                    {
                        h         = ColaHilillos.Dequeue();
                        h.Fase    = Hilillo.FaseDeHilillo.L;
                        h.Quantum = this.Quantum;
                        Terminado = false;
                    }
                    else
                    {
                        Terminado = true;
                    }
                }
            }
            else if (h.Fase == Hilillo.FaseDeHilillo.Exec)
            {
                h.Quantum--; //reducir quantum

                if (h.Quantum == 0)
                {
                    lock (ColaHilillos)
                    {
                        ColaHilillos.Enqueue(h);
                        h         = ColaHilillos.Dequeue();
                        h.Quantum = this.Quantum;
                    }
                }

                h.Fase = Hilillo.FaseDeHilillo.L;
            }
            else if (h.Fase == Hilillo.FaseDeHilillo.Fin)
            {
                lock (HilillosFinalizados)
                {
                    HilillosFinalizados.Add(h);
                }
                lock (ColaHilillos)
                {
                    if (ColaHilillos.Count == 0)
                    {
                        h = Hilillo.HililloVacio;
                    }
                    else
                    {
                        h         = ColaHilillos.Dequeue();
                        h.Fase    = Hilillo.FaseDeHilillo.L;
                        h.Quantum = this.Quantum;
                    }
                }
            }

            //barrera
            Barrera.SignalAndWait();
        }
Example #4
0
        private void Tick()
        {
            Debug.Print("N0: Entrando a Tick()...\n" +
                        "Fase de h[0]: " + h[0].Fase + "\n" +
                        "Fase de h[1]: " + h[1].Fase + "\n");

            //aumentar ciclos
            h[0].Ciclos++;
            h[1].Ciclos++;

            //reducir quantums
            if (h[0].Fase == Hilillo.FaseDeHilillo.Exec)
            {
                h[0].Quantum--;
            }
            if (h[1].Fase == Hilillo.FaseDeHilillo.Exec)
            {
                h[1].Quantum--;
            }

            //tabla
            Debug.Assert(!(h[1].Fase == Hilillo.FaseDeHilillo.V && h[0].Fase == Hilillo.FaseDeHilillo.L));
            Debug.Assert(!(h[1].Fase == Hilillo.FaseDeHilillo.L && h[0].Fase == Hilillo.FaseDeHilillo.V));
            Debug.Assert(!(h[1].Fase == Hilillo.FaseDeHilillo.L && h[0].Fase == Hilillo.FaseDeHilillo.L));
            Debug.Assert(!(h[1].Fase == Hilillo.FaseDeHilillo.FI && h[0].Fase == Hilillo.FaseDeHilillo.FI));
            Debug.Assert(!(h[1].Fase == Hilillo.FaseDeHilillo.IR && h[0].Fase == Hilillo.FaseDeHilillo.IR));
            Debug.Assert(!(h[1].Fase == Hilillo.FaseDeHilillo.FD && h[0].Fase == Hilillo.FaseDeHilillo.L));
            Debug.Assert(!(h[1].Fase == Hilillo.FaseDeHilillo.FD && h[0].Fase == Hilillo.FaseDeHilillo.FD));
            Debug.Assert(!(h[1].Fase == Hilillo.FaseDeHilillo.Exec && h[1].Quantum > 0 && h[0].Fase == Hilillo.FaseDeHilillo.L));
            Debug.Assert(!(h[1].Quantum == 0 && h[0].Fase == Hilillo.FaseDeHilillo.L));
            Debug.Assert(!(h[1].Fase == Hilillo.FaseDeHilillo.Fin && h[0].Fase == Hilillo.FaseDeHilillo.L));
            Debug.Assert(!(h[1].Fase == Hilillo.FaseDeHilillo.Fin && h[0].Fase == Hilillo.FaseDeHilillo.Fin));
            if ((h[0].Fase == Hilillo.FaseDeHilillo.FI ||
                 h[0].Fase == Hilillo.FaseDeHilillo.FD) &&
                h[1].Fase == Hilillo.FaseDeHilillo.V)
            { // H0: V && H1: FI|FD
                lock (ColaHilillos)
                {
                    if (ColaHilillos.Count != 0)
                    {
                        h[1]         = ColaHilillos.Dequeue();
                        h[1].Fase    = Hilillo.FaseDeHilillo.L;
                        h[1].Quantum = this.Quantum;
                    }
                }
            }
            else if (h[0].Fase == Hilillo.FaseDeHilillo.Exec)
            { // H0: Exec - Mayor riesgo de fracasar
                if (h[1].Fase == Hilillo.FaseDeHilillo.Exec && h[1].Quantum > 0)
                {
                    h[1].Fase = Hilillo.FaseDeHilillo.L;
                }
                else if (h[1].Fase == Hilillo.FaseDeHilillo.Exec && h[1].Quantum == 0)
                {
                    lock (ColaHilillos)
                    {
                        ColaHilillos.Enqueue(h[1]);
                    }
                    h[1] = Hilillo.HililloVacio;
                }
                else if (h[1].Fase == Hilillo.FaseDeHilillo.Fin)
                {
                    lock (HilillosFinalizados)
                    {
                        HilillosFinalizados.Add(h[1]);
                    }
                    h[1] = Hilillo.HililloVacio;
                }

                //solo cuando q==0
                if (h[0].Quantum == 0)
                {
                    lock (ColaHilillos)
                    {
                        ColaHilillos.Enqueue(h[0]);
                        h[0] = ColaHilillos.Dequeue();
                    }
                    h[0].Quantum = this.Quantum;
                }

                //común
                h[0].Fase = Hilillo.FaseDeHilillo.L;
            }
            else if (h[0].Fase == Hilillo.FaseDeHilillo.Fin)
            { // H0: Fin - Riesgo de fracasar
                lock (HilillosFinalizados)
                {
                    HilillosFinalizados.Add(h[0]);
                }

                if (h[1].Fase == Hilillo.FaseDeHilillo.Exec && h[1].Quantum > 0)
                {
                    h[1].Fase = Hilillo.FaseDeHilillo.L;
                }
                else if (h[1].Fase == Hilillo.FaseDeHilillo.Exec && h[1].Quantum == 0)
                {
                    lock (ColaHilillos)
                    {
                        ColaHilillos.Enqueue(h[1]);
                        h[0]         = ColaHilillos.Dequeue();
                        h[0].Fase    = Hilillo.FaseDeHilillo.L;
                        h[0].Quantum = this.Quantum;
                    }
                    h[1] = Hilillo.HililloVacio;
                    goto salida;
                }

                //común
                lock (ColaHilillos)
                {
                    if (ColaHilillos.Count == 0)
                    {
                        h[0] = Hilillo.HililloVacio;
                    }
                    else
                    {
                        h[0]         = ColaHilillos.Dequeue();
                        h[0].Fase    = Hilillo.FaseDeHilillo.L;
                        h[0].Quantum = this.Quantum;
                    }
                }
            }
            else if (h[1].Fase == Hilillo.FaseDeHilillo.Exec && h[1].Quantum > 0)
            { //H1: Exec, q > 0 && H0: V|L|FI|IR|FD
                h[1].Fase = Hilillo.FaseDeHilillo.L;
            }
            else if (h[1].Fase == Hilillo.FaseDeHilillo.Exec && h[1].Quantum == 0)
            { //H1: Exec, q == 0 && H0: V|L|FI|IR|FD
                if (h[0].Fase == Hilillo.FaseDeHilillo.V)
                {
                    lock (ColaHilillos)
                    {
                        ColaHilillos.Enqueue(h[1]);
                        h[1]         = Hilillo.HililloVacio;
                        h[0]         = ColaHilillos.Dequeue();
                        h[0].Fase    = Hilillo.FaseDeHilillo.L;
                        h[0].Quantum = this.Quantum;
                    }
                }
                else if (h[0].Fase == Hilillo.FaseDeHilillo.L ||
                         h[0].Fase == Hilillo.FaseDeHilillo.IR)
                {
                    lock (ColaHilillos)
                    {
                        ColaHilillos.Enqueue(h[1]);
                    }
                    h[1] = Hilillo.HililloVacio;
                }
                else if (h[0].Fase == Hilillo.FaseDeHilillo.FI ||
                         h[0].Fase == Hilillo.FaseDeHilillo.FD)
                {
                    lock (ColaHilillos)
                    {
                        ColaHilillos.Enqueue(h[1]);
                        h[1] = ColaHilillos.Dequeue();
                    }
                    h[1].Fase    = Hilillo.FaseDeHilillo.L;
                    h[1].Quantum = this.Quantum;
                }
            }
            else if (h[1].Fase == Hilillo.FaseDeHilillo.Fin)
            { //H1: Fin && H0: V|L|FI|IR|FD
                lock (HilillosFinalizados)
                {
                    HilillosFinalizados.Add(h[1]);
                }

                if (h[0].Fase == Hilillo.FaseDeHilillo.V)
                {
                    lock (ColaHilillos)
                    {
                        if (ColaHilillos.Count == 0)
                        {
                            h[0] = Hilillo.HililloVacio;
                        }
                        else
                        {
                            h[0]         = ColaHilillos.Dequeue();
                            h[0].Fase    = Hilillo.FaseDeHilillo.L;
                            h[0].Quantum = this.Quantum;
                        }
                    }
                    h[1] = Hilillo.HililloVacio;
                }
                if (h[0].Fase == Hilillo.FaseDeHilillo.IR)
                {
                    h[1] = Hilillo.HililloVacio;
                }
                else if (h[0].Fase == Hilillo.FaseDeHilillo.FI ||
                         h[0].Fase == Hilillo.FaseDeHilillo.FD)
                {
                    lock (ColaHilillos)
                    {
                        if (ColaHilillos.Count == 0)
                        {
                            h[1] = Hilillo.HililloVacio;
                        }
                        else
                        {
                            h[1]         = ColaHilillos.Dequeue();
                            h[1].Fase    = Hilillo.FaseDeHilillo.L;
                            h[1].Quantum = this.Quantum;
                        }
                    }
                }
            }
            else if (h[0].Fase == Hilillo.FaseDeHilillo.V && h[1].Fase == Hilillo.FaseDeHilillo.V)
            {
                Terminado = true;
            }

salida:

            //barrera
            Barrera.SignalAndWait();
        }