Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        //move the player position

        //for xbox controller
        float h = moveInputScript.GetMoveHorizontalAxis();        //mov_horiz
        float v = moveInputScript.GetMoveVerticalAxis();          //mov_vert

        //check if can breathe and set their color
        if (beaverMouth.transform.position.y >= constants.waterSurface)
        {
            //if transitioning to can beathe, play sound
            if (!playerStateScript.GetCanBreathe())
            {
                soundPlayer.PlayClip(surfacingSound, 1.0f);
            }

            playerStateScript.SetCanBreathe(true);
            if ("1" == playerStateScript.GetTeamNumber())
            {
                beaverSprite.GetComponent <SpriteRenderer>().color = constants.team1Color;
            }
            else
            {
                beaverSprite.GetComponent <SpriteRenderer>().color = constants.team2Color;
            }
        }
        else
        {
            //if transitioning to can't beathe, play sound
            if (playerStateScript.GetCanBreathe())
            {
                soundPlayer.PlayClip(divingSound, 1.0f);
            }

            playerStateScript.SetCanBreathe(false);

            if ("1" == playerStateScript.GetTeamNumber())
            {
                beaverSprite.GetComponent <SpriteRenderer>().color = constants.team1ColorWater;
            }
            else
            {
                beaverSprite.GetComponent <SpriteRenderer>().color = constants.team2ColorWater;
            }
        }

        if (!playerStateScript.GetIsSuffocating())
        {
            //check if in water or at surface
            if (transform.position.y >= constants.waterSurface)
            {
                animator.SetBool("on_land", false);

                //check if walking on platform
                //if( transform.position.y >= platformSurface && playerStateScript.GetIsTouchingPlatform()) {
                if (playerStateScript.GetIsTouchingPlatform())
                {
                    rBody.gravityScale = landGravity;
                    if (transform.position.y >= platformSurface)
                    {
                        animator.SetBool("on_land", true);
                        v = 0;                         //do not allow vertical movement when on the platform
                    }
                }
                else
                {
                    rBody.gravityScale = airGravity;
                }
            }
            else
            {
                rBody.gravityScale = waterGravity;
                animator.SetBool("on_land", false);
            }
        }

        //set animation if stick is moved enough
        if ((Mathf.Abs(h) > leftAnalogThresh) || (Mathf.Abs(v) > leftAnalogThresh))
        {
            //show the player moving animation
            animator.SetBool("is_moving", true);

            //move the player in the direction of the input
            rBody.AddForce(new Vector2(moveForce * h, 0));
            rBody.AddForce(new Vector2(0, moveForce * v));
        }
        else
        {
            animator.SetBool("is_moving", false);
        }

        // ********
        // * Had to take out the following to let the dash do it's thing
        // ***********
        ////limit to max speed in x
        //if (rBody.velocity.x > maxSpeed)
        //{
        //    rBody.velocity = new Vector2(maxSpeed, rBody.velocity.y);
        //}
        //else if (rBody.velocity.x < maxSpeed * -1)
        //{
        //    rBody.velocity = new Vector2(maxSpeed * -1, rBody.velocity.y);
        //}

        ////limit to max speed in y
        //if (rBody.velocity.y > maxSpeed)
        //{
        //    rBody.velocity = new Vector2(rBody.velocity.x, maxSpeed);
        //}
        //else if (rBody.velocity.y < maxSpeed * -1)
        //{
        //    rBody.velocity = new Vector2(rBody.velocity.x, maxSpeed * -1);
        //}

        //point the beaver_sprite in the same direction as it is moving
        RotateBeaver(h, v);

        //set the offset pearl object to point in the direction it will be thrown
        //also sets throw angle


        //flip the orientation of the sprite if direction was changed
        if ((facingRight && h < 0) || (!facingRight && h > 0))
        {
            Flip();
        }
    }