Example #1
0
    bool collide(tetromino te, int new_rot, int new_x, int new_y)
    {
        bool           res  = false;
        int            row  = 0;
        int            col  = 0;
        int            b_i  = 0;
        tetromino_type type = this.tetrominoes[te.type];
        uint           rot  = type.rot[new_rot];

        for (uint b = 0x8000; b > 0; b = b >> 1, ++b_i)
        {
            int  index   = (int)((new_x + col) + ((new_y + row)) * COL_COUNT);
            bool collide = false;
            if (index < (this.gr.gc.Length - 1) && index >= 0)
            {
                grid_case gc = this.gr.gc[index];
                collide = (gc.color != 0xFFFFFFFF) && (!gc.is_cur);
            }
            bool border = ((new_y + row) < 0) || ((new_x + col) < 0) || ((new_x + col) >= COL_COUNT);
            if (((rot & b) > 0) && (border || collide))
            {
                res = true;
                break;
            }
            if (++col == 4)
            {
                ++row;
                col = 0;
            }
        }

        return(res);
    }
Example #2
0
    void rotate(tetromino te, int new_rot)
    {
        int            row         = 0;
        int            col         = 0;
        tetromino_type type        = this.tetrominoes[te.type];
        uint           rot         = type.rot[te.rotation];
        uint           desired_rot = type.rot[new_rot];

        for (uint b = 0x8000; b > 0; b = b >> 1)
        {
            int index = (int)((te.pos_x + col) + ((te.pos_y + row) * COL_COUNT));
            if (index >= 0 && index < this.gr.gc.Length - 1)
            {
                if ((rot & b) > 0)
                {
                    this.gr.gc[index].color  = 0xFFFFFFFF;
                    this.gr.gc[index].is_cur = false;
                }
                if ((desired_rot & b) > 0)
                {
                    this.gr.gc[index].color  = type.color;
                    this.gr.gc[index].is_cur = true;
                }
            }
            if (++col == 4)
            {
                ++row;
                col = 0;
            }
        }
    }
Example #3
0
    void move(tetromino te, int new_x, int new_y)
    {
        int            row  = 0;
        int            col  = 0;
        tetromino_type type = this.tetrominoes[te.type];

        for (uint b = 0x8000; b > 0; b = b >> 1)
        {
            if ((type.rot[te.rotation] & b) > 0)
            {
                int old_index = (int)((te.pos_x + col) + ((te.pos_y + row) * COL_COUNT));
                int new_index = (int)((new_x + col) + ((new_y + row) * COL_COUNT));
                if (old_index >= 0 && old_index < this.gr.gc.Length - 1)
                {
                    this.gr.gc[old_index].color  = 0xFFFFFFFF;
                    this.gr.gc[old_index].is_cur = false;
                }
                if (new_index >= 0 && new_index < this.gr.gc.Length - 1)
                {
                    this.gr.gc[new_index].color  = type.color;
                    this.gr.gc[new_index].is_cur = true;
                }
            }

            if (++col == 4)
            {
                ++row;
                col = 0;
            }
        }
    }
Example #4
0
    tetromino next_tetromino()
    {
        for (int i = 0; i < this.gr.gc.Length; ++i)
        {
            this.gr.gc[i].is_cur = false;
        }
        tetromino res;

        res.pos_x      = 3;
        res.pos_y      = (int)ROW_COUNT - 2;
        res.rotation   = 0;
        res.type       = this.next_type;
        this.next_type = Random.Range(0, 7);
        int row = 0;

        for (int y = 0; y < 4; ++y)
        {
            for (int x = 0; x < 4; ++x)
            {
                int            index = (x + row) * 4;
                int            mask  = 0x8000 >> (x + row);
                tetromino_type type  = this.tetrominoes[this.next_type];
                Color32        color = ((type.rot[0] & mask) > 0) ? argb_to_unity_color32(type.color) : this.next_base_color;
                this.next_t_mesh.colors[index + 0] = color;
                this.next_t_mesh.colors[index + 1] = color;
                this.next_t_mesh.colors[index + 2] = color;
                this.next_t_mesh.colors[index + 3] = color;
            }
            row += 4;
        }
        send_tetris_mesh_to_mesh(this.next_t_mesh, this.next_mesh);
        move(res, res.pos_x, res.pos_y);
        return(res);
    }