예제 #1
0
    public bool checkChipDidSnap(TabletPuzzleChip chip)
    {
        // Remove the current chip from any quadrant
        foreach (TabletQuadrant q in this.quadrants)
        {
            q.removeChipIfNeeded(chip);
        }

        // Check if the chip is snapping to any quadrant
        bool didSnap = false;

        foreach (TabletQuadrant q in this.quadrants)
        {
            Vector3 chipPosition = chip.transform.position;
            Bounds  qBounds      = q.GetComponent <BoxCollider2D>().bounds;
            float   chipOffset   = chip.GetComponent <BoxCollider2D>().bounds.size.x / 2;

            if (chipPosition.x >= qBounds.min.x && chipPosition.x <= qBounds.center.x &&
                chipPosition.y >= qBounds.min.y && chipPosition.y <= qBounds.max.y)                   // Left
            // If there is a Chip there, bring it back to the board
            {
                if (q.leftChip != null && q.leftChip != chip)
                {
                    q.leftChip.reset();
                }
                q.leftChip = chip;
                // Set new position
                chip.transform.position = new Vector3(qBounds.center.x - chipOffset, qBounds.center.y, chip.transform.position.z);
                chip.turnOff();
                didSnap = true;
            }
            else if (chipPosition.x > qBounds.center.x && chipPosition.x <= qBounds.max.x &&
                     chipPosition.y >= qBounds.min.y && chipPosition.y <= qBounds.max.y)              // Right
            // If there is a Chip there, bring it back to the board
            {
                if (q.rightChip != null && q.rightChip != chip)
                {
                    q.rightChip.reset();
                }
                q.rightChip = chip;
                // Set new position
                chip.transform.position = new Vector3(qBounds.center.x + chipOffset, qBounds.center.y, chip.transform.position.z);
                chip.turnOff();
                didSnap = true;
            }
        }

        if (didSnap)
        {
            this.audioSource.PlayOneShot(this.snapAudioClip, 1);
        }

        this.checkDidWin();
        return(didSnap);
    }
예제 #2
0
    // Public methods

    // If this chip is on this quadrant, remove it
    public void removeChipIfNeeded(TabletPuzzleChip chip)
    {
        if (this.leftChip == chip)
        {
            this.leftChip = null;
        }
        else if (this.rightChip == chip)
        {
            this.rightChip = null;
        }
    }