Exemplo n.º 1
0
    //input and logic goes here
    void Update()
    {
        //<<<<<<< HEAD:A Sticky Situation/Assets/Engine/PlayerController.cs
        if (!canMove)
        {
            return;
        }

        if (celebrating)
        {
            return;
        }

        //get horizontal movement
        if (GlobalProperties.IS_NETWORKED)
        {
            xInput  = Input.GetAxis("Horizontal");
            xInput *= accelerationSpeed;
        }
        else if (!isPaused)
        //>>>>>>> 9d7014c9d9c7ae46f9e434202e06ac007b80b210:A Sticky Situation/Assets/Engine/Player/PlayerController.cs
        {
            if (XBox.StartPressed())
            {
                isPaused = true;
                Camera.main.GetComponent <PauseButtons>().pauseScreen.SetActive(true);
                Camera.main.GetComponent <PauseButtons>().mainCanvas.SetActive(false);

                PlayerController[] allPlayers = GameObject.FindObjectsOfType <PlayerController>();

                foreach (var p in allPlayers)
                {
                    p.isPaused = true;
                }
            }

            if (!canMove)
            {
                return;
            }

            //get horizontal movement
            if (GlobalProperties.IS_NETWORKED)
            {
                xInput  = Input.GetAxis("Horizontal");
                xInput *= accelerationSpeed;
            }
            else
            {
                if (AI == null)
                {
                    xInput  = XBox.HorizontalAxis();
                    xInput *= accelerationSpeed;

                    if (XBox.SprintPressed() && xInput != 0 && !exhausted)
                    {
                        COMMAND_Sprint();
                    }
                    else
                    {
                        COMMAND_DontSprint();
                    }
                }
            }

            if (GlobalProperties.IS_NETWORKED)
            {
                SpecialCharacterMovesNetwork();
            }
            else
            {
                SpecialCharacterMovesLocal();
            }

            CalculateSprintScale(false /*xInput > 0*/);

            if (xInput > 0 || xInput < 0)
            {
                animator.SetBool("Walking", true);

                if (xInput > 0)
                {
                    this.transform.localScale    = scale;
                    nametag.transform.localScale = nametagScale;
                    abs.transform.localScale     = absScale;
                }
                else
                {
                    this.transform.localScale    = minScale;
                    nametag.transform.localScale = nametagMinScale;
                    abs.transform.localScale     = absMinScale;
                }
            }
            else
            {
                animator.SetBool("Walking", false);
            }

            isGrounded = Physics2D.OverlapCircle(footTransform.position, groundedRadius, whatIsGround);
            animator.SetBool("Grounded", isGrounded);

            if (isGrounded)
            {
                if (GlobalProperties.IS_NETWORKED)
                {
                    if (Input.GetButtonDown("Jump"))
                    {
                        isGrounded = false;
                        animator.SetBool("Grounded", false);
                        animator.SetBool("Jumped", true);
                        myBody.AddForce(Vector2.up * jumpForce);
                        AudioSource.PlayClipAtPoint(jump, this.transform.position);
                        animator.SetBool("InAir", true);
                    }
                }
                else
                {
                    if (AI == null)
                    {
                        if (XBox.PressedJump())
                        {
                            COMMAND_Jump();
                        }
                    }
                }

                if (!wasGrounded)
                {
                    AudioSource.PlayClipAtPoint(land, this.transform.position);
                    animator.SetBool("InAir", false);
                }
            }
            else
            {
                animator.SetBool("InAir", true);
            }

            //<<<<<<< HEAD:A Sticky Situation/Assets/Engine/PlayerController.cs
            if (XBox.CelebratePressed())
            {
                if (!celebrating)
                {
                    Celebrate();
                }
            }

            float raycastD = .55f;
            //check raycasting for objects to the left and right of player
            if (xInput > 0)
            {
                //right
                if (RaycastCollision(true, raycastD))
                {
                    myBody.velocity = new Vector2(0, myBody.velocity.y);
                    xInput          = 0;

                    if (AI != null)
                    {
                        AI.BlockCollide(true);
                    }
                }
            }
            else if (xInput < 0)
            {
                //left
                if (RaycastCollision(false, raycastD))
                {
                    myBody.velocity = new Vector2(0, myBody.velocity.y);
                    xInput          = 0;

                    if (AI != null)
                    {
                        AI.BlockCollide(false);
                    }
                }
            }

            if (hasStickyBomb)
            {
                if (AI == null)
                {
                    bombImage.SetActive(true);
                    if (GlobalProperties.IS_NETWORKED && Input.GetMouseButtonDown(0))
                    {
                        NetworkThrowBomb();
                    }
                    else if (!GlobalProperties.IS_NETWORKED && XBox.PressedThrow())
                    {
                        COMMAND_LocalThrowBomb();
                    }
                }
            }
            else if (isStuck)
            {
                bombImage.SetActive(true);
                bombImage.GetComponent <Image> ().color = Color.red;
            }
            else
            {
                bombImage.SetActive(false);
            }

            wasGrounded = isGrounded;
        }
    }