コード例 #1
0
    //Activates when translating is true and exits if either undo or confirm are pushed (if confirm results in a successful drop)
    void Update()
    {
        if (Translating && !PauseMenu.GameIsPaused && (!Selector.selecting))
        {
            translatingPressingTimer -= Time.deltaTime;

            int cpX = TranslatingMatrix.GetLength(0);
            int cpY = TranslatingMatrix.GetLength(1);
            int cpZ = TranslatingMatrix.GetLength(2);

            bool[,,] cleanMatrix = new bool[cpX, cpY, cpZ];

            if (translatingPressingTimer <= 0)
            {
                switch (CameraRotator.cameraOrientation)
                {
                case (0):
                    mirrorMove = new Vector2(x: move.x, y: move.y);
                    break;

                case (1):
                    mirrorMove = new Vector2(x: -move.y, y: move.x);
                    break;

                case (2):
                    mirrorMove = new Vector2(x: -move.x, y: -move.y);
                    break;

                case (3):
                    mirrorMove = new Vector2(x: move.y, y: -move.x);
                    break;
                }

                if (mirrorMove.x > 0.1 || mirrorMove.x < -0.1)
                {
                    if (mirrorMove.x > 0)
                    {
                        translatingPressingTimer = translatingPressingTime;

                        for (int y = 0; y < cpY; y++)
                        {
                            for (int z = 0; z < cpZ; z++)
                            {
                                if (TranslatingMatrix[(cpX - 1), y, z] == true)
                                {
                                    return;
                                }
                            }
                        }
                        for (int x = 1; x < cpX; x++)
                        {
                            for (int y = 0; y < cpY; y++)
                            {
                                for (int z = 0; z < cpZ; z++)
                                {
                                    cleanMatrix[x, y, z] = TranslatingMatrix[(x - 1), y, z];
                                }
                            }
                        }
                        TranslatingMatrix = cleanMatrix.Clone() as bool[, , ];
                        TranslatingObject.transform.Translate(1, 0, 0, Space.World);
                        AudioMan.Play("Translate");
                    }
                    else
                    {
                        translatingPressingTimer = translatingPressingTime;

                        for (int y = 0; y < cpY; y++)
                        {
                            for (int z = 0; z < cpZ; z++)
                            {
                                if (TranslatingMatrix[0, y, z] == true)
                                {
                                    return;
                                }
                            }
                        }

                        for (int x = 0; x < (cpX - 1); x++)
                        {
                            for (int y = 0; y < cpY; y++)
                            {
                                for (int z = 0; z < cpZ; z++)
                                {
                                    cleanMatrix[x, y, z] = TranslatingMatrix[(x + 1), y, z];
                                }
                            }
                        }
                        TranslatingMatrix = cleanMatrix.Clone() as bool[, , ];
                        TranslatingObject.transform.Translate(-1, 0, 0, Space.World);
                        AudioMan.Play("Translate");
                    }
                }
                else if (mirrorMove.y > 0.1 || mirrorMove.y < -0.1)
                {
                    if (mirrorMove.y > 0)
                    {
                        translatingPressingTimer = translatingPressingTime;

                        for (int x = 0; x < cpX; x++)
                        {
                            for (int y = 0; y < cpY; y++)
                            {
                                if (TranslatingMatrix[x, y, (cpZ - 1)] == true)
                                {
                                    return;
                                }
                            }
                        }
                        for (int x = 0; x < cpX; x++)
                        {
                            for (int y = 0; y < cpY; y++)
                            {
                                for (int z = 1; z < cpZ; z++)
                                {
                                    cleanMatrix[x, y, z] = TranslatingMatrix[x, y, (z - 1)];
                                }
                            }
                        }
                        TranslatingMatrix = cleanMatrix.Clone() as bool[, , ];
                        TranslatingObject.transform.Translate(0, 0, 1, Space.World);
                        AudioMan.Play("Translate");
                    }
                    else
                    {
                        translatingPressingTimer = translatingPressingTime;

                        for (int x = 0; x < cpX; x++)
                        {
                            for (int y = 0; y < cpY; y++)
                            {
                                if (TranslatingMatrix[x, y, 0] == true)
                                {
                                    return;
                                }
                            }
                        }

                        for (int x = 0; x < cpX; x++)
                        {
                            for (int y = 0; y < cpY; y++)
                            {
                                for (int z = 0; z < (cpZ - 1); z++)
                                {
                                    cleanMatrix[x, y, z] = TranslatingMatrix[x, y, (z + 1)];
                                }
                            }
                        }
                        TranslatingMatrix = cleanMatrix.Clone() as bool[, , ];
                        TranslatingObject.transform.Translate(0, 0, -1, Space.World);
                        AudioMan.Play("Translate");
                    }
                }
            }
        }
    }
コード例 #2
0
    //Checks from the bottom layer up to see if there is a valid place to drop (returns yes/no answer). Also it's important to note that the piece is dropped to the lowest level first.
    private bool AttemptDrop()
    {
        int cpX = TranslatingMatrix.GetLength(0);
        int cpY = TranslatingMatrix.GetLength(1);
        int cpZ = TranslatingMatrix.GetLength(2);

        //Assemble the piece coordinates
        int[,] pieceList = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };

        int pn = 0;

        for (int y = (cpY - 1); y > -1; y--)
        {
            for (int x = 0; x < cpX; x++)
            {
                for (int z = 0; z < cpZ; z++)
                {
                    if (TranslatingMatrix[x, y, z] == true)
                    {
                        pieceList[pn, 0] = x;
                        pieceList[pn, 1] = y;
                        pieceList[pn, 2] = z;
                        pn += 1;
                    }
                }
            }
        }



        int cbY = BoardMatrix.GetLength(1);

        int[,] tempPieceList = { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } };
        for (int i = 0; i < 4; i++)
        {
            tempPieceList[i, 0] = pieceList[i, 0];
            tempPieceList[i, 1] = pieceList[i, 1] + (cbY - 4);
            tempPieceList[i, 2] = pieceList[i, 2];
        }

        int  temp  = 0;
        bool works = true;

        for (int y = (cbY - 1); y > -1; y--)
        {
            for (int i = 0; i < 4; i++)
            {
                temp = tempPieceList[i, 1];

                if (y < (cbY - 1))
                {
                    tempPieceList[i, 1] = (temp - 1);
                }
                if (tempPieceList[i, 1] < 0)
                {
                    return(false);
                }
            }

            pieceList = tempPieceList;

            works = true;
            for (int i = 0; i < 4; i++)
            {
                if (BoardMatrix[tempPieceList[i, 0], tempPieceList[i, 1], tempPieceList[i, 2]] == true)
                {
                    works = false;
                    break;
                }
            }

            if (works)
            {
                for (int i = 0; i < 4; i++)
                {
                    BoardMatrix[tempPieceList[i, 0], tempPieceList[i, 1], tempPieceList[i, 2]] = true;
                }

                Vector3 distance = new Vector3(0, -(y + 1), 0);
                TranslatingObject.transform.Translate(distance, Space.World);
                return(true);
            }
        }

        return(false);
    }