Пример #1
0
    void PlacePiece()
    {
        PieceComponent[] pieces = CurrentPiece.GetPieces();
        for (int i = 0; i < pieces.Length; i++)
        {
            int finalX = Round(pieces[i].GetX()) + CurrentPiece.GetPositionX();
            int finalY = Round(pieces[i].GetY()) + CurrentPiece.GetPositionY();
            int finalZ = Round(pieces[i].GetZ()) + CurrentPiece.GetPositionZ();
            GameState[finalX, finalY, finalZ] = true;
            if (CheckForClear(finalY))
            {
                ClearLevel(finalY);
            }
        }
        GamePiece testNewPiece = new GamePiece();

        testNewPiece.SetPosition(PointerX, PointerY, PointerZ);
        if (CheckPosition(testNewPiece))
        {
            CurrentPiece = testNewPiece.Clone();
            CurrentColor = GradientColors.Evaluate(Random.value);
        }
        else
        {
            GameOver();
        }
        UpdateBoard();
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        HandleInput();

        //Handles the automatic progression of the game, when not paused or clearing
        if (!Paused && !Clearing)
        {
            DropClock += Time.deltaTime;

            //Drops the block down the vertical axis
            if (DropClock > DropTime)
            {
                DropClock = 0f;
                GamePiece testPiece = CurrentPiece.Clone();
                testPiece.MoveY(-1);
                if (CheckPosition(testPiece))
                {
                    MoveY(-1);
                }
                else
                {
                    PlacePiece();
                }
            }

            DifficultyClock += Time.deltaTime;

            //Speeds up block dropping as the game goes on
            if (DifficultyClock > DifficultyTime)
            {
                DifficultyClock = 0f;
                if (DropTimeDefault * 0.95f > DropTimeMin)
                {
                    DropTimeDefault *= 0.95f;
                    ClearTime        = DropTimeDefault;

                    if (!Input.GetKey(k_Drop))
                    {
                        DropTime = DropTimeDefault;
                    }
                }
            }
        }

        //Handles the clearing animation
        if (!Paused && Clearing)
        {
            ClearClock += Time.deltaTime;

            if (ClearClock > ClearTime)
            {
                for (int i = 0; i < ClearingLevels.Length; i++)
                {
                    if (ClearingLevels[i])
                    {
                        Instantiate(m_clearparticles, new Vector3(GridX / 2, i, GridZ / 2), Quaternion.identity);
                    }
                }
                PushDown();
                ClearClock = 0f;
                Clearing   = false;
            }
        }

        if (FreeSpin)
        {
            CameraAngleXZ += 15f * Time.deltaTime;
            if (CameraAngleXZ > 360f)
            {
                CameraAngleXZ -= 360f;
            }
        }

        if (NeedsUpdate)
        {
            UpdateBoard();
        }

        if (LastCameraAngleXY != CameraAngleXY || LastCameraAngleXZ != CameraAngleXZ || LastCameraTarget != CameraTarget)
        {
            PositionCamera();
        }
    }