Пример #1
0
    private static void ProcessHorizontal(Grid grid, TetraminoMono tetraminoMono, Vector2Int offset)
    {
        if (offset.sqrMagnitude == 0)
        {
            return;
        }
        Tetramino tetraminoData = tetraminoMono.tetramino;

        //Vector2Int projectionDir = VectorUtil.V2_V2Int(((Vector2)offset).normalized);
        Vector2Int projectionDir                = offset;
        Vector2Int stopPosition                 = Grid.StopPosition(grid, tetraminoData, projectionDir);
        Vector2Int stopDeltaPosition            = stopPosition - tetraminoData.centerPos;
        int        stopDeltaPositionSqrManitude = stopDeltaPosition.sqrMagnitude;
        int        offsetPositionSqrManitude    = offset.sqrMagnitude;

        if (stopDeltaPositionSqrManitude < offsetPositionSqrManitude)
        {
            tetraminoMono.SetCenterPosition(stopPosition);
            Debug.Log("stopDeltaPositionSqrManitude < offsetPositionSqrManitude");
            // tetramino can't move because of grid blocks being occupied
        }
        else
        {
            tetraminoMono.TranslateCenterPosition(offset);
        }
    }
    private static void ProcessHorizontal(Grid grid, TetraminoMono tetraminoMono, Vector2Int offset)
    {
        if (offset.sqrMagnitude == 0)
        {
            return;
        }
        Tetramino tetraminoData = tetraminoMono.tetramino;
        //bool collision =
        //    Grid.Collision(grid, tetraminoData, offset, Tetramino.RotationType.None);
        //if (!collision)
        //{
        //    tetraminoMono.TranslateCenterPosition(offset);
        //}
        Vector2Int projectionDir                = VectorUtil.V2_V2Int(((Vector2)offset).normalized);
        Vector2Int stopPosition                 = Grid.StopPosition(Grid.Ins, tetraminoData, projectionDir);
        Vector2Int stopDeltaPosition            = stopPosition - tetraminoData.centerPos;
        int        stopDeltaPositionSqrManitude = stopDeltaPosition.sqrMagnitude;
        int        offsetPositionSqrManitude    = offset.sqrMagnitude;

        if ((stopDeltaPositionSqrManitude < offsetPositionSqrManitude))
        {
            tetraminoMono.SetCenterPosition(stopPosition);
            Debug.Log("stopDeltaPositionSqrManitude < offsetPositionSqrManitude");
        }
        else
        {
            tetraminoMono.TranslateCenterPosition(offset);
        }
    }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        bool update      = UpdateTimer(Time.deltaTime);
        bool instantMove = Input.GetKeyDown(KeyCode.Space);

        if (update || instantMove)
        {
            Grid       grid              = Grid.Ins;
            Tetramino  tetramino         = tetraminoMono.tetramino;
            Vector2Int offset            = Vector2Int.down;
            bool       spawnNewTetramino = false;
            if (instantMove)
            {
                //Vector2Int projectionPos = projection.projection.GetComponent<TetraminoMono>().tetramino.centerPos;
                //Vector2Int tetraminoPos = tetramino.centerPos;
                //offset = projectionPos - tetraminoPos;
                spawnNewTetramino = true;
            }
            else
            {
                bool collision = Grid.Collision(grid, tetramino, Vector2Int.down, Tetramino.RotationType.None);
                if (collision)
                {
                    //Debug.Log("collision");
                    spawnNewTetramino = true;
                }
                else
                {
                    tetraminoMono.TranslateCenterPosition(offset);
                }
            }
            if (spawnNewTetramino)
            {
                Tetramino tetraminoProjectionCopy = projection.DropProjection();  //TODO Check exact spawn time
                SpawnNewTetramino();
                SweepLine.Sweep(tetraminoProjectionCopy);
            }
        }
    }