Legacy GM Tetris destroy completed row, need help

B

BlazeDragon

Guest
I have basically a tetris like clone and I convert the blocks into 50x50 objects I call "obj_solid". I need to check these rows if they are all filled and delete them all...I have followed an online tutorial and it didn't help....it basically has me jumping to a position and check each one and repeating for number of rows and columns to check the whole grid....i tried with code and this is what I attempted....help please.

I have this in alarm[1] which I set to 1 at obj creation
Code:
var px = 200
var py = 1000
while (py > 150) {
    if (instance_position(px,py,obj_solid)) && 
    (instance_position(px+50,py,obj_solid)) &&
    (instance_position(px+100,py,obj_solid)) &&
    (instance_position(px+150,py,obj_solid)) &&
    (instance_position(px+200,py,obj_solid)) &&
    (instance_position(px+250,py,obj_solid)) &&
    (instance_position(px+300,py,obj_solid)) &&
    (instance_position(px+350,py,obj_solid)) &&
    (instance_position(px+400,py,obj_solid)) &&
    (instance_position(px+450,py,obj_solid)) &&
    (instance_position(px+500,py,obj_solid)) &&
    (instance_position(px+550,py,obj_solid)) &&
    (instance_position(px+600,py,obj_solid)) &&
    (instance_position(px+650,py,obj_solid)) &&
    (instance_position(px+700,py,obj_solid))
    {
        position_destroy(px,py);
        position_destroy(px+50,py);
        position_destroy(px+100,py);
        position_destroy(px+150,py);
        position_destroy(px+200,py);
        position_destroy(px+250,py);
        position_destroy(px+300,py);
        position_destroy(px+350,py);
        position_destroy(px+400,py);
        position_destroy(px+450,py);
        position_destroy(px+500,py);
        position_destroy(px+550,py);
        position_destroy(px+600,py);
        position_destroy(px+650,py);
        position_destroy(px+700,py);
    }
    else {
        py -= 50;
    }

}

alarm[1] = 1;
 

Bentley

Member
I wrote this super fast, so don't hold it against me if there's something I forgot. But this is how I'd approach it:
Code:
var cols = 8;
var rows = 10;
var block_count;
var offset_x = sprite_get_width(spr_block); // How far your blocks are horizontally apart
var offset_y = sprite_get_height(spr_block); // How far your blocks are vertically apart

for (var yy = 0; yy < rows; yy++)
{
    block_count = 0;

    for (var xx = 0; xx < cols; xx++)
    {
        if (position_meeting(xx * offset_x, yy * offset_y, obj_block))
        {
            block_count++;
        }
      
        // You'd probably throw a break in here the moment there's not a block as there's no need to continue checking this row

        if (block_count == cols)
        {
            //Row completed!
        }
    }
}
The idea is to check each row for a line of 8 (or however many columns there are in Tetris). Let's say were at row 0. We check every col across. At the end of that second for loop, if block_count is equal to the number of columns, we know that a row is filled. You could store their ID's in a list and destroy them if the row is completed.

You might find it much easier to use a grid instead of objects.
 
Last edited:
Top