Example #1
0
    void Update()
    {
        /*
         * Create tether point functionality
         */

        // Creating a tether point
        if (tetherUIState == TetherUIState.GAMEPLAY && !GameManager.isPlayerDead() && !GameManager.CameraIsZoomedOut() && GameManager.inst.pauseType == PauseType.NONE && !GameManager.isPlayerDashing() && !GameManager.GetPlayerScript().inPlaceTetherAnim())
        {
            if (PlayerControlManager.GetKeyDown(ControlInput.DROP_TETHER))
            {
                //CreatePoint();
                //GameManager.GetPlayer().GetComponent<Player>().setPlaceAnchorAnim();

                // Order flipped so the tether point exists for the screenshot
                // Test!
                CreatePoint();
            }
        }


        /*
         * Fast tethering functionality
         */

        // Keep track of the fast tether back key
        if (allowFastTether)
        {
            // These conditions determine whether tethering is allowed
            if (tetherUIState == TetherUIState.GAMEPLAY && !GameManager.isPlayerDead() && !GameManager.CameraIsZoomedOut() && !GameManager.isPlayerDashing() && !GameManager.isPaused())
            {
                // If the player presses the menu key, start the timer
                //if (Input.GetKeyDown(PlayerControlManager.LH_TetherMenu) || Input.GetKeyDown(PlayerControlManager.RH_TetherMenu))
                if (PlayerControlManager.GetKeyDown(ControlInput.TETHER_MENU))
                {
                    fastTetherKeyTimer = fastTetherKeyTime;
                }

                // If the menu button is released before the timer has reached zero, call a fast tether back
                //if (Input.GetKeyUp(PlayerControlManager.LH_TetherMenu) || Input.GetKeyUp(PlayerControlManager.RH_TetherMenu))
                if (PlayerControlManager.GetKeyUp(ControlInput.TETHER_MENU))
                {
                    OnFastTetherStart(LevelStateManager.curState);
                }
            }
        }
        else
        {
            fastTetherKeyTimer = 0;
        }

        // Update fastTetherKeyTimer
        if (fastTetherKeyTimer > 0)
        {
            fastTetherKeyTimer -= Time.deltaTime;
            if (fastTetherKeyTimer < 0)
            {
                fastTetherKeyTimer = 0;
            }
        }


        /*
         * Tether menu functionality
         */

        // Bringing up the tether menu
        // Adding the pause menu active check prevents the cursor from getting reverted to the gameplay cursor while the pause menu is up
        if ((tetherUIState == TetherUIState.GAMEPLAY || tetherUIState == TetherUIState.TETHER_MENU) && !PauseMenuManager.pauseMenuActive)
        {
            // Test for bringing up the menu, while alive
            if (!GameManager.isPlayerDead())
            {
                // If the tether menu key is held down
                //if (PlayerControlManager.GetKey(ControlInput.TETHER_MENU) && !GameManager.CameraIsZoomedOut() && fastTetherKeyTimer <= 0 && !GameManager.isPlayerDashing())
                if (PlayerControlManager.GetKey(ControlInput.TETHER_MENU) && fastTetherKeyTimer <= 0 && tetherMenuDisableTimer == 0 && !GameManager.isPlayerDashing() && (GameManager.inst.pauseType == PauseType.NONE || GameManager.inst.pauseType == PauseType.TETHER_MENU))
                {
                    tetherUIState = TetherUIState.TETHER_MENU;
                    //GameManager.setPause(true);
                    if (GameManager.inst.pauseType == PauseType.NONE)
                    {
                        GameManager.inst.EnterPauseState(PauseType.TETHER_MENU);
                    }

                    CursorManager.inst.lockCursorType = true;
                    CursorManager.inst.cursorState    = CursorState.MENU;
                    ShowTetherMenu();
                }
                else
                {
                    tetherUIState = TetherUIState.GAMEPLAY;

                    //GameManager.setPause(false);
                    if (GameManager.inst.pauseType == PauseType.TETHER_MENU)
                    {
                        GameManager.inst.ExitPauseState();
                        //Debug.Log("ExitPauseState()");
                    }

                    CursorManager.inst.lockCursorType = false;
                    CursorManager.inst.OnCursorBoundsUpdated();
                    HideTetherMenu();
                }
            }
            // If the player is dead, force the menu to come up
            else
            {
                tetherUIState = TetherUIState.TETHER_MENU;
                //GameManager.setPause(true);
                GameManager.inst.EnterPauseState(PauseType.TETHER_MENU);
                CursorManager.inst.lockCursorType = true;
                CursorManager.inst.cursorState    = CursorState.MENU;
                ShowTetherMenu();
            }
        }

        /*
         * Tether Corner HUD visibility
         */

        if (tetherHUDVisible)
        {
            tetherHUDGroup.alpha = Mathf.Lerp(tetherHUDGroup.alpha, 1, tetherHUDFadeInSpeed * Time.deltaTime);
        }
        else
        {
            tetherHUDGroup.alpha = Mathf.Lerp(tetherHUDGroup.alpha, 0, tetherHUDFadeOutSpeed * Time.deltaTime);
        }

        /*
         * Tether Corner HUD fading when zooming out
         */

        // When zooming/zoomed out, hide the bottom left time tether HUD
        // JK let's not do this

        /*
         * if (GameManager.CameraIsZoomedOut())
         * {
         * tetherHUDGroup.alpha = Mathf.Lerp(tetherHUDGroup.alpha, 0, tetherHUDFadeOutSpeed * Time.deltaTime);
         * }
         * // When zooming back in or not zoomed, reveal the bottom left time tether HUD
         * else
         * {
         * tetherHUDGroup.alpha = Mathf.Lerp(tetherHUDGroup.alpha, 1, tetherHUDFadeInSpeed * Time.deltaTime);
         * }
         */


        /*
         * Other Update Stuff
         */

        UpdateTimeArrowPos();
        //ScreenshotManager.inst.UpdateScreenshotState();

        if (tetherUIState == TetherUIState.TETHER_MENU)
        {
            if (menuLight != null && menuLightOn != null)
            {
                menuLight.sprite = menuLightOn;
            }
        }
        else
        {
            if (menuLight != null && menuLightOff != null)
            {
                menuLight.sprite = menuLightOff;
            }
        }


        // End level tether point collection
        // Once all indicator return objects have returned to the player and been destroyed, this will allow EndLevelAllTetherPointdCollected to return true
        if (endLevelWaitForCollection)
        {
            if (IndicatorReturnObject.NoInstancesExist())
            {
                endLevelWaitForCollection = false;
            }
        }

        if (tetherMenuDisableTimer > 0)
        {
            tetherMenuDisableTimer -= Time.deltaTime;
            if (tetherMenuDisableTimer < 0)
            {
                // Don't allow the timer to reach 0 until the tether menu key has been released
                if (PlayerControlManager.GetKey(ControlInput.TETHER_MENU))
                {
                    tetherMenuDisableTimer = 0.1f;
                }
                else
                {
                    tetherMenuDisableTimer = 0f;
                }
            }
        }
    }
Example #2
0
    void updateZoomPan(bool panToTarget)
    {
        if (panToTarget)
        {
            panOffset = Vector2.Lerp(panOffset, Vector2.zero, 0.2f);
        }
        else
        {
            // Used to avoid double inputs stacking from both mouse and keyboard
            // 0 = right, 1 = left, 2 = top, 3 = bottom
            bool[] dirs = new bool[4];

            if (useCursorPan && GameManager.inst.pauseType == PauseType.ZOOM)
            {
                // Horizontal pan
                // Right side
                if (!atRightBound && Input.mousePosition.x > Screen.width - Screen.width / horizScrollPercDivisor)
                {
                    panOffset += new Vector2(panSpeed * Time.deltaTime, 0);
                    dirs[0]    = true;
                }
                // Left side
                else if (!atLeftBound && Input.mousePosition.x < 0 + Screen.width / horizScrollPercDivisor)
                {
                    panOffset -= new Vector2(panSpeed * Time.deltaTime, 0);
                    dirs[1]    = true;
                }

                // Vertical pan
                // Top side
                if (!atTopBound && Input.mousePosition.y > Screen.height - Screen.height / vertScrollPercDivisor)
                {
                    panOffset += new Vector2(0, panSpeed * Time.deltaTime);
                    dirs[2]    = true;
                }
                // Bottom side
                else if (!atBottomBound && Input.mousePosition.y < 0 + Screen.width / vertScrollPercDivisor)
                {
                    panOffset -= new Vector2(0, panSpeed * Time.deltaTime);
                    dirs[3]    = true;
                }
            }
            if (useKeyboardPan && GameManager.inst.pauseType == PauseType.ZOOM)
            {
                // Horizontal pan
                // Right side
                if (!atRightBound && PlayerControlManager.GetKey(ControlInput.RIGHT) && !dirs[0])
                {
                    panOffset += new Vector2(panSpeed * Time.deltaTime, 0);
                }
                // Left side
                else if (!atLeftBound && PlayerControlManager.GetKey(ControlInput.LEFT) && !dirs[1])
                {
                    panOffset -= new Vector2(panSpeed * Time.deltaTime, 0);
                }

                // Vertical pan
                // Top side
                if (!atTopBound && PlayerControlManager.GetKey(ControlInput.UP) && !dirs[2])
                {
                    panOffset += new Vector2(0, panSpeed * Time.deltaTime);
                }
                // Bottom side
                else if (!atBottomBound && PlayerControlManager.GetKey(ControlInput.DOWN) && !dirs[3])
                {
                    panOffset -= new Vector2(0, panSpeed * Time.deltaTime);
                }
            }
        }

        //Debug.Log("panOffset: " + panOffset);
        //cam.transform.localPosition = Vector3.Lerp(cam.transform.localPosition, new Vector3 (panOffset.x, panOffset.y, cam.transform.localPosition.z), 10 * Time.deltaTime);
        cam.transform.localPosition = new Vector3(panOffset.x, panOffset.y, cam.transform.localPosition.z);
    }
Example #3
0
    /// <summary>
    /// Standard movement behavior for the Player.
    /// DON'T CALL THIS
    /// </summary>
    public void move()
    {
        Vector2 movementVector = Vector2.zero;

        if (PlayerControlManager.GetKey(ControlInput.UP)) // UP
        {
            movementVector += Vector2.up;
        }
        if (PlayerControlManager.GetKey(ControlInput.LEFT)) // LEFT
        {
            movementVector += Vector2.left;
        }
        if (PlayerControlManager.GetKey(ControlInput.DOWN))         // DOWN
        {
            movementVector += Vector2.down;
        }
        if (PlayerControlManager.GetKey(ControlInput.RIGHT)) // RIGHT
        {
            movementVector += Vector2.right;
        }

        //update animator on movement direction, if we're moving
        if (movementVector != Vector2.zero)
        {
            float zRot = Vector2.SignedAngle(Vector2.right, movementVector);
            zRot += zRot < 0f ? 360f : 0f;
            int quadrant = (int)((zRot / 360f) * 4f);
            anim.SetInteger("Direction", quadrant + 1);
        }

        movementVector     = movementVector.normalized * getSelf().getMovespeed() * Time.deltaTime;
        physbody.velocity += movementVector;
        if (physbody.velocity.magnitude > getSelf().getMovespeed())
        {
            physbody.velocity = physbody.velocity.normalized * getSelf().getMovespeed();
        }

        // Wall check / check for moving platforms
        RaycastHit2D[]  hits     = new RaycastHit2D[1];
        int             hitCount = 0;
        ContactFilter2D cf       = new ContactFilter2D();

        cf.SetLayerMask(moveMask);
        hitCount = GetComponent <Collider2D>().Cast(movementVector, cf, hits, getSelf().getMovespeed() * Time.deltaTime);

        //Check for Pits/platforms
        Collider2D[]    pitsFound      = new Collider2D[1];
        Collider2D[]    platformsFound = new Collider2D[1];
        int             pitCount       = 0;
        int             platformCount  = 0;
        ContactFilter2D pitFilter      = new ContactFilter2D();
        ContactFilter2D platformFilter = new ContactFilter2D();

        pitFilter.SetLayerMask(1 << LayerMask.NameToLayer("Pits"));
        pitFilter.useTriggers = true;
        platformFilter.SetLayerMask(1 << LayerMask.NameToLayer("SkyEnts"));
        platformFilter.useTriggers = true;

        Vector2 colSize  = gameObject.GetComponent <BoxCollider2D> ().size;
        Vector2 moveVect = new Vector2(movementVector.normalized.x * colSize.x * 0.5f, movementVector.normalized.y * colSize.y);

        platformCount = Physics2D.OverlapBox((Vector3)GetComponent <Collider2D>().offset + transform.position + (Vector3)(moveVect), GetComponent <BoxCollider2D>().size, 0, platformFilter, platformsFound);
        pitCount      = Physics2D.OverlapBox((Vector3)GetComponent <Collider2D>().offset + transform.position + (Vector3)(moveVect), GetComponent <BoxCollider2D>().size, 0, pitFilter, pitsFound);

        TESTPOSITION = (Vector3)GetComponent <Collider2D> ().offset + transform.position + (Vector3)(moveVect);
        TESTSIZE     = GetComponent <BoxCollider2D> ().size;

        bool seesPlatform = false;

        for (int i = 0; i < platformsFound.Length; i++)
        {
            if (platformsFound[i] != null)
            {
                if (platformsFound [i].CompareTag("MovingPlatform"))
                {
                    seesPlatform = true;
                }
            }
        }

        bool seesPit = (pitCount > 0 && !seesPlatform);

        //if there are no walls or pits, move
        if (hitCount <= 0 && !seesPit && movementVector != Vector2.zero)
        {
            transform.Translate((Vector3)movementVector);
            anim.SetBool("isMoving", true);
        }
        else
        {
            anim.SetBool("isMoving", false);
        }

        //if there are no walls and there is a pit, incriment the pit timer
        if (seesPit && hitCount <= 0)
        {
            anim.SetBool("Stumbling", true);
            physbody.velocity -= (physbody.velocity * pitSpeedAdjustment);
            pitTimer          += Time.deltaTime;
        }
        else
        {
            anim.SetBool("Stumbling", false);
            pitTimer = 0;
        }

        //if the pit timer fills, kill the player
        if (pitTimer >= pitFallDelay || (seesPit && movementVector == Vector2.zero) || (movementVector != Vector2.zero && !CheckForGround()))
        {
            transform.position = transform.position + (Vector3)(moveVect * 3);
            anim.SetTrigger("Fall");
            getSelf().onDeath();
        }
    }
Example #4
0
    /// <summary>
    /// Checks the keyboard for movement input.
    /// </summary>
    void getInput()
    {
        if (!_beingPushed && _playerInRange && !GameManager.isPaused() && _stasisTimer == 0)
        {
            //Move in direction if key is pressed
            switch (_moveDirection)
            {
            case Direction.Up:
                if (PlayerControlManager.GetKey(ControlInput.UP))
                {
                    move(_moveDirection);
                }
                break;

            case Direction.Right:
                if (PlayerControlManager.GetKey(ControlInput.RIGHT))
                {
                    move(_moveDirection);
                }
                break;

            case Direction.Down:
                if (PlayerControlManager.GetKey(ControlInput.DOWN))
                {
                    move(_moveDirection);
                }
                break;

            case Direction.Left:
                if (PlayerControlManager.GetKey(ControlInput.LEFT))
                {
                    move(_moveDirection);
                }
                break;
            }
        }
        if (_beingPushed)
        {
            if (!_playerInRange || !_canMove || GameManager.isPaused() || inStasis || CheckPath() || _stasisTimer > 0)
            {
                stop();
            }
            //stop moving when key is released
            switch (_moveDirection)
            {
            case Direction.Up:
                if (!PlayerControlManager.GetKey(ControlInput.UP))
                {
                    stop();
                }
                break;

            case Direction.Right:
                if (!PlayerControlManager.GetKey(ControlInput.RIGHT))
                {
                    stop();
                }
                break;

            case Direction.Down:
                if (!PlayerControlManager.GetKey(ControlInput.DOWN))
                {
                    stop();
                }
                break;

            case Direction.Left:
                if (!PlayerControlManager.GetKey(ControlInput.LEFT))
                {
                    stop();
                }
                break;
            }
        }
    }