Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        if (GameStateController.Instance.IsPlaying == false)
        {
            return;
        }

        movementController.Move(inputProvider.Horizontal);
        if (punchTimer > 0)
        {
            punchTimer -= Time.deltaTime;
            if (punchTimer < 0)
            {
                punchTimer = 0;
            }
        }

        if (inputProvider.JumpDown)
        {
            if (movementController.Jump())
            {
                soundController.PlayJump();
            }
            else
            {
                if (abilityController.Slam())
                {
                    animator.SetTrigger("Slam");
                    soundController.PlayPunch();
                }
            }
        }

        if (inputProvider.PunchDown && punchTimer <= 0)
        {
            if (abilityController.Punch())
            {
                punchTimer = abilityController._punchCooldown;
                animator.SetTrigger("Punch");
                soundController.PlayPunch();
            }
        }


        //animation
        animator.SetFloat("VelocityX", Mathf.Abs(movementController.Velocity.x));
        animator.SetFloat("VelocityY", movementController.Velocity.y);
        animator.SetBool("IsBlocked", movementController.IsBlocked);

        if (_lastHadPunch != abilityController.hasPunch)
        {
            _lastHadPunch = abilityController.hasPunch;
            animator.SetBool("HasPunch", abilityController.hasPunch);
            animator.SetTrigger("ChangeAbilities");
        }

        if (_lastHadSlam != abilityController.hasSlam)
        {
            _lastHadSlam = abilityController.hasPunch;
            animator.SetBool("HasSlam", abilityController.hasSlam);
            animator.SetTrigger("ChangeAbilities");
        }

        if (movementController.LastDirection > 0)
        {
            playerSprite.flipX = true;
        }
        else
        {
            playerSprite.flipX = false;
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        if (gameStateController.IsPaused)
        {
            return;
        }

        if (Input.GetButtonDown("Jump"))
        {
            groundMovementController.Jump();
        }

        float horizontal = Input.GetAxis("Horizontal");

        //int horizontal = 0;
        //if (Input.GetKey(KeyCode.D)) {
        //    horizontal = 1;
        //} else if (Input.GetKey(KeyCode.A)) {
        //    horizontal = -1;
        //}


        groundMovementController.Move(horizontal * (isFlipped ? -1f : 1f));

        float center = (flipMaxThresh + flipMinThresh) / 2;

        if (isFlipped && transform.position.y > flipMaxThresh)
        {
            cameraController.targetZRotation = 0f;
            groundMovementController.SetGravityScale(1.0f);
            groundMovementController.SetRelative(Vector2.up, Vector2.right);
            musicController.ReplaceTrack(1, 0, 1f);
            isFlipped            = false;
            spriteRenderer.flipY = false;
        }
        else if (!isFlipped && transform.position.y < flipMinThresh)
        {
            groundMovementController.SetGravityScale(-1.0f);
            groundMovementController.SetRelative(Vector2.down, Vector2.left);
            isFlipped = true;
            musicController.ReplaceTrack(0, 1, 1f);
            cameraController.targetZRotation = 180f;
            spriteRenderer.flipY             = true;
        }

        if (groundMovementController.LastDirection < 0f)
        {
            spriteRenderer.flipX = !isFlipped;
        }
        else if (groundMovementController.LastDirection > 0f)
        {
            spriteRenderer.flipX = isFlipped;
        }

        if (isFlipped)
        {
            animator.SetBool("falling", groundMovementController.Velocity.y > 0);
        }
        else
        {
            animator.SetBool("falling", groundMovementController.Velocity.y < 0);
        }

        animator.SetBool("moving", Mathf.Abs(groundMovementController.Velocity.x) > 0.15f);
        animator.SetBool("grounded", groundMovementController.IsGrounded);
    }