void handleTornado()
    {
        canTornado    = false;
        canBroom      = true;
        canDoubleJump = true;
        anim.SetBool("inTornado", true);
        velocity           = Vector3.zero;
        transform.position = Vector3.SmoothDamp(transform.position, currentTornado.position, ref velocitySmoothing, 0.05f);

        if (AtlasInputManager.getKeyPressed("Jump"))
        {
            firstJump();
            anim.SetBool("inTornado", false);
            returnToMovement();
            Deformer nadoDeformer = currentTornado.GetComponent <Deformer>();
            if (nadoDeformer)
            {
                nadoDeformer.startDeform(new Vector3(0.75f, 2.0f, 1.0f), 0.1f);
                SoundManager.Instance.playClip("LevelObjects/EnterTornado", 1);
            }
            currentTornado = null;
        }
        if (AtlasInputManager.getKeyPressed("Down"))
        {
            movingPlatform mp = currentTornado.GetComponent <movingPlatform>();
            if (mp)
            {
                velocity.x = mp.getVelocity().x;
            }
            Deformer nadoDeformer = currentTornado.GetComponent <Deformer>();
            if (nadoDeformer)
            {
                nadoDeformer.startDeform(new Vector3(2.0f, 0.25f, 1.0f), 0.1f);
            }
            anim.SetBool("inTornado", false);
            returnToMovement();
            currentTornado = null;
            SoundManager.Instance.playClip("LevelObjects/EnterTornado", -1);
        }
    }
Beispiel #2
0
 void jump()
 {
     deformer.startDeform(new Vector3(0.9f, 1.1f, 1.0f), 0.1f, 0.1f);
     velocity.x = 2.5f * facing;
     velocity.y = 3f;
 }
    void handleMovement(float msMod = 1.0f, bool canJump = true, bool canTurnAround = true)
    {
        if (heldObject != null)
        {
            msMod  *= 0.5f;
            canJump = false;
        }

        Vector2 input = new Vector2(0, 0);

        if (!(state == State.WaitMoveable && isGrounded()))
        {
            input = new Vector2(AtlasInputManager.getAxisState("Dpad").x, AtlasInputManager.getAxisState("Dpad").y);
        }

        if (isGrounded() || coyoteTime > 0)
        {
            if (AtlasInputManager.getKeyPressed("Jump") && canJump)
            {
                firstJump();
            }
            if (AtlasInputManager.getKeyPressed("Broom"))
            {
                triggerBroomStart();
            }
            if (isGrounded())
            {
                if (!canBroom && state == State.Movement)
                {
                    canBroom = true;
                }
                canDoubleJump = true;
                resourceManager.Instance.restoreMana();
            }
        }
        else
        {
            if (canBroom && AtlasInputManager.getKeyPressed("Broom"))
            {
                if (wallRiding)
                {
                    flipHorizontal();
                    triggerBroomStart(fastBroom, facing);
                }
                else
                {
                    triggerBroomStart(fastBroom);
                }
                return;
            }

            if (hasWallJump && wallRiding && AtlasInputManager.getKeyPressed("Jump") && resourceManager.Instance.getPlayerMana() >= 2)
            {
                state = State.WallJumpInit;
                return;
            }

            if (hasDoubleJump && AtlasInputManager.getKeyPressed("Jump") && canJump && canDoubleJump && resourceManager.Instance.getPlayerMana() >= 1)
            {
                doubleJump();
            }
        }

        float currentMoveSpeed = moveSpeed;

        if (isCrouching())
        {
            currentMoveSpeed = 1.5f;
        }
        float targetVelocityX = input.x * currentMoveSpeed * msMod;

        anim.SetBool("isRunning", isGrounded() && (targetVelocityX != 0));
        anim.SetBool("isJumping", !isGrounded() && (velocity.y > 0) && canDoubleJump);
        anim.SetBool("isFalling", !isGrounded() && (velocity.y < -0.5f) && !controller.collisions.descendingSlope && !heldObject);
        anim.SetBool("wallSlide", wallRiding);
        if (wallRiding)
        {
            deformer.RemoveDeform("jump");
            deformer.RemoveDeform("fastfall");
        }

        if (canTurnAround)
        {
            setFacing(velocity.x);
        }

        velocity.x  = Mathf.SmoothDamp(velocity.x, targetVelocityX, ref velocityXSmoothing, (controller.collisions.below) ? groundAccelerationTime : airAccelerationTime);
        velocity.y += gravity * Time.deltaTime * ((wallRiding && velocity.y <= 0) ? 0.5f : 1.0f);

        if (wallRiding && velocity.y < maxWallSlideVel)
        {
            velocity.y = maxWallSlideVel;
        }

        float termVel;

        if (fastFalling)
        {
            if (AtlasInputManager.getAxisState("Dpad").y >= 0 || isGrounded() || velocity.y > 0)
            {
                fastFalling = false;
            }
            termVel     = fastFallVel;
            velocity.y += gravity * Time.deltaTime;
        }
        else
        {
            termVel = maxFallVel;
            deformer.RemoveDeform("fastfall");
            if (AtlasInputManager.getKeyPressed("Down") && !isGrounded() && (velocity.y <= 0.5f || !AtlasInputManager.getKey("Jump")))
            {
                fastFalling = true;
                deformer.startDeform(new Vector3(0.85f, 1.4f, 1.0f), 0.2f, -1.0f, -1.0f, "fastfall", true);
            }
        }
        if (velocity.y < termVel)
        {
            velocity.y = termVel;
        }

        if (velocity.y <= 0 && controller.isSafePosition())
        {
            lastSafePosition = transform.position;
        }
    }
    private void OnTriggerEnter2D(Collider2D other)
    {
        List <Collider2D> hitters = new List <Collider2D>();

        other.GetContacts(hitters);

        //Because the hitboxes appear as children, we have to filter AllyHitboxes out
        //Otherwise you could get hurt by whacking brambles or something
        //We can probably use this to implement hitlag when hurting things..
        foreach (Collider2D h in hitters)
        {
            if (h.tag == "AllyHitbox")
            {
                continue;
            }

            //if (other.transform.tag == "ResetDamaging" && !invulnerable)
            //{
            //    if (graceFrames > 0)
            //    {
            //        graceFrames--;
            //    }
            //    else
            //    {
            //        resetPosition = true;
            //    }
            //}
            if (intangibleStates.Contains(state))
            {
                return;
            }

            //if (other.gameObject.layer == LayerMask.NameToLayer("Danger") && !invulnerable)
            //{
            //    if (other.CompareTag("ResetDamaging") && graceFrames > 0) return;
            //    startBonk(1, resetPosition);
            //    return;
            //}

            if (other.tag == "Tornado" && canTornado)
            {
                resetAnimator();
                SoundManager.Instance.playClip("LevelObjects/EnterTornado");
                canTornado     = false;
                state          = State.Tornado;
                currentTornado = other.transform;
                Deformer nadoDeformer = other.GetComponent <Deformer>();
                if (nadoDeformer)
                {
                    nadoDeformer.startDeform(new Vector3(1.75f, .75f, 1.0f), 0.1f);
                }
            }

            if (other.CompareTag("Door"))
            {
                if (other.GetComponent <doorController>().enterable)
                {
                    currentDoor = other.GetComponent <doorController>();
                }
            }


            if (other.tag == "Follower")
            {
                followController other_fc = other.GetComponent <followController>();
                if (!other_fc.canCollect)
                {
                    return;
                }

                int numFollowers = 0;
                other_fc.following            = getFollower(GetComponent <followController>());
                other_fc.following.followedBy = other_fc;
                other_fc.canCollect           = false;

                followController getFollower(followController fc)
                {
                    if (!fc.followedBy)
                    {
                        return(fc);
                    }
                    else
                    {
                        numFollowers++;
                        return(getFollower(fc.followedBy));
                    }
                }

                SoundManager.Instance.playClip("Collectibles/starShard", numFollowers);
            }

            if (other.CompareTag("BroomCollectible") && state == State.Broom && hanger.childCount == 0)
            {
                other.transform.parent   = hanger;
                other.transform.position = hanger.position - Vector3.up * 0.15f;
                other.SendMessage("BroomPickUp");
            }

            if (other.CompareTag("Water"))
            {
                steps.isSubmerged = true;
            }
        }
    }