Exemplo n.º 1
0
 private IEnumerator ResetPuzzle()
 {
     while (movesToUndo > 0)
     {
         ObjectMovements toUndo = undoScript.undoStack.Pop();
         toUndo.movedObject.GetComponent <MoveObject>().newPos = toUndo.oldPosition;
         movesToUndo--;
         yield return(new WaitForSecondsRealtime(0.25f));
     }
 }
Exemplo n.º 2
0
    void moveBoulder()
    {
        // Check where the object should be pushed (away from the player)
        // -------- (C) MATTHEW INGLIS 2019 ---------
        Vector2 playerToBoulder = transform.position - playerPos.position;
        float   angle           = Vector2.SignedAngle(Vector2.up, playerToBoulder);

        if (angle < 0)
        {
            angle = 360f + angle;
        }

        Vector3 dir = Vector3.zero;

        if (angle > 315 || angle <= 45)
        {
            dir = Vector3.up;
        }
        else if (angle > 135 && angle <= 225)
        {
            dir = Vector3.down;
        }
        else if (angle > 45 && angle <= 135)
        {
            dir = Vector3.left;
        }
        else if (angle > 225 && angle <= 315)
        {
            dir = Vector3.right;
        }
        // -------- END MATTHEW INGLIS

        // Check if the new position will be inside of any object
        RaycastHit2D hit = Physics2D.Raycast(transform.position, dir, 1.5f, LayerMask);

        // If it won't collide with anything, move it to the position
        if (hit.collider == null)
        {
            newPos += dir;
        }
        // Otherwise move it to the edge of the wall/collider
        else
        {
            if (dir == Vector3.up)
            {
                newPos = hit.point + new Vector2(0, -0.5f);
            }
            if (dir == Vector3.down)
            {
                newPos = hit.point + new Vector2(0, 0.5f);
            }
            if (dir == Vector3.left)
            {
                newPos = hit.point + new Vector2(0.5f, 0);
            }
            if (dir == Vector3.right)
            {
                newPos = hit.point + new Vector2(-0.5f, 0);
            }
        }
        if ((transform.position - newPos).magnitude > 0.01f)
        {
            ObjectMovements isMoved = new ObjectMovements();
            isMoved.movedObject = gameObject;
            isMoved.oldPosition = transform.position;
            undoScript.undoStack.Push(isMoved);
        }

        // Reset  the push timer
        pushTimer = 0;
    }