private void Awake()
 {
     manager    = GetComponent <SidescrollerControlManager>();
     input      = GetComponent <InputReceiver>();
     rb         = GetComponent <Rigidbody2D>();
     col        = GetComponent <Collider2D>();
     isDropping = manager.IsGrounded();
 }
Esempio n. 2
0
    private void FixedUpdate()
    {
        if (hp.currentValue <= hp.minValue && input.enabled)
        {
            OnDeath();
        }
        else if (manager.IsGrounded() && !input.enabled && Time.time - timeOfDeath >= .1f)
        {
            playerSprite.sprite = pinger.sprites[PingSpawner.Die];
        }

        if (Time.time - timeOfDeath >= deathAnimationTime)
        {
            GameManager.GetInstance().screenManager.GoToNextScene();
        }
    }
    private void Update()
    {
        float movement = input.GetQuantizedMovementVector().y;

        if (movement < 0 && Time.time - lastDropTime > dropDuration && manager.IsGrounded())
        {
            lastDropTime = Time.time;
        }

        if (!isDropping && Time.time - lastDropTime < dropDuration)
        {
            isDropping         = true;
            gameObject.layer   = playerDropThroughLayer;
            manager.groundMask = (1 << defaultLayer);
        }
        else if (isDropping && Time.time - lastDropTime >= dropDuration)
        {
            isDropping         = false;
            gameObject.layer   = playerLayer;
            manager.groundMask = (1 << defaultLayer) | (1 << dropThroughLayer);
        }
    }
Esempio n. 4
0
    private void FixedUpdate()
    {
        // Land on ground
        if (manager.IsGrounded() && rb.gravityScale == fallGravityScale)
        {
            GameManager.GetInstance().soundManager.PlaySound("land_on_ground_SFX", 0.7f, false);
            pingSpawner.Reveal(PingSpawner.Land);
            screenShake.Shake(ScreenShake.LandShake);
        }

        // Refresh double jumps
        if (doubleJumpsLeft != maxDoubleJumps)
        {
            if (manager.IsGrounded() || (wallRefreshesDoubleJumps && (manager.IsGrounded(Vector2.left) || manager.IsGrounded(Vector2.right))))
            {
                doubleJumpsLeft = maxDoubleJumps;
            }
        }

        // Jump if we are able to
        if (input.GetButtonDown("Jump"))
        {
            lastJumpInput = Time.time;
        }

        if (Time.time - lastJumpInput >= jumpDelay)
        {
            lastJumpInput = Mathf.Infinity;
            float targetSpeed = jumpSpeed - rb.velocity.y;

            // Grounded jump
            if (manager.IsGrounded())
            {
                rb.AddForce(targetSpeed * Vector2.up, ForceMode2D.Impulse);
                pingSpawner.Reveal(PingSpawner.Jump);
            }
            // Wall jump
            else if (allowWallJump && (manager.IsGrounded(Vector2.left) || manager.IsGrounded(Vector2.right)))
            {
                Vector2 targetVelocity;
                if (manager.IsGrounded(Vector2.left))
                {
                    targetVelocity = new Vector2(wallJumpVelocity.x - rb.velocity.x, wallJumpVelocity.y - rb.velocity.y);
                }
                else
                {
                    targetVelocity = new Vector2(-wallJumpVelocity.x - rb.velocity.x, wallJumpVelocity.y - rb.velocity.y);
                }
                rb.AddForce(targetVelocity, ForceMode2D.Impulse);
                pingSpawner.Reveal(PingSpawner.Jump);
            }
            // Double jump
            else if (doubleJumpsLeft > 0)
            {
                doubleJumpsLeft--;
                rb.AddForce(targetSpeed * Vector2.up, ForceMode2D.Impulse);
                pingSpawner.Reveal(PingSpawner.Jump);
            }
        }

        rb.gravityScale = manager.defaultGravityScale;
        if (rb.velocity.y < 0)
        {
            rb.gravityScale = fallGravityScale;
        }
        if (input.GetButtonUp("Jump"))
        {
            rb.gravityScale = jumpReleaseGravityScale;
        }
    }