Ejemplo n.º 1
0
 // Esta función indicará qué velocidad tenemos en tierra
 float calcularVelocidadEnTierra(GravChange gravitacional, Rigidbody2D QuecoRig)
 {
     if (gravitacional.abajo)
     {
         return(Mathf.Abs(QuecoRig.velocity.x));
     }
     else if (gravitacional.arriba)
     {
         return(Mathf.Abs(QuecoRig.velocity.x));
     }
     else if (gravitacional.izq)
     {
         return(Mathf.Abs(QuecoRig.velocity.y));
     }
     else
     {
         return(Mathf.Abs(QuecoRig.velocity.y));
     }
 }
Ejemplo n.º 2
0
    /*
     * Esto lo sustituiremos después por un Vector2 y lo devolveremos, dando un SpeedX y SpeedY
     * */

    // Esta función la vamos a calcular para saber cuándo estamos al inicio del salto o al final
    float calcularVelocidadEnAire(GravChange gravitacional, Rigidbody2D QuecoRig)
    {
        if (gravitacional.abajo)
        {
            return(QuecoRig.velocity.y);
        }
        else if (gravitacional.arriba)
        {
            return(-QuecoRig.velocity.y);
        }
        else if (gravitacional.izq)
        {
            return(QuecoRig.velocity.x);
        }
        else
        {
            return(-QuecoRig.velocity.x);
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        speed     = 350f;
        jumpSpeed = 750f;

        GravChange gravitacional = GetComponent <GravChange> ();
        //Obtenemos el Rigid Body del Queco para que al saltar le podamos aplicar fuerzas.
        Rigidbody2D QuecoRig = this.gameObject.GetComponent <Rigidbody2D> ();
        //Vamos a obtener la velocidad del personaje en todo momento para controlar la velocidad del salto.
        float airVelocity    = calcularVelocidadEnAire(gravitacional, QuecoRig);
        float groundVelocity = calcularVelocidadEnTierra(gravitacional, QuecoRig);

        //Asignamos dichas velocidades a los valores que controlan las animaciones
        GlobalStats.currentStats.jugador.GetComponent <Animator>().SetFloat("SpeedX", airVelocity);
        GlobalStats.currentStats.jugador.GetComponent <Animator>().SetFloat("SpeedY", groundVelocity);

        if (Input.GetKey(KeyCode.D))
        {
            if (gravitacional.abajo || gravitacional.arriba)
            {
                QuecoRig.velocity = new Vector2(speed, QuecoRig.velocity.y);
                if (gravitacional.abajo)
                {
                    isFacingRight = false;
                }
                else
                {
                    isFacingRight = true;
                }
                GlobalStats.currentStats.SetLimitAimAngle(new Vector4(90, 270, 0, 359));
            }
            if (gravitacional.abajo)
            {
                this.gameObject.transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
            else if (gravitacional.arriba)
            {
                this.gameObject.transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
        }

        if (Input.GetKey(KeyCode.A))
        {
            if (gravitacional.abajo || gravitacional.arriba)
            {
                QuecoRig.velocity = new Vector2(-speed, QuecoRig.velocity.y);
                if (gravitacional.abajo)
                {
                    isFacingRight = true;
                }
                else
                {
                    isFacingRight = false;
                }
                GlobalStats.currentStats.SetLimitAimAngle(new Vector4(270, 90, 180, 179));
            }
            if (gravitacional.abajo)
            {
                this.gameObject.transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
            else if (gravitacional.arriba)
            {
                this.gameObject.transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
        }

        if (Input.GetKey(KeyCode.W))
        {
            if (gravitacional.izq || gravitacional.der)
            {
                QuecoRig.velocity = new Vector2(QuecoRig.velocity.x, speed);
                if (gravitacional.der)
                {
                    isFacingRight = false;
                }
                else
                {
                    isFacingRight = true;
                }
                GlobalStats.currentStats.SetLimitAimAngle(new Vector4(180, 0, 90, 89));
            }
            if (gravitacional.izq)
            {
                this.gameObject.transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
            else if (gravitacional.der)
            {
                this.gameObject.transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
        }

        if (Input.GetKey(KeyCode.S))
        {
            if (gravitacional.izq || gravitacional.der)
            {
                QuecoRig.velocity = new Vector2(QuecoRig.velocity.x, -speed);
                if (gravitacional.izq)
                {
                    isFacingRight = false;
                }
                else
                {
                    isFacingRight = true;
                }
                GlobalStats.currentStats.SetLimitAimAngle(new Vector4(360, 180, 270, 269));
            }
            if (gravitacional.der)
            {
                this.gameObject.transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
            else if (gravitacional.izq)
            {
                this.gameObject.transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
            }
        }

        if (Input.GetKeyDown(KeyCode.Space))
        {
            if (GlobalStats.currentStats.jugador.GetComponent <Animator>().GetBool("Ground") == true)
            {
                if (gravitacional.abajo)
                {
                    QuecoRig.velocity = new Vector2(0, jumpSpeed);
                }
                if (gravitacional.arriba)
                {
                    QuecoRig.velocity = new Vector2(0, -jumpSpeed);
                }
                if (gravitacional.izq)
                {
                    QuecoRig.velocity = new Vector2(jumpSpeed, 0);
                }
                if (gravitacional.der)
                {
                    QuecoRig.velocity = new Vector2(-jumpSpeed, 0);
                }
                GlobalStats.currentStats.jugador.GetComponent <Animator>().SetBool("Ground", false);
            }
        }

        if (QuecoRig.velocity == Vector2.zero)
        {
            QuecoRig.GetComponent <Animator>().SetBool("isIdle", true);
        }
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        //Debug.Log(Vector2.Distance(transform.position, GlobalStats.currentStats.jugador.transform.position));
        //Debug.Log(moveSpeed);
        //Debug.Log(player.transform.position);
        GravChange gravitacional = GetComponent <GravChange>();

        if (puntosVida <= 0)
        {
            PrefabManager.currentPrefabs.newtAgarrado.SetActive(false);
            PrefabManager.currentPrefabs.newt.GetComponent <Fire>().loaded = true;
            GlobalStats.currentStats.objetoActivo = GlobalStats.currentStats.jugador;
            GlobalStats.currentStats.jugador.GetComponent <GravChange>().gravitational = true;
            SoundManager.currentSounds.enemyDeath.Play();
            transform.localScale = new Vector2(0, 0);
            GlobalStats.currentStats.jugador.GetComponent <Jugador>().subirExp(expAtDeath);
            Destroy(this);
        }

        if ((Mathf.Abs(Vector2.Distance(transform.position, GlobalStats.currentStats.jugador.transform.position)) <= minDist) || isHit)
        {
            try
            {
                this.GetComponent <Animator>().SetBool("Attack", true);
            }
            catch
            {
                Debug.Log("Esto es un pincho xD");
            }
            if (gravitacional.abajo || gravitacional.arriba)
            {
                if (transform.position.x - GlobalStats.currentStats.jugador.transform.position.x > 0)
                {
                    if (gravitacional.abajo)
                    {
                        this.gameObject.transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
                    }
                    else if (gravitacional.arriba)
                    {
                        this.gameObject.transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
                    }
                    myRB.velocity = new Vector2(-1.5f * moveSpeed, myRB.velocity.y);
                }
                else if (transform.position.x - GlobalStats.currentStats.jugador.transform.position.x != 0)
                {
                    if (gravitacional.abajo)
                    {
                        this.gameObject.transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
                    }
                    else if (gravitacional.arriba)
                    {
                        this.gameObject.transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
                    }
                    myRB.velocity = new Vector2(1.5f * moveSpeed, myRB.velocity.y);
                }
            }
            if (gravitacional.izq || gravitacional.der)
            {
                if (transform.position.y - GlobalStats.currentStats.jugador.transform.position.y > 0)
                {
                    if (gravitacional.izq)
                    {
                        this.gameObject.transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
                    }
                    else if (gravitacional.der)
                    {
                        this.gameObject.transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
                    }
                    myRB.velocity = new Vector2(myRB.velocity.x, -1.5f * moveSpeed);
                }
                else if (transform.position.y - GlobalStats.currentStats.jugador.transform.position.y != 0)
                {
                    if (gravitacional.izq)
                    {
                        this.gameObject.transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
                    }
                    else if (gravitacional.der)
                    {
                        this.gameObject.transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
                    }
                    myRB.velocity = new Vector2(myRB.velocity.x, 1.5f * moveSpeed);
                }
            }
        }
    }
Ejemplo n.º 5
0
 // Use this for initialization
 void Start()
 {
     //find the bullet manager in the scene
     bulletManager = GameObject.Find("BulletManager");
     //initialise health to 10
     health = 10;
     //initialise timer to 0;
     timer = 0.0f;
     //by default the player can fire
     canFire = true;
     //initialise the player
     player = gameObject.GetComponent<Rigidbody> ();
     // initialise the sphere world
     gravity = GameObject.FindGameObjectWithTag ("Sphere").GetComponent<GravChange> ();
     //disable use of unity's gravity for the player
     player.useGravity = false;
     //freexe rotation for this game object
     player.constraints = RigidbodyConstraints.FreezeRotation;
     //stop the mouse pointer from moving
     Cursor.lockState = CursorLockMode.Locked;
     //make the mouse cursor invisible
     Cursor.visible = false;
     //initialise the camera to the main scene camera
     cam = Camera.main;
     //initialise debugger by finding it in the scene
     m_debugger = GameObject.Find("Canvas").GetComponentInChildren<DebugUtil>();
     //initialise fuel gague
     m_fuelGague = 5.0f;
     //player is not flying by default
     m_flying = false;
     //initialise the respawn manager
     rManager = GameObject.Find("RespawnManager").GetComponent<RespawnManagerScript>();
 }