コード例 #1
0
ファイル: Tetronimo.cs プロジェクト: ghsoares/Tetris-AI
    public override void _Draw()
    {
        float squareSize = gameInstance.squareSize;

        for (int y = 0; y < sizeY; y++)
        {
            for (int x = 0; x < sizeX; x++)
            {
                if (grid[y, x] == 1)
                {
                    DrawRect(
                        new Rect2(
                            (x + posX) * squareSize, (y + posY) * squareSize,
                            squareSize, squareSize
                            ),
                        TetrominosTable.GetColor(colorIdx)
                        );
                }
            }
        }
        int boundsSizeX = (boundsMaxX - boundsMinX) + 1;
        int boundsSizeY = (boundsMaxY - boundsMinY) + 1;

        /*DrawRect(new Rect2(
         *  (posX + boundsMinX) * squareSize, (posY + boundsMinY) * squareSize,
         *  boundsSizeX * squareSize, boundsSizeY * squareSize
         *  ),
         *  new Color(.25f, 1f, .25f, .5f)
         * );*/
    }
コード例 #2
0
ファイル: Tetronimo.cs プロジェクト: ghsoares/Tetris-AI
    public void UpdateGrid()
    {
        TetrominosTable.GetTetromino(
            (int)type, rotation, out grid, out sizeX, out sizeY, out int[] bounds
            );

        this.boundsMinX = bounds[0];
        this.boundsMinY = bounds[1];
        this.boundsMaxX = bounds[2];
        this.boundsMaxY = bounds[3];
    }
コード例 #3
0
ファイル: Tetronimo.cs プロジェクト: ghsoares/Tetris-AI
    public bool Rotate()
    {
        int rot = rotation;

        int[,] grid = null;
        int sizeX = 0;
        int sizeY = 0;

        int[] bounds  = null;
        int   posX    = this.posX;
        int   posY    = this.posY;
        bool  success = false;

        rot++;
        rot %= 4;
        TetrominosTable.GetTetromino(
            (int)type, rot, out grid, out sizeX, out sizeY, out bounds
            );

        for (int i = 0; i < 5; i++)
        {
            TetrominosTable.GetWallKickOffset(
                (int)type, rot, i, out int offX, out int offY
                );
            posX = this.posX + offX;
            posY = this.posY + offY;
            if (TestPosition(
                    posX, posY, grid, sizeX, sizeY, bounds[0], bounds[1], bounds[2], bounds[3]
                    ))
            {
                success = true;
                break;
            }
        }
        if (!success)
        {
            return(false);
        }

        this.posX       = posX;
        this.posY       = posY;
        this.rotation   = rot;
        this.grid       = grid;
        this.sizeX      = sizeX;
        this.sizeY      = sizeY;
        this.boundsMinX = bounds[0];
        this.boundsMinY = bounds[1];
        this.boundsMaxX = bounds[2];
        this.boundsMaxY = bounds[3];

        return(true);
    }
コード例 #4
0
    public override void _Draw()
    {
        /*Transform2D t = GetTransform();
         * t.origin = currentPosition;
         * VisualServer.CanvasItemSetTransform(GetCanvasItem(), t);*/

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                if (grid[y, x] != 0)
                {
                    DrawRect(
                        new Rect2(
                            x * squareSize, y * squareSize,
                            squareSize, squareSize
                            ),
                        TetrominosTable.GetColor(grid[y, x])
                        );
                }
            }
        }
    }