Example #1
0
    // Update is called once per frame
    void Update()
    {
        horInput  = Input.GetAxisRaw("Horizontal");
        vertInput = Input.GetAxisRaw("Vertical");
        // even tho I'm clamping input, raw works better
        xMove = (int)Mathf.Clamp(horInput, -1, 1);
        yMove = (int)Mathf.Clamp(vertInput, -1, 1);

        if (xMove != 0)
        {
            transform.localScale = new Vector3(xMove, transform.localScale.y, transform.localScale.z);
        }

        if (Input.GetKey(KeyCode.R))
        {
            depthInput = 1;
        }
        else if (Input.GetKey(KeyCode.F))
        {
            depthInput = -1;
        }
        else
        {
            depthInput = 0;
        }

        if (Input.GetKeyDown(KeyCode.G) && !usingRope)
        {
            UseRope();
        }

        if ((Time.time > timeOfLastMovement + timeBetweenMovements) && (xMove != 0 || yMove != 0 || depthInput != 0) && playerControlled)
        {
            timeOfLastMovement = Time.time;

            desiredX = xPos + xMove;
            //desiredX = Mathf.Clamp(desiredX, 0, grid.xSize - 1);

            desiredY = yPos + yMove;
            //desiredY = Mathf.Clamp(desiredY, 0, grid.ySize - 1);

            desiredZ = zPos + depthInput;
            //desiredZ = Mathf.Clamp(desiredZ, 0, grid.zSize - 1);

            if (gridManager.IsSolid(desiredX, desiredY, desiredZ))
            {
                // try to sttack
                StartCoroutine(Smash(desiredX, desiredY, desiredZ));
            }
            else
            {
                CheckAnchor(xPos, yPos, zPos, desiredX, desiredY, desiredZ);
                xPos      = desiredX;
                yPos      = desiredY;
                zPos      = desiredZ;
                targetPos = gridManager.GetPosition(xPos, yPos, zPos);
                UpdateDepth();
                // move into new square
                UpdateGravity();
            }
        }
        if (!usingRope)
        {
            transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
        }
        else
        {
            spriteRenderer.sortingOrder = (int)transform.position.z * -10 + 5; // +5 to stay on top of blocks
            pickaxe.sortingOrder        = (int)transform.position.z * -10 + 6;
            int currentZ = (int)transform.position.z;
            if (currentZ != lastZLayer)
            {
                lastZLayer = currentZ;
                OnPlayerChangeLayer?.Invoke(lastZLayer);
            }
        }
        //transform.position = Vector3.MoveTowards(transform.position, )
    }
Example #2
0
 void UpdateDepth()
 {
     spriteRenderer.sortingOrder = -zPos * 10 + 5; // +5 to stay on top of blocks
     pickaxe.sortingOrder        = -zPos * 10 + 6;
     OnPlayerChangeLayer?.Invoke(zPos);
 }