Пример #1
0
    // change what cells a Tetromino appears in from previous coords to newpoints
    void UpdateCells(Tetromino activeblock, List <Vector2> newpoints)
    {
        List <CellObject> newCells = new List <CellObject>();

        foreach (Vector2 point in activeblock.GetAllPoints())
        {
            CellObject cell = getCellAtPos(point);
            if (cell != null)
            {
                cell.changeColor(Color.white);
            }
        }

        foreach (Vector2 point in newpoints)
        {
            newCells.Add(getCellAtPos(point));
        }

        foreach (CellObject newcell in newCells)
        {
            if (newcell != null)
            {
                newcell.changeColor(activeblock.BlockColor);
            }
        }
    }
Пример #2
0
    void SpacePress(Tetromino activeblock)
    {
        int collisResult = -1;
        int distance;

        List <Vector2> newpoints   = new List <Vector2>();
        List <Vector2> finalpoints = new List <Vector2>();

        for (distance = 0; collisResult != 1; distance++)
        {
            List <Vector2> testpoints = new List <Vector2>();

            foreach (Vector2 point in activeblock.GetAllPoints())
            {
                Vector2 testpoint = new Vector2(point.x, point.y - distance);
                testpoints.Add(testpoint);
            }

            collisResult = CheckCollision(testpoints);
            newpoints    = testpoints;
        }

        // add 1 back because of grid start at 0
        foreach (Vector2 point in newpoints)
        {
            Vector2 finalpoint = new Vector2(point.x, point.y + 1);
            finalpoints.Add(finalpoint);
        }

        SetCellsOccupied(finalpoints);
        UpdateCells(activeblock, finalpoints);
        block = SpawnBlock();
    }