Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (Player.IsGamePaused)
        {
            return;
        }

        HandleAnimationSet();
        if (Player.isExhausted)
        {
            return;
        }

        if (!isWalltouching || CanMove())
        {
            var actualMoveSpeed = (isInAir && !isOnLadder) ? Player.airSpeed : Player.moveSpeed;


            // HACK: This is terrible code
            if ((InputManager.IsPressed("left") || InputManager.IsPressed("right")) && !Player.isExhausted)  // We are walking
            {
                if (!SFXManager.IsFXPlaying("Steps") && !isInAir)
                {
                    SFXManager.PlayFX("Steps", true); // Want to loop
                }
                if (SFXManager.IsFXPlaying("Steps") && isInAir)
                {
                    SFXManager.StopFX("Steps");
                }
            }
            else if (SFXManager.IsFXPlaying("Steps"))
            {
                SFXManager.StopFX("Steps");
            }

            if (InputManager.IsPressed("left"))
            {
                if (isFacingRight)
                {
                    FlipPlayer();
                }
                body.AddForce(new Vector2(-1, 0) * actualMoveSpeed * Time.deltaTime, ForceMode2D.Impulse);
            }
            else if (InputManager.IsPressed("right"))
            {
                if (!isFacingRight)
                {
                    FlipPlayer();
                }
                body.AddForce(new Vector2(1, 0) * actualMoveSpeed * Time.deltaTime, ForceMode2D.Impulse);
            }
        }

        if (InputManager.IsPressed("jump") && !Player.isExhausted && !isJumpCooldown && jumpCounter > 0)
        {
            SFXManager.PlayFX("Jump");
            body.AddForce(new Vector2(0, 1) * Player.jumpStrength);
            isJumpCooldown = true;
            jumpCounter--;
            this.SignalIsClimbing(false);
            StartCoroutine(jumpTimer.Countdown(0.5f, new Delegates.EmptyDel(resetJumpCooldown)));
        }

        if (InputManager.IsPressed("up") || InputManager.IsPressed("down"))
        {
            if (avatarCollider.IsTouchingLayers(LayerMask.GetMask("LadderLayer")))
            {
                this.SignalIsClimbing(true);
            }
            // TODO: Add portal exiting/interaction
        }

        if (isOnLadder)
        {
            var climbForce = new Vector2(0, 0);
            if (InputManager.IsPressed("up"))
            {
                climbForce = new Vector2(0, 1);
            }
            if (InputManager.IsPressed("down") && isInAir && !isTouchingSomething)
            {
                climbForce = new Vector2(0, -1);
            }
            transform.Translate(climbForce * Player.climbSpeed * Time.deltaTime);
        }
        else
        {
            // We should be able to attack here
            if (InputManager.IsPressed("attack") && !isAttackCooldown)
            {
                HandleAttackLogic();
            }
        }

        if (OnInteractable)
        {
            if (InputManager.IsPressed("up") && !Player.isInteractCooldown)
            {
                Player.isInteractCooldown = true;
                Player.StartCoroutine(interactTimer.Countdown(0.5f, new Delegates.EmptyDel(Player.resetInteractCooldown)));
                OnInteractable.Interact();
            }
        }


        body.velocity = VelocityClamper.ClampVelocity(body.velocity, Player.maxVelocity);
    }
Exemplo n.º 2
0
 void Update()
 {
     RunAI();
     body.velocity = VelocityClamper.ClampVelocity(body.velocity, MaxMovementSpeed);
 }