private void FixedUpdate()
    {
        if (!dropThroughPlatforms && AtlasInputManager.getKey("Jump") && isCrouching())
        {
            dropThroughPlatforms = true;
            controller.collisions.Reset();
            Vector3 downVec = Vector3.down;
            controller.VerticalCollisions(ref downVec);
            controller.checkGrounded(downVec.y);
        }
        anim.SetBool("isGrounded", isGrounded());
        if (isGrounded())
        {
            coyoteTime = maxCoyoteTime;
        }
        else if (coyoteTime > 0)
        {
            coyoteTime--;
        }

        if (state == State.Reset || state == State.Wait || state == State.Menu)
        {
            return;
        }
        controller.Move(velocity * Time.deltaTime);
        controller.checkWallSlide(facing);
        isWallSliding();
        if (controller.collisions.above || controller.collisions.below)
        {
            velocity.y = 0;
        }
    }
    void handleBroom()
    {
        if (AtlasInputManager.getKeyPressed("Broom") ||
            AtlasInputManager.getKeyPressed("Down") ||
            (!AtlasInputManager.getKey("Broom") &&
             AtlasInputManager.Instance.holdBroom))
        {
            endBroom();
            return;
        }
        if (AtlasInputManager.getKeyPressed("Jump") && canDoubleJump && resourceManager.Instance.getPlayerMana() >= 1)
        {
            endBroom();
            if (hasDoubleJump)
            {
                doubleJump();
            }
            return;
        }
        if ((facing == -1) ? controller.collisions.left : controller.collisions.right)
        {
            startBonk();
            return;
        }
        float vdir = 0 * AtlasInputManager.getAxisState("Dpad").y;

        velocity.y = moveSpeed / 2.0f * vdir;
        velocity.x = moveSpeed * 2 * facing;
    }
    void handleHolding()
    {
        if (!anim.GetBool("isHolding"))
        {
            return;
        }
        if (!heldObject)
        {
            anim.SetBool("isHolding", false);
            return;
        }

        heldObject.transform.localScale = new Vector3(facing, 1, 1);
        if ((state != State.Movement && state != State.WaitMoveable) || AtlasInputManager.getKeyPressed("Down"))
        {
            anim.SetBool("isHolding", false);
            dropHolding();
        }
        else if (AtlasInputManager.getKeyPressed("Up") || AtlasInputManager.getKeyPressed("Jump"))
        {
            anim.SetBool("isHolding", false);
            anim.SetTrigger("Throw");
            freezeForSeconds(0.4f, true);
            Invoke("throwHolding", 0.15f);
        }
    }
    private void Update()
    {
        if (AtlasInputManager.getKeyPressed("Escape"))
        {
            if (SceneManager.GetActiveScene().name == "Main Menu")
            {
                Application.Quit();
            }
            else
            {
                switch (state)
                {
                case MenuState.Closed:
                    togglePauseMenu(true);
                    break;

                case MenuState.Pause:
                    togglePauseMenu(false);
                    break;

                case MenuState.Controls:
                    togglePauseMenu(true);
                    break;

                case MenuState.Cheats:
                    togglePauseMenu(true);
                    break;
                }
            }
        }
    }
    private static void Init()
    {
        instance          = Resources.LoadAll <AtlasInputManager>("Managers")[0];
        instance.controls = new InputMaster();

        setControlScheme(instance.actionMap.ToString());
    }
    void handleAttack()
    {
        anim.SetFloat("animTime", anim.GetCurrentAnimatorStateInfo(0).normalizedTime);
        deformer.RemoveDeform("fastfall");

        if (AtlasInputManager.getKeyPressed("Attack"))
        {
            state = State.Attack;
            anim.SetTrigger("Attack");
        }
        if (!isGrounded())
        {
            arialAttacking = true;
        }
        else
        {
            if (arialAttacking)
            {
                if (fastFalling)
                {
                    anim.SetTrigger("fastFall");
                }
                anim.SetTrigger("attackLand");
                anim.SetBool("Attacking", false);
                particleMaker.createDust();
            }
            arialAttacking = false;
        }
    }
    void Update()
    {
        Vector2 input = AtlasInputManager.getAxisState("Dpad");

        if (input.x == 0 && input.y == 0)
        {
            selectIcon.transform.localPosition = Vector2.zero;
            selectIcon.SetActive(false);
            return;
        }
        selectIcon.SetActive(true);
        float theta = Mathf.Atan2(input.y, input.x);

        theta *= Mathf.Rad2Deg;
        theta += 360.0f;
        int index = (int)Mathf.Round(theta / 45.0f);

        index   %= 8;
        selected = index;
        selectIcon.transform.localPosition = Vector2.SmoothDamp(
            selectIcon.transform.localPosition,
            input.normalized,
            ref selectIconVel,
            0.05f);
    }
 void allowDoor()
 {
     if (currentDoor != null && AtlasInputManager.getKeyPressed("Interact"))
     {
         cutScenePrep();
         StartCoroutine(doDoor());
     }
 }
 void handleUncrouch()
 {
     checkCrouchHitbox();
     if (dropThroughPlatforms && AtlasInputManager.getAxisState("Dpad").y >= 0 || isGrounded())
     {
         dropThroughPlatforms = false;
     }
 }
 public void setControlScheme()
 {
     if (newControlScheme != null && newControlScheme != "")
     {
         AtlasInputManager.setControlScheme(newControlScheme);
     }
     togglePauseMenu(true);
 }
 public void handleScout()
 {
     if (AtlasInputManager.getKeyPressed("Scout"))
     {
         //pauseUntilCondition();
         gameManager.Instance.pause_manager.addPause(pauseManager.PauseType.Scouter);
         GameObject scouter = gameManager.createInstance("UI/ScouterTarget", transform.position);
         Camera.main.GetComponent <cameraController>().target = scouter.transform;
     }
 }
    private void OnTriggerStay2D(Collider2D other)
    {
        if (other.gameObject.layer == LayerMask.NameToLayer("BroomTrigger") && state == State.Broom)
        {
            other.SendMessage("OnBroomCollide");
        }

        if (other.CompareTag("Liftable") && AtlasInputManager.getKeyPressed("Up", true))
        {
            liftObject(other.gameObject);
        }

        if (other.CompareTag("ResetDamaging"))
        {
            if (graceFrames > 0)
            {
                graceFrames--;
            }
            else
            {
                resetPosition = true;
            }
        }
        ;

        if (other.CompareTag("ResetDrown"))
        {
            drown();
        }

        if (intangibleStates.Contains(state))
        {
            return;
        }
        if (other.gameObject.layer == LayerMask.NameToLayer("Danger") && (!invulnerable || other.CompareTag("ResetDamaging")))
        {
            if (other.CompareTag("ResetDamaging") && graceFrames > 0)
            {
                return;
            }

            if (other.CompareTag("Projectile"))
            {
                projectile p = other.GetComponent <projectile>();
                if (p.hurtPlayer)
                {
                    p.hit();
                }
            }

            startBonk(1, resetPosition);

            return;
        }
    }
 void canPickUp()
 {
     if (AtlasInputManager.getKeyPressed("Down") && isGrounded())
     {
         RaycastHit2D pickup = Physics2D.Raycast(transform.position, -Vector2.up, 0.5f, 1 << LayerMask.NameToLayer("Pickupable"));
         if (pickup.collider != null)
         {
             pickup.transform.SendMessage("pickUp");
         }
     }
 }
 void allowCrouch()
 {
     if (AtlasInputManager.getAxisState("Dpad").y < 0 && isGrounded())
     {
         anim.SetBool("isCrouching", true);
     }
     else if (controller.checkVertDist(0.3f))
     {
         anim.SetBool("isCrouching", false);
     }
 }
Esempio n. 15
0
    public void takeStep(float stepSize)
    {
        stepSize = 0.175f;
        if (Mathf.Ceil(AtlasInputManager.getAxisState("Dpad").x) != pc.facing)
        {
            return;
        }
        Vector3 velocity = stepSize * pc.facing * Vector3.right + .01f * Vector3.down;

        pc.controller.Move(velocity);
    }
 void handleAttackInput()
 {
     if (AtlasInputManager.getKeyPressed("Attack"))
     {
         if (state == State.Broom)
         {
             endBroom();
         }
         state = State.Attack;
         anim.SetTrigger("SelectAttack");
     }
 }
    // Update is called once per frame
    void Update()
    {
        if (!AtlasInputManager.getKey("Scout"))
        {
            Destroy(gameObject);
        }
        if (selectedPc && AtlasInputManager.getKeyPressed("Jump"))
        {
            textPanel.SetActive(true);
            textPanel.GetComponentInChildren <TextMeshProUGUI>().text = selectedPc.scoutMessage.Replace("\\n", "\n");
        }
        Vector2 velocity = AtlasInputManager.getAxisState("Dpad");

        transform.Translate(velocity * speed * Time.deltaTime);
    }
    //State BroomStart waits for Atlas to get on Broom. Animator calls startBroom
    void handleBroomStart()
    {
        anim.SetTrigger("broomStart");
        SoundManager.Instance.playClip("onBroom");
        deformer.RemoveDeform("fastfall");
        deformer.RemoveDeform("jump");
        if (state == State.Attack)
        {
            setFacing(AtlasInputManager.getAxisState("Dpad").x);
        }
        //if (AtlasInputManager.Instance.aimAtMouse())
        //{
        //    setFacing(AtlasInputManager.Instance.getPlayerAim(true).x);
        //}

        state     = fastBroom ? State.Broom : State.Wait;
        fastBroom = false;
        velocity  = Vector3.zero;
    }
    //Ideally we can find a way to pause until  a certain condition is met
    //But what do we do about multiple pauseCoroutines?
    IEnumerator pauseCoroutine()
    {
        Vector2 prevVelocity  = velocity;
        State   prevState     = state;
        float   prevAnimSpeed = anim.speed;

        velocity   = Vector3.zero;
        state      = State.Wait;
        anim.speed = 0;

        while (AtlasInputManager.getKey("Scout"))
        {
            yield return(new WaitForEndOfFrame());
        }

        state      = prevState;
        velocity   = prevVelocity;
        anim.speed = prevAnimSpeed;
    }
    IEnumerator WallJumpCoroutine()
    {
        state = State.WallJump;
        GameObject explosion = gameManager.createInstance("Effects/Explosions/wallBlast", transform.position + new Vector3(-0.80f * facing, 0.23f, 0));

        explosion.transform.localScale = sprite.localScale;
        if (screenShake)
        {
            Camera.main.GetComponent <cameraController>().StartShake(0.2f, 0.15f);
        }

        SoundManager.Instance.playClip("wallBlast");
        anim.SetBool("isJumping", false);
        anim.SetBool("isFalling", false);
        anim.SetBool("wallSlide", false);
        anim.SetBool("wallBlast", true);

        yield return(new WaitForSeconds(wallBlastDelay));

        anim.SetBool("isJumping", true);
        anim.SetBool("wallBlast", false);

        flipHorizontal();

        velocity.y = wallJumpVelocity;

        float startTime = Time.time;

        while (Time.time - startTime < 0.1f)
        {
            velocity.x  = wallJumpVelocity * facing;
            velocity.y += gravity * Time.deltaTime;

            if (AtlasInputManager.getKeyPressed("Broom") && canBroom)
            {
                triggerBroomStart();
                yield break;
            }
            yield return(new WaitForFixedUpdate());
        }
        anim.SetBool("wallBlast", false);
        returnToMovement();
    }
 IEnumerator jumpCoroutine(bool dj = false)
 {
     for (int i = 0; i < variableJumpIncrements; i++)
     {
         if (!AtlasInputManager.getKey("Jump"))
         {
             if (dj)
             {
                 velocity.y = Mathf.Min(velocity.y, doubleJumpVelocity / 2.0f);
             }
             else
             {
                 velocity.y /= 4;
             }
             i = variableJumpIncrements;
             yield return(0);
         }
         yield return(new WaitForSeconds(4 / 60.0f));
     }
 }
    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);
        }
    }
 //Popping a WooshBerry calls this.
 public void triggerBroomStart(bool fast = false, float dir = 0)
 {
     if (resetPosition || !controller.collisions.tangible)
     {
         return;
     }
     if (intangibleStates.Contains(state))
     {
         return;
     }
     //Cancel is ceiling above while crouching
     if (isCrouching() && !controller.checkVertDist(0.3f))
     {
         return;
     }
     if (dir == 0 && !wallRiding)
     {
         dir = AtlasInputManager.getAxisState("Dpad").x;
     }
     setFacing(dir);
     state     = State.BroomStart;
     fastBroom = fast;
     canBroom  = false;
 }
    void isWallSliding()
    {
        if (isGrounded() || state == State.Attack)
        {
            wallRiding = false;
            return;
        }
        float hdir = AtlasInputManager.getAxisState("Dpad").x;

        if (!wallRiding)
        {
            if (controller.collisions.wallRideLeft && hdir == -1 || controller.collisions.wallRideRight && hdir == 1)
            {
                wallRiding = true;
                return;
            }
        }
        else
        {
            wallRiding = controller.collisions.wallRideLeft || controller.collisions.wallRideRight;
            return;
        }
        wallRiding = false;
    }
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        playerController pc = animator.gameObject.GetComponentInParent <playerController>();

        foreach (AnimatorControllerParameter key in animator.parameters)
        {
            if (key.type == AnimatorControllerParameterType.Trigger)
            {
                animator.ResetTrigger(key.name);
            }
        }
        animator.SetBool("Attacking", true);

        bool up   = false;
        bool down = false;

        if (AtlasInputManager.Instance.aimAtMouse())
        {
            Vector2 aim = AtlasInputManager.Instance.getPlayerAim(true);
            up   = aim.y > 0;
            down = pc.isGrounded() ? pc.isCrouching() : aim.y < 0;
            if (aim.x != 0)
            {
                pc.setFacing(aim.x);
            }
        }
        else
        {
            up   = AtlasInputManager.getAxisState("Dpad").y > 0.1f;
            down = AtlasInputManager.getAxisState("Dpad").y < -0.1f || pc.isCrouching();
        }

        bool falling = (pc.velocity.y < -0.1);

        if (up)
        {
            animator.SetTrigger("UpAttack");
            SoundManager.Instance.playClip("BroomAttacks/LightAttack", Random.Range(-1, 1));
        }
        else if (down)
        {
            animator.SetTrigger("DownAttack");
            SoundManager.Instance.playClip("BroomAttacks/LightAttack", Random.Range(-1, 1));
        }
        else
        {
            if (!pc.isGrounded())
            {
                if (falling)
                {
                    animator.SetTrigger("FallingAttack");
                }
                else
                {
                    animator.SetTrigger("RisingAttack");
                }
            }
            else
            {
                animator.SetTrigger("Attack");
            }
            SoundManager.Instance.playClip("BroomAttacks/LightAttack", Random.Range(-1, 1));
        }
    }
 private void OnTriggerStay2D(Collider2D collision)
 {
     if (!(transform.parent && transform.parent.name == "seed") && collision.CompareTag("Player") && canPick && AtlasInputManager.getKeyPressed("Up", true))
     {
         if (gameManager.Instance.playerCtrl.canLift())
         {
             GameObject berry = gameManager.createInstance(liftObject, center);
             gameManager.Instance.playerCtrl.liftObject(berry.transform.Find("handle").gameObject);
             StartCoroutine(Picked(false));
         }
     }
 }
Esempio n. 27
0
 // Update is called once per frame
 void Update()
 {
     equipmentPanel.gameObject.SetActive(AtlasInputManager.getKey("DisplayEquipment"));
 }
    void Update()
    {
        if (AtlasInputManager.getKeyPressed("Cheat"))
        {
            hasDoubleJump = true;
            hasWallJump   = true;
            SoundManager.Instance.playClip("jump2");
        }
        playerShouldWait();
        handleParticles();
        if (state != State.Wait && state != State.WaitMoveable)
        {
            handleUncrouch();
            handleHolding();
            handleScout();
        }

        switch (state)
        {
        case State.Movement:
            handleMovement();
            handleAttackInput();
            canPickUp();
            allowDoor();
            allowCrouch();
            break;

        case State.BroomStart:
            handleBroomStart();
            break;

        case State.Broom:
            handleBroom();
            handleAttackInput();
            break;

        case State.Attack:
            handleAttack();
            handleMovement(isGrounded() ? 0f : 1.0f, false, false);
            break;

        //Hurt and Bonk look the same to the player, but have different effects
        case State.Bonk:
        case State.Hurt:
            bonk();
            break;

        case State.Reset:
            handleReset();
            break;

        case State.WaitMoveable:
            handleMovement(1, false, false);
            break;

        case State.WallJumpInit:
            wallJumpInit();
            break;

        case State.WallJump:
            handleWallJump();
            break;

        case State.Tornado:
            handleTornado();
            break;

        default:
            break;
        }
        //Debug.DrawLine(lastSafePosition, lastSafePosition + Vector3.up, Color.blue);
    }
    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;
        }
    }