Exemple #1
0
 public void QuitarVida(int danyo)
 {
     salud -= danyo;
     if (salud <= 0)
     {
         vidas--;
         uiScript.RestarVida();
         salud = saludMaxima;
     }
     if (estado == EstadoPlayer.AndandoDer)
     {
         print("aplicando fuerza 1");
         estado = EstadoPlayer.Sufriendo;
         GetComponent <Rigidbody2D>().transform.Translate(new Vector2(0, 0.1f));
         GetComponent <Rigidbody2D>().AddRelativeForce(new Vector2(-fuerzaImpactoX, fuerzaImpactoY), ForceMode2D.Impulse);
     }
     else if (estado == EstadoPlayer.AndandoIzq)
     {
         print("aplicando fuerza 2");
         estado = EstadoPlayer.Sufriendo;
         print(fuerzaImpactoX + ":" + fuerzaImpactoY);
         GetComponent <Rigidbody2D>().transform.Translate(new Vector2(0, 0.1f));
         GetComponent <Rigidbody2D>().AddRelativeForce(new Vector2(fuerzaImpactoX, fuerzaImpactoY), ForceMode2D.Impulse);
     }
     textSalud.text = salud.ToString();
 }
 public void CancelarPoder()
 {
     efectoPoder.SetActive(false);
     GetComponent <SpriteRenderer>().color = new Color(1, 1, 1);
     estadoPlayer  = EstadoPlayer.normal;
     poderActivado = false;
     DOTween.KillAll();
 }
Exemple #3
0
    void FixedUpdate()
    {
        float xPos         = Input.GetAxis("Horizontal");
        float ySpeedActual = rb2D.velocity.y;

        if (estado == EstadoPlayer.Sufriendo)
        {
            return;
        }

        if (Mathf.Abs(xPos) > 0.01f)
        {
            playerAnimator.SetBool("Andando", true);
        }
        else
        {
            playerAnimator.SetBool("Andando", false);
        }



        if (estado == EstadoPlayer.Saltando)
        {
            estado = EstadoPlayer.Pausa;
            if (EstaEnElSuelo())
            {
                rb2D.velocity = new Vector2(xPos * speed, jumpForce);
            }
            else
            {
                rb2D.velocity = new Vector2(xPos * speed, ySpeedActual);
            }
        }
        else if (xPos > 0.01f)
        {
            {
                rb2D.velocity = new Vector2(xPos * speed, ySpeedActual);
                estado        = EstadoPlayer.AndandoDer;
            }
        }
        else if (xPos < -0.01f)
        {
            rb2D.velocity = new Vector2(xPos * speed, ySpeedActual);
            estado        = EstadoPlayer.AndandoIzq;
        }



        if (mirarFrente && xPos < -0.01)
        {
            CambiarOrientacion();
        }
        else if (!mirarFrente && xPos > 0.01)
        {
            CambiarOrientacion();
        }
    }
Exemple #4
0
    void FixedUpdate()
    {
        float xPos         = Input.GetAxis("Horizontal");
        float ySpeedActual = rb2D.velocity.y;

        if (estado == EstadoPlayer.Sufriendo)
        {
            return;
        }

        // Si sufre no puede hacer nada de esto
        if (Mathf.Abs(xPos) > 0.01f)
        {
            playerAnimator.SetBool("Andando", true);
        }
        else
        {
            playerAnimator.SetBool("Andando", false);
        }

        // Vamos a comprobar si el personaje esta en el suelo o en el aire
        if (estado == EstadoPlayer.Saltando)
        {
            estado = EstadoPlayer.Pausa;
            if (EstaEnSuelo())
            {
                rb2D.velocity = new Vector2(xPos * speed, jumpForce);
            }
            else
            {
                rb2D.velocity = new Vector2(xPos * speed, ySpeedActual);
            }
            // Nos movemos a la derecha
        }
        else if (xPos > 0.01f)
        {
            rb2D.velocity = new Vector2(xPos * speed, ySpeedActual);

            transform.localScale = new Vector2(1, 1);
            estado = EstadoPlayer.AndandoDer;
            // Nos movemos a la izquierda
        }
        else if (xPos < -0.01f)
        {
            rb2D.velocity = new Vector2(xPos * speed, ySpeedActual);

            transform.localScale = new Vector2(-1, 1);
            estado = EstadoPlayer.AndandoIzq;
        }
        else
        {
            estado = EstadoPlayer.Pausa;
        }
    }
Exemple #5
0
 private void Update()
 {
     if (Input.GetKey(KeyCode.Space))
     {
         estado = EstadoPlayer.Saltando;
     }
     if (estado == EstadoPlayer.Sufriendo && EstaEnElSuelo())
     {
         estado = EstadoPlayer.Pausa;
     }
 }
    private void Update()
    {
        // SI JUGAR ES FALSE SE ACABO EL JUEGO
        if (!jugar)
        {
            CancelInvoke("ContarSegundos");

            // MOSTRAMOS UNA IMAGEN DE GAMEOVER
            gameOver.GetComponent <Image>().enabled = true;
            // PARAMOS LAS ANIMACIONES
            GameControler.PararAnimaciones();

            // FINALIZAMOS EL JUEGO
            Invoke("FinalizarJuego", 2);
        }

        // SI ESTA SALTANDO
        if (Input.GetKeyDown(KeyCode.Space))
        {
            estado = EstadoPlayer.Saltando;
        }

        if (Input.GetKeyDown(KeyCode.Z) && estado != EstadoPlayer.Pausa)
        {
            // APARECE EL CARAMELO
            GameObject bala = Instantiate(prefabBala,
                                          puntoGeneracionBala.transform.position,
                                          puntoGeneracionBala.transform.rotation);
            // SI EL PLAYER ESTA MIRANDO HACIA LA DERECHA LA BALA SALDRA
            // A LA DERECHA O A LA IZQUIERDA SI ESTA MIRANDO A LA IZQUIERDA
            if (estado == EstadoPlayer.AndandoDerecha)
            {
                // PARA HACER LA FUERZA CON RESPECTO AL MUNDO
                bala.GetComponent <Rigidbody2D>().AddRelativeForce(Vector2.right * potenciaDisparo);
                bala.GetComponent <AudioSource>().Play();
            }
            else if (estado == EstadoPlayer.AndandoIzquierda)
            {
                // PARA HACER LA FUERZA CON RESPECTO AL MUNDO
                bala.GetComponent <Rigidbody2D>().AddRelativeForce(Vector2.left * potenciaDisparo);
                bala.GetComponent <AudioSource>().Play();
            }
            else
            {
                // print(estado);
            }
        }
        // SI ESTA SUFRIENDO Y ESTA EN EL SUELO LO DEJAMOS EN PAUSA
        if (estado == EstadoPlayer.Sufriendo && EstaEnElSuelo())
        {
            // DEJAMOS EL ESTADO A PAUSA PARA QUE VUELVA ACTIVAR LAS FUERZAS
            estado = EstadoPlayer.Pausa;
        }
    }
Exemple #7
0
 public void RecibirDano(float dano)
 {
     if (gm.QuitarVida(dano))
     {
         IniciarPosicion();
         gm.ResetGame();
     }
     estadoPlayer = EstadoPlayer.recibiendoDano;
     animator.SetBool("recibiendoDano", true);
     Invoke("QuitarRecibirDano", 0.5f);
 }
Exemple #8
0
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.Space))
     {
         estado = EstadoPlayer.Saltando;
     }
     print(estado + ":" + EstaEnSuelo());
     if (estado == EstadoPlayer.Sufriendo && EstaEnSuelo())
     {
         estado = EstadoPlayer.Pausa;
     }
 }
    public void TerminarTeletransportar()
    {
        GetComponent <SpriteRenderer>().enabled = true;
        rb.isKinematic = false;

        foreach (CapsuleCollider2D cc in GetComponents <CapsuleCollider2D>())
        {
            cc.enabled = true;
        }

        estadoPlayer       = EstadoPlayer.normal;
        transform.position = GameObject.Find("DestinoTeletransporte").transform.position;
        ui.FundirNegro(0, 1.5f);
    }
    void FixedUpdate()
    {
        float xPos         = Input.GetAxis("Horizontal");
        float ySpeedActual = rb2D.velocity.y;

        if (estado == EstadoPlayer.Sufriendo)
        {
            return;
        }

        if (Mathf.Abs(xPos) > 0.01f)
        {
            playerAnimator.SetBool("andando", true);
        }
        else
        {
            playerAnimator.SetBool("andando", false);
        }

        if (estado == EstadoPlayer.Saltando)
        {
            estado = EstadoPlayer.Pausa;
            if (EstaEnElSuelo())
            {
                rb2D.velocity = new Vector2(xPos * speed, jumpForce);
            }
            else
            {
                rb2D.velocity = new Vector2(xPos * speed, ySpeedActual);
            }
        }
        else if (xPos > 0.01f)
        {
            rb2D.velocity = new Vector2(xPos * speed, ySpeedActual);
            if (estado == EstadoPlayer.AndandoIzq)
            {
                transform.localScale = new Vector2(1, 1);
            }
            estado = EstadoPlayer.AndandoDer;
        }
        else if (xPos < -0.01f)
        {
            rb2D.velocity = new Vector2(xPos * speed, ySpeedActual);
            if (estado == EstadoPlayer.AndandoDer)
            {
                transform.localScale = new Vector2(-1, 1);
            }
            estado = EstadoPlayer.AndandoIzq;
        }
    }
    public void TerminarNivel()
    {
        CancelInvoke("Parpadeo");
        GetComponent <SpriteRenderer>().enabled = true;
        Destroy(rb);

        foreach (CapsuleCollider2D cc in GetComponents <CapsuleCollider2D>())
        {
            cc.enabled = false;
        }

        gm.TerminarNivel();
        estadoPlayer = EstadoPlayer.paralizado;
    }
Exemple #12
0
    private void Reiniciar()
    {
        gm.Empezar(nombreJugador);
        icono.SetActive(true);
        llama.SetActive(true);
        material.color = new Color(1, 1, 1, 1);
        Sequence s = DOTween.Sequence();

        s.Append(material.DOColor(new Color(1, 1, 1, 0), 0.05f));
        s.Append(material.DOColor(new Color(1, 1, 1, 1), 0.05f));
        s.SetLoops(14);
        estadoPlayer = EstadoPlayer.recibiendoDano;

        Invoke("QuitarRecibiendoDano", 1.4f);
    }
    // EXTRAS

    private void Parpadeo()
    {
        if (parpadeos < 8)
        {
            GetComponent <SpriteRenderer>().enabled = !GetComponent <SpriteRenderer>().enabled;
            parpadeos++;
        }
        else
        {
            GetComponent <SpriteRenderer>().enabled = true;
            parpadeos    = 0;
            estadoPlayer = EstadoPlayer.normal;
            CancelInvoke("Parpadeo");
        }
    }
    // TELETRANSPORTE

    public void Teletransportar()
    {
        rb.isKinematic = true;
        rb.velocity    = Vector2.zero;
        foreach (CapsuleCollider2D cc in GetComponents <CapsuleCollider2D>())
        {
            cc.enabled = false;
        }

        estadoPlayer = EstadoPlayer.paralizado;
        animator.SetBool("corriendo", false);
        ui.FundirNegro(1, 1.5f);
        CancelInvoke();
        GetComponent <SpriteRenderer>().enabled = true;
        Invoke("TerminarTeletransportar", 1.5f);
    }
 public void CambiarPosicionPlayer()
 {
     // FUERZA EN DIAGONAL HACIA ARRIBA HACIA LA IZQUIERDA
     // HACIA LA IZQUIERDA
     if (estado == EstadoPlayer.AndandoDerecha)
     {
         GetComponent <Rigidbody2D>().AddRelativeForce(
             new Vector3(-fuerzaImpactoX, fuerzaImpactoY), ForceMode2D.Impulse);
         estado = EstadoPlayer.Sufriendo;
     }
     else if (estado == EstadoPlayer.AndandoIzquierda)
     {
         GetComponent <Rigidbody2D>().AddRelativeForce(
             new Vector3(fuerzaImpactoX, fuerzaImpactoY), ForceMode2D.Impulse);
         estado = EstadoPlayer.Sufriendo;
     }
 }
    // PODER

    public void ActivarPoder()
    {
        if (estadoPlayer != EstadoPlayer.paralizado && estadoPlayer != EstadoPlayer.inmune && gm.ObtenerPoder() > 0 && !animator.GetBool("recibiendoDano"))
        {
            Sequence s = DOTween.Sequence();
            s.Append(GetComponent <SpriteRenderer>().DOColor(new Color(1, 0.8f, 0), 0.5f));
            s.Append(GetComponent <SpriteRenderer>().DOColor(new Color(1, 1, 1), 0.5f));
            s.SetLoops(-1);
            efectoPoder.SetActive(true);
            fogonazo.SetActive(true);
            fogonazo.GetComponent <SpriteRenderer>().DOColor(new Color(1, 1, 1, 0), 0.2f);
            Invoke("QuitarFogonazo", 0.2f);
            estadoPlayer  = EstadoPlayer.inmune;
            poderActivado = true;
            audios[AUDIO_PODER].Play();
            gm.ActivarPoder();
        }
    }
    // DANO

    public void RecibirDano(float dano)
    {
        if (estadoPlayer == EstadoPlayer.normal)
        {
            audios[AUDIO_DANO].Play();
            if (gm.QuitarVida(dano))
            {
                PerderVida(true);
            }
            else
            {
                animator.SetBool("recibiendoDano", true);
            }

            estadoPlayer  = EstadoPlayer.inmune;
            tieneCadencia = false;
            animator.SetBool("disparando", false);
        }
    }
Exemple #18
0
    public void RecibirDano(int dano)
    {
        if (estadoPlayer == EstadoPlayer.normal)
        {
            if (!gm.RecibirDano(dano, nombreJugador))
            {
                MeshRenderer mr = GetComponentInChildren <MeshRenderer>();
                Sequence     s  = DOTween.Sequence();
                s.Append(material.DOColor(new Color(1, 1, 1, 0), 0.05f));
                s.Append(material.DOColor(new Color(1, 1, 1, 1), 0.05f));
                s.SetLoops(14);
                estadoPlayer = EstadoPlayer.recibiendoDano;
                Invoke("QuitarRecibiendoDano", 1.4f);
            }
            else
            {
                GameObject go = Instantiate(explosion, transform.position, transform.rotation);
                icono.SetActive(false);
                material.color = new Color(1, 1, 1, 0);
                llama.SetActive(false);
                audioLaser.Stop();
                StopCoroutine("DispararContinuo");
                StopCoroutine("DispararLaser");
                disparoContinuo = false;
                disparoLaser    = false;
                estadoPlayer    = EstadoPlayer.reiniciando;

                if (!gm.RestarVida(nombreJugador))
                {
                    gm.ReiniciarJugador(nombreJugador);
                    Invoke("Reiniciar", 2.5f);
                }
                else
                {
                    gm.MostrarGameOver(nombreJugador);
                    tag  = "Untagged";
                    name = name + "Muerto";
                }
            }
        }
    }
 public void RecibirDanyo(int danyo)
 {
     salud = salud - danyo;
     if (salud <= 0)
     {
         vidas--;
         uiScript.RestarVida();
         salud = saludMaxima;
     }
     if (estado == EstadoPlayer.AndandoDer)
     {
         GetComponent <Rigidbody2D>().AddRelativeForce(
             new Vector2(-fuerzaImpactoX, fuerzaImpactoY), ForceMode2D.Impulse);
         estado = EstadoPlayer.Sufriendo;
     }
     else if (estado == EstadoPlayer.AndandoIzq)
     {
         GetComponent <Rigidbody2D>().AddRelativeForce(
             new Vector2(fuerzaImpactoX, fuerzaImpactoY), ForceMode2D.Impulse);
         estado = EstadoPlayer.Sufriendo;
     }
     txtSalud.text = "Health:" + salud.ToString();
 }
Exemple #20
0
    // PODER

    public void ActivarPoder()
    {
        if (estadoPlayer != EstadoPlayer.paralizado && estadoPlayer != EstadoPlayer.inmune && gm.ObtenerPoder() > 0 && !animator.GetBool("recibiendoDano"))
        {
            Sequence s = DOTween.Sequence();
            s.Append(GetComponent <SpriteRenderer>().DOColor(new Color(1, 0.8f, 0), 0.5f));
            s.Append(GetComponent <SpriteRenderer>().DOColor(new Color(1, 1, 1), 0.5f));
            s.SetLoops(-1);
            efectoPoder.SetActive(true);
            fogonazo.SetActive(true);
            fogonazo.transform.localScale = new Vector3(2, 2, 1);
            fogonazo.transform.DOScale(0, 0.6f);
            fogonazo.transform.DORotate(new Vector3(0, 0, 720), 0.6f, RotateMode.LocalAxisAdd);
            Sequence s2 = DOTween.Sequence();
            s2.Append(fogonazo.GetComponent <SpriteRenderer>().DOColor(new Color(1, 1, 1, 0.8f), 0.2f));
            s2.Append(fogonazo.GetComponent <SpriteRenderer>().DOColor(new Color(1, 1, 1, 0), 0.4f));
            Invoke("QuitarFogonazo", 0.6f);
            estadoPlayer  = EstadoPlayer.inmune;
            poderActivado = true;
            audios[AUDIO_PODER].Play();
            gm.ActivarPoder();
        }
    }
Exemple #21
0
    public void Recibirdanyo(int danyo)
    {
        salud = salud - danyo;

        if (salud <= 0)
        {
            vidas--;
            salud = saludMaxima;
            uiScript.RestarVida();
        }

        if (estado == EstadoPlayer.AndandoDer)
        {
            estado = EstadoPlayer.Sufriendo;
            GetComponent <Rigidbody2D>().AddRelativeForce(
                new Vector2(-fuerzaimpactoX, fuerzaImpactoY), ForceMode2D.Impulse);
        }
        else if (estado == EstadoPlayer.AndandoIzq)
        {
            estado = EstadoPlayer.Sufriendo;
            GetComponent <Rigidbody2D>().AddRelativeForce(
                new Vector2(fuerzaimpactoX, fuerzaImpactoY), ForceMode2D.Impulse);
        }
    }
Exemple #22
0
 private void QuitarRecibiendoDano()
 {
     estadoPlayer = EstadoPlayer.normal;
 }
Exemple #23
0
 public void DespausarJuego()
 {
     estadoPlayer = EstadoPlayer.normal;
     gm.DespausarJuego();
 }
Exemple #24
0
 public void PausarJuego()
 {
     estadoPlayer = EstadoPlayer.reiniciando;
     gm.PausarJuego();
 }
Exemple #25
0
 private void QuitarRecibirDano()
 {
     estadoPlayer = EstadoPlayer.normal;
     animator.SetBool("recibiendoDano", false);
 }
    // Update is called once per frame
    void FixedUpdate()
    {
        float xPos = Input.GetAxis("Horizontal");

        //float yPos = Input.GetAxis("Vertical");

        // LA VELOCIDAD EN EL EJE Y ES CONSTANTE Y LE APLICA LA FUERZA DE LA GRAVEDAD
        // SI NO LO PONEMOS VA MUY DESPACIO
        //float ySpeed = rb2D.velocity.y;

        // VAMOS A PONER QUE LA VELOCIDAD EN X E Y SEA PROPORCIONAL
        //float ySpeed = rb2D.velocity.y;

        // GUARDAR LA VELOCIDAD ACTUAL EN EL EJE DE LA Y
        // VELOCIDAD QUE TENIA ANTERIOR
        float ySpeedActual = rb2D.velocity.y;


        // PARA SALIRSE DE LA FUNCION PARA QUE NO HAGA LOS VELOCITY CUANDO NOS
        // ESTA QUITANDO VIDAS
        if (estado == EstadoPlayer.Sufriendo)
        {
            return;
        }

        // PARA SABER LA DIRECCION QUE TIENE EL PLAYER
        // PARA LOS DISPAROS
        // float valorAbsoluto = Mathf.Abs(xPos);

        // CAMBIAR POSICION Y ANIMACION DEL PLAYER
        if (Mathf.Abs(xPos) > 0.01f)
        {
            // ANDA
            // MODIFICAMOS EL PARAMETRO DEL ANIMATOR CUIDADITO
            playerAnimator.SetBool("Andando", true);
        }
        else
        {   // SE PARA
            // MODIFICAMOS EL PARAMETRO DEL ANIMATOR
            playerAnimator.SetBool("Andando", false);
        }



        // SI LA POSICION DE y > 0
        //if (yPos > 0) {
        // SI LA ESTOY PULSANDO SE MOVERA
        // LO DE PREGUNTAR XPOS = 0 ES MAS ARRIESGADO (DIRECCION PLAYER)
        // (valorAbsoluto > 0.01f) { // NO SALTA CUANDO ESTOY PARADO Y ESTA MAL HAY QUE MODIFICARLA
        // PORQUE QUEREMOS QUE SALTE AUNQUE ESTE PARADO
        //if (saltando)


        // print(estado);
        // Añadimos el Enumerador
        if (estado == EstadoPlayer.Saltando) // SI ESTAS SALTANDO ES UN ESTADO MOMENTANEO
        {
            estado = EstadoPlayer.Pausa;     // LO PONEMOS AQUI PARA QUE SALTE SOLO UNA VEZ
            // ESTA EN EL SUELO
            if (EstaEnElSuelo())
            {
                // LE PONEMOS SOLO LA FUERZA DE SALTO
                rb2D.velocity = new Vector2(xPos * speed, jumpForce);
            }
            // CUANDO NO ESTES EN EL SUELO PARA QUE NO VAYA LATERALMENTE
            else
            { //PARA IR HACIA LA DERECHA E IZQUIERDA
                rb2D.velocity = new Vector2(xPos * speed, ySpeedActual);
            }
        }
        else if (xPos > 0.01f)   // HACIA LA DERECHA
        {
            rb2D.velocity = new Vector2(xPos * speed, ySpeedActual);
            if (estado == EstadoPlayer.AndandoIzquierda)
            {
                // PARA QUE ROTE
                transform.localScale = new Vector2(1, 1);
            }
            estado = EstadoPlayer.AndandoDerecha;
        }
        else if (xPos < -0.01f) // HACIA LA IZQUIERDA
        {
            rb2D.velocity = new Vector2(xPos * speed, ySpeedActual);
            if (estado == EstadoPlayer.AndandoDerecha || estado == EstadoPlayer.Pausa)
            {
                transform.localScale = new Vector2(-1, 1);
            }
            estado = EstadoPlayer.AndandoIzquierda;
        }

        /* // CUANDO SUELTE
         * else if (valorAbsoluto > 0.01f)
         * {
         *  rb2D.velocity = new Vector2(xPos * speed, ySpeedActual);
         * }*/

        //rb2D.velocity = new Vector3(xPos * speed, ySpeedActual);
    }