Example #1
0
    void Update()
    {
        //Check if the Bsave is at surface. Thsi is a temporary solution the OnTriggerEnter method is a little bit more elegant
        // but will only work right when the mouth peace flips with the beaver sprite whoch it hopefully will.
        if (playerStateScript.GetIsSuffocating() && transform.position.y > 2.4f)
        {
            rBody.gravityScale = constants.waterGravity;
        }
        // beaver is suffocating and out of water
        if (playerStateScript.GetCanBreathe() && playerStateScript.GetIsSuffocating())
        {
            //set gravity back
            rBody.gravityScale = constants.airGravity;

            //isSuffocating = false;
            playerStateScript.SetIsSuffocating(false);
            //print("isSuffocating set false");

            // reset the beaver to be in the normal layer where they can interact with obstacles
            transform.FindChild("Beaver").gameObject.layer = LayerMask.NameToLayer("Non_Interactable");
            beaverMouth.transform.FindChild("beaver_mouth").gameObject.layer = LayerMask.NameToLayer("Non_Interactable");

            //animator.SetBool ("at_surface", true); // sets animator so that it transitions form foating to idle
            animator.SetTrigger("surface");

            // sets the icon animator to normal
//			iconIndicator.SetTrigger ("out_of_water");
//			iconIndicator.SetBool("isDead", false);

            //movingScript.enabled = true; // enable movement again (same for dashing and throwing)
            movingScript.SetMoveForce(constants.moveForceNormal);
            dashScript.enabled      = true;
            throwingScript.enabled  = true;
            colDetectScript.enabled = true;

            beaverPearlCollider.GetComponent <Collider2D> ().enabled = true;
        }
        // beaver is fine and under water
        else if (!playerStateScript.GetIsSuffocating() && !playerStateScript.GetCanBreathe())
        {
            animator.SetBool("at_surface", false);
            check_breathing();
        }
    }
Example #2
0
    // Update is called once per frame
    void Update()
    {
//		iconAnim.ResetTrigger ("breathing_in");
//		iconAnim.ResetTrigger ("breathing_out");
//		iconAnim.ResetTrigger ("breath_held");

        // above water
        if (playerStateScript.GetCanBreathe())
        {
            iconAnim.SetBool("isDead", false);
            iconAnim.SetBool("underwater", false);
        }
        else
        {
            iconAnim.SetBool("underwater", true);
        }

        // underwater and is dead
        if (!playerStateScript.GetCanBreathe() && playerStateScript.GetIsSuffocating())
        {
            iconAnim.SetTrigger("is_dead");
            iconAnim.SetBool("isDead", true);
        }

        if (!playerStateScript.GetCanBreathe())
        {
            iconAnim.SetTrigger("breath_held");
        }

        // breathing in and out in the game (while not suffocating).
        if (!playerStateScript.GetIsSuffocating())
        {
            if (Input.GetKey(breatheIn))
            {
                iconAnim.SetTrigger("breathing_in");
            }

            if (Input.GetKey(breatheOut))
            {
                iconAnim.SetTrigger("breathing_out");
            }
        }
    }
Example #3
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();
        }
    }