Build • test • document

A falling-block game,
from the ground up.

A complete GameMaker GML tutorial for a 64 × 64 grid, intentionally uneven graphics, reliable rotation and a traditional next-piece, score and level panel.

9 stages8 log checkpoints32 test casesSRS quarter-turn rotationWorks offline

Stage 1

Create the project, objects and room

Build a falling-block game in GameMaker using GML Code. This guide uses modern 2.3+ function syntax, seven four-cell shapes and a traditional 10-column × 20-row board. It assumes no existing game code. Work in order: each stage finishes with a runnable checkpoint.

Your graphics: no attached graphics were available when this guide was prepared. The illustrations are examples, not edits of your files. First build with the included coloured placeholders, then follow Stage 7 to prepare and connect your artwork.
  1. Create a blank GameMaker project named GridDrop. Select GML Code, not GML Visual. Avoid a physics template.
  2. Create a room named rm_game. Set its width to 1152 and height to 1408. Make it the first/start room in Room Order.
  3. Leave room physics and cameras/viewports disabled for this version. Use normal room coordinates for all drawing.
  4. Create an object named obj_game. Assign no sprite and no collision mask. Leave Solid and Persistent off. Leave Visible on so its Draw event executes.
  5. In the room, add/select an Instance Layer named Instances. Place exactly one obj_game instance at (0,0).
  6. Set the game speed to 60 frames per second in Game Options. On a smaller screen, optionally add window_set_size(576,704); at the top of Create for the desktop target. Keep the logical room at 1152 × 1408. Menu wording can vary by IDE release.

The board's top-left is (64,64), its interior measures 640 × 1280, and its outer boundary ends at (704,1344). The side panel starts at x=768. Scaling the whole room to a smaller window changes displayed pixel size, not the 64-pixel logical grid.

(64,64) · 10 × 20 cellsNEXTSCORE 0000LEVEL 1LINES 0Room: 1152 × 1408Cell: 64 × 64 logical pxBoard: 640 × 1280Layout illustration · not a screenshot
The board occupies most of the room. Measure the grid interior separately from any decorative border.
ResourcePurpose
obj_gameOwns board state, input, active/next pieces, rules and drawing.
scr_tetromino_dataA script containing cell-coordinate and rotation-offset functions, created next.
Nine optional spritesSeven cell styles, grid background and next-panel frame; added in Stage 7.

No individual falling-block, floor or wall objects are needed. An occupancy array provides their collisions. This separates the uneven painted edges from exact square gameplay footprints.

Stage 2

Create the grid, logical masks and drawing

Grid coordinates are whole-number columns and rows. Room coordinates are pixels. Store 24 rows: four hidden rows plus twenty visible rows. Stored row 4 is therefore the first visible row.

pixel_x = 64 + column × 64
pixel_y = 64 + (stored_row − 4) × 64
array_index = stored_row × 10 + column

Every board cell stores -1 for empty or a shape ID from 0 to 6. Each active piece has four local [column,row] offsets. It stays separate from the board until it locks. Movement tests all four candidate cells before changing its position.

  1. Create a Script asset named scr_tetromino_data. Delete its default contents and paste the complete script below. Do not wrap these functions in another function.
  2. Open obj_game → Add Event → Create. Paste Part A.
  3. Add a Step event. Paste the Stage 2 Step code.
  4. Add a normal Draw event. Paste the Draw code. Leave Draw GUI empty.
Why the shape origin and rotation matrix matter

T/J/L/S/Z rotate in a 3 × 3 matrix about (1,1); I rotates in a 4 × 4 matrix about (1.5,1.5). O keeps the same occupied squares. The clockwise coordinate rule is (x,y) → (n−1−y,x), because screen Y increases downwards. The matrix origin can sit left of the first occupied cell: do not clamp that origin to zero.

Script asset · complete contents
// Script asset scr_tetromino_data: replace default contents.
// IDs: I=0 O=1 T=2 S=3 Z=4 J=5 L=6.
function tet_cells(_type,_rot) {
    var _base=[
        [[0,1],[1,1],[2,1],[3,1]],
        [[1,0],[2,0],[1,1],[2,1]],
        [[1,0],[0,1],[1,1],[2,1]],
        [[1,0],[2,0],[0,1],[1,1]],
        [[0,0],[1,0],[1,1],[2,1]],
        [[0,0],[0,1],[1,1],[2,1]],
        [[2,0],[0,1],[1,1],[2,1]]
    ];
    var _out=[];
    var _n=(_type==0) ? 4 : 3;
    for(var _i=0;_i<4;_i++) {
        var _cx=_base[_type][_i][0];
        var _cy=_base[_type][_i][1];
        if(_type!=1) for(var _r=0;_r<_rot;_r++) {
            var _oldx=_cx; _cx=_n-1-_cy; _cy=_oldx;
        }
        array_push(_out,[_cx,_cy]);
    }
    return _out;
}
function tet_kicks(_type,_from,_to) {
    // SRS offsets converted to positive Y DOWN. Do not invert again.
    var _key=_from*4+_to;
    if(_type==1) return [[0,0]];
    if(_type==0) {
        switch(_key) {
            case 1: return [[0,0],[-2,0],[1,0],[-2,1],[1,-2]];
            case 4: return [[0,0],[2,0],[-1,0],[2,-1],[-1,2]];
            case 6: return [[0,0],[-1,0],[2,0],[-1,-2],[2,1]];
            case 9: return [[0,0],[1,0],[-2,0],[1,2],[-2,-1]];
            case 11: return [[0,0],[2,0],[-1,0],[2,-1],[-1,2]];
            case 14: return [[0,0],[-2,0],[1,0],[-2,1],[1,-2]];
            case 12: return [[0,0],[1,0],[-2,0],[1,2],[-2,-1]];
            case 3: return [[0,0],[-1,0],[2,0],[-1,-2],[2,1]];
        }
    } else {
        switch(_key) {
            case 1: return [[0,0],[-1,0],[-1,-1],[0,2],[-1,2]];
            case 4: return [[0,0],[1,0],[1,1],[0,-2],[1,-2]];
            case 6: return [[0,0],[1,0],[1,1],[0,-2],[1,-2]];
            case 9: return [[0,0],[-1,0],[-1,-1],[0,2],[-1,2]];
            case 11: return [[0,0],[1,0],[1,-1],[0,2],[1,2]];
            case 14: return [[0,0],[-1,0],[-1,1],[0,-2],[-1,-2]];
            case 12: return [[0,0],[-1,0],[-1,1],[0,-2],[-1,-2]];
            case 3: return [[0,0],[1,0],[1,-1],[0,2],[1,2]];
        }
    }
    return [[0,0]];
}
obj_game → Create · Part A
// Part A: obj_game Create event. Later parts are appended below.
cell_size=64; cols=10; visible_rows=20; hidden_rows=4;
rows=visible_rows+hidden_rows;
board_x=64; board_y=64; panel_x=768;
game_score=0; game_level=1; total_lines=0;
active_type=2; active_rot=0; active_x=3; active_y=hidden_rows;
next_type=0; game_over=false; paused=false;
debug_grid=true; ghost_enabled=false; use_art=false;
cell_sprites=[-1,-1,-1,-1,-1,-1,-1];
grid_sprite=-1; next_sprite=-1;
fall_timer=0; lock_timer=0; lock_resets=0;
lock_delay=0.5; max_lock_resets=15;
move_dir=0; repeat_timer=0; das_delay=0.15; arr_delay=0.05;
piece_colours=[
    make_colour_rgb(65,205,225),make_colour_rgb(245,205,60),
    make_colour_rgb(177,107,245),make_colour_rgb(100,205,112),
    make_colour_rgb(242,100,115),make_colour_rgb(80,140,245),
    make_colour_rgb(245,165,65)
];
reset_board=function() {
    // Flat array: avoids sharing references to nested row arrays.
    board=array_create(cols*rows,-1);
};
fits=function(_type,_rot,_x,_y) {
    var _cells=tet_cells(_type,_rot);
    for(var _i=0;_i<4;_i++) {
        var _cx=_x+_cells[_i][0];
        var _cy=_y+_cells[_i][1];
        // Bounds must be checked BEFORE reading the array.
        if(_cx<0 || _cx>=cols || _cy<0 || _cy>=rows) return false;
        if(board[_cy*cols+_cx]!=-1) return false;
    }
    return true;
};
try_move=function(_dx,_dy) {
    if(!fits(active_type,active_rot,active_x+_dx,active_y+_dy)) return false;
    active_x+=_dx; active_y+=_dy;
    return true;
};
draw_cell=function(_type,_px,_py,_scale,_alpha) {
    var _spr=cell_sprites[_type];
    if(use_art && sprite_exists(_spr)) {
        // Artwork canvas 80x80, origin (8,8), logical cell 64x64.
        draw_sprite_ext(_spr,0,_px,_py,_scale,_scale,0,c_white,_alpha);
    } else {
        draw_set_alpha(_alpha); draw_set_colour(piece_colours[_type]);
        draw_rectangle(_px+2*_scale,_py+2*_scale,
            _px+62*_scale,_py+62*_scale,false);
        draw_set_alpha(1);
    }
};
draw_piece=function(_type,_rot,_gx,_gy,_alpha) {
    var _cells=tet_cells(_type,_rot);
    for(var _i=0;_i<4;_i++) {
        var _cx=_gx+_cells[_i][0]; var _cy=_gy+_cells[_i][1];
        if(_cy>=hidden_rows && _cy<rows)
            draw_cell(_type,board_x+_cx*cell_size,
                board_y+(_cy-hidden_rows)*cell_size,1,_alpha);
    }
};
draw_preview=function() {
    var _cells=tet_cells(next_type,0);
    var _minx=4,_maxx=0,_miny=4,_maxy=0;
    for(var _i=0;_i<4;_i++) {
        _minx=min(_minx,_cells[_i][0]); _maxx=max(_maxx,_cells[_i][0]);
        _miny=min(_miny,_cells[_i][1]); _maxy=max(_maxy,_cells[_i][1]);
    }
    var _s=48;
    var _left=panel_x+(320-(_maxx-_minx+1)*_s)*0.5;
    var _top=180+(192-(_maxy-_miny+1)*_s)*0.5;
    for(var _j=0;_j<4;_j++)
        draw_cell(next_type,_left+(_cells[_j][0]-_minx)*_s,
            _top+(_cells[_j][1]-_miny)*_s,_s/cell_size,1);
};
reset_board();
obj_game → Step · Stage 2 · complete event
// Stage 2 Step: manual movement only.
if(keyboard_check_pressed(vk_f1)) debug_grid=!debug_grid;
if(keyboard_check_pressed(vk_left)) try_move(-1,0);
if(keyboard_check_pressed(vk_right)) try_move(1,0);
if(keyboard_check_pressed(vk_down)) try_move(0,1);
obj_game → normal Draw · retain this event throughout
// obj_game Draw event: use unchanged from Stage 2 onwards.
draw_set_alpha(1); draw_set_halign(fa_left); draw_set_valign(fa_top);
draw_clear(make_colour_rgb(12,18,30));
draw_set_colour(make_colour_rgb(20,29,45));
draw_rectangle(board_x,board_y,board_x+cols*cell_size,
    board_y+visible_rows*cell_size,false);
if(use_art && sprite_exists(grid_sprite)) draw_sprite(grid_sprite,0,board_x,board_y);
for(var _ry=hidden_rows;_ry<rows;_ry++) {
    for(var _rx=0;_rx<cols;_rx++) {
        var _type=board[_ry*cols+_rx];
        if(_type!=-1) draw_cell(_type,board_x+_rx*cell_size,
            board_y+(_ry-hidden_rows)*cell_size,1,1);
    }
}
if(ghost_enabled && !game_over) {
    var _ghost_y=active_y;
    while(fits(active_type,active_rot,active_x,_ghost_y+1)) _ghost_y++;
    draw_piece(active_type,active_rot,active_x,_ghost_y,0.22);
}
draw_piece(active_type,active_rot,active_x,active_y,1);
if(debug_grid) {
    draw_set_alpha(0.4); draw_set_colour(c_white);
    for(var _gx=0;_gx<=cols;_gx++)
        draw_line(board_x+_gx*cell_size,board_y,
            board_x+_gx*cell_size,board_y+visible_rows*cell_size);
    for(var _gy=0;_gy<=visible_rows;_gy++)
        draw_line(board_x,board_y+_gy*cell_size,board_x+cols*cell_size,
            board_y+_gy*cell_size);
    draw_set_alpha(1); draw_set_colour(c_lime);
    var _cells=tet_cells(active_type,active_rot);
    for(var _i=0;_i<4;_i++) {
        var _cy=active_y+_cells[_i][1];
        if(_cy>=hidden_rows && _cy<rows) {
            var _px=board_x+(active_x+_cells[_i][0])*cell_size;
            var _py=board_y+(_cy-hidden_rows)*cell_size;
            draw_rectangle(_px,_py,_px+63,_py+63,true);
        }
    }
}
draw_set_colour(c_white); draw_rectangle(panel_x,64,panel_x+320,480,true);
if(use_art && sprite_exists(next_sprite)) draw_sprite(next_sprite,0,panel_x,64);
draw_set_colour(c_white); draw_text(panel_x+24,96,"NEXT"); draw_preview();
draw_text(panel_x+24,520,"SCORE  "+string(game_score));
draw_text(panel_x+24,580,"LEVEL  "+string(game_level));
draw_text(panel_x+24,640,"LINES  "+string(total_lines));
draw_text(panel_x+24,740,"LEFT / RIGHT: move");
draw_text(panel_x+24,780,"UP / X: clockwise");
draw_text(panel_x+24,820,"Z: anticlockwise");
draw_text(panel_x+24,860,"DOWN: soft drop");
draw_text(panel_x+24,900,"SPACE: hard drop");
draw_text(panel_x+24,940,"P: pause   R: restart");
draw_text(panel_x+24,980,"F1: grid / cell outlines");
if(paused || game_over) {
    draw_set_alpha(0.85); draw_set_colour(c_black);
    draw_rectangle(board_x,board_y+500,board_x+640,board_y+690,false);
    draw_set_alpha(1); draw_set_colour(c_white);
    draw_text(board_x+160,board_y+550,game_over ? "GAME OVER - R" : "PAUSED - P");
}

Run now. The T moves one cell per Left/Right/Down press and stops at the board boundaries. Falling, rotation and locking are deliberately absent at this checkpoint. The next panel is a placeholder until Stage 3. F1 toggles grid lines and green outlines for the active piece's logical cells.

The gameplay collision mask

The mask is the union of four exact 64 × 64 occupied cells. fits() checks bounds before indexing the array, then checks occupancy. try_move() commits only a valid move. There is no need to move freely in pixels and round back to the grid.

A single rectangular mask around an L or T would also occupy its empty corners. A precise mask would follow the uneven outline. Neither should decide board collisions. Stage 7 shows how to configure individual square sprite masks, while the array remains authoritative.

Stage 3

Spawn pieces and show the next shape

  1. Keep Part A in Create. Append Part B below its last line.
  2. Replace the whole Step event with Stage 3 below. Keep Draw unchanged.
  3. Run and use N to test the current/next sequence.

A Fisher–Yates shuffle randomises a bag containing each of the seven pieces once. spawn_piece() promotes next to current, queues another shape, resets timers, and checks the spawn cells. A blocked spawn sets game_over. The matrix starts at stored row 3; some cells can be hidden at first.

Create · append Part B
// Part B: append to Create after Part A.
bag=[];
take_from_bag=function() {
    if(array_length(bag)==0) {
        bag=[0,1,2,3,4,5,6];
        for(var _i=6;_i>0;_i--) {
            var _j=irandom(_i);
            var _temp=bag[_i]; bag[_i]=bag[_j]; bag[_j]=_temp;
        }
    }
    return array_pop(bag);
};
spawn_piece=function() {
    active_type=next_type; next_type=take_from_bag();
    active_rot=0; active_x=3; active_y=hidden_rows-1;
    fall_timer=0; lock_timer=0; lock_resets=0;
    move_dir=0; repeat_timer=0;
    if(!fits(active_type,active_rot,active_x,active_y)) game_over=true;
};
reset_game=function() {
    reset_board(); game_score=0; game_level=1; total_lines=0;
    game_over=false; paused=false; bag=[];
    next_type=take_from_bag(); spawn_piece();
};
randomize();
reset_game();
Step · Stage 3 · replace whole event
// Stage 3 Step: preview testing. N is TEMPORARY.
if(keyboard_check_pressed(vk_f1)) debug_grid=!debug_grid;
if(keyboard_check_pressed(ord("R"))) { reset_game(); exit; }
if(game_over) exit;
if(keyboard_check_pressed(ord("N"))) { spawn_piece(); exit; }
if(keyboard_check_pressed(vk_left)) try_move(-1,0);
if(keyboard_check_pressed(vk_right)) try_move(1,0);
if(keyboard_check_pressed(vk_down)) try_move(0,1);

N is a temporary testing key: it discards the active piece without fixing it to the board. This control is removed in Stage 5. R resets the board and bag. The preview uses actual occupied bounds to centre every shape.

Stage 4

Rotate using SRS wall and floor kicks

  1. Append Part C to Create after Part B.
  2. Replace the whole Step event with Stage 4.
  3. Test open-space rotations, then walls and floor. Up/X rotates clockwise; Z rotates anticlockwise.

States 0,1,2,3 are spawn, right, reverse and left. try_rotate() tries the rotated cells in place, then each SRS kick offset in order. J/L/S/T/Z share a table; I has its own; O has no displacement. All candidates failing leaves position and rotation unchanged.

The script already converts kick offsets to downward-positive Y. Do not invert them again. Rotation changes the four grid offsets, rather than using image_angle to turn a picture without updating occupancy.

Create · append Part C
// Part C: append to Create after Part B.
try_rotate=function(_dir) {
    var _newrot=(active_rot+_dir+4)%4;
    var _kicks=tet_kicks(active_type,active_rot,_newrot);
    for(var _i=0;_i<array_length(_kicks);_i++) {
        var _nx=active_x+_kicks[_i][0]; var _ny=active_y+_kicks[_i][1];
        if(fits(active_type,_newrot,_nx,_ny)) {
            active_x=_nx; active_y=_ny; active_rot=_newrot;
            return true;
        }
    }
    return false;
};
Step · Stage 4 · replace whole event
// Stage 3 Step: preview testing. N is TEMPORARY.
if(keyboard_check_pressed(vk_f1)) debug_grid=!debug_grid;
if(keyboard_check_pressed(ord("R"))) { reset_game(); exit; }
if(game_over) exit;
if(keyboard_check_pressed(ord("N"))) { spawn_piece(); exit; }
if(keyboard_check_pressed(vk_left)) try_move(-1,0);
if(keyboard_check_pressed(vk_right)) try_move(1,0);
if(keyboard_check_pressed(vk_down)) try_move(0,1);
if(keyboard_check_pressed(vk_up) || keyboard_check_pressed(ord("X"))) try_rotate(1);
if(keyboard_check_pressed(ord("Z"))) try_rotate(-1);

These are standard SRS quarter-turn shapes and kick tables. Spawn, top-out, gravity and scoring are the tutorial's stated rules. This is not a claim of full modern Tetris guideline compliance: Hold, 180° rotation, T-spins, combos and back-to-back bonuses are outside the core build.

Stage 5

Add falling, locking, clearing and scoring

  1. Append Part D after Part C in Create.
  2. Replace the whole Step event with Stage 5. This removes the temporary N control.
  3. Run: pieces now fall automatically. Hold Down for soft drop; Space hard-drops and locks immediately.

Contact starts a 0.5-second lock delay. Successful grounded lateral moves or rotations reset it up to 15 times per piece; rejected actions do not. Locking writes the four cells to the board. Complete rows clear together, surviving rows compact downward, then the preview piece spawns.

Create · append Part D
// Part D: append to Create after Part C.
clear_lines=function() {
    var _write=rows-1; var _cleared=0;
    for(var _read=rows-1;_read>=0;_read--) {
        var _full=true;
        for(var _cx=0;_cx<cols;_cx++)
            if(board[_read*cols+_cx]==-1) { _full=false; break; }
        if(_full) _cleared++;
        else {
            for(var _col=0;_col<cols;_col++)
                board[_write*cols+_col]=board[_read*cols+_col];
            _write--;
        }
    }
    for(var _ry=_write;_ry>=0;_ry--)
        for(var _rx=0;_rx<cols;_rx++) board[_ry*cols+_rx]=-1;
    var _points=[0,100,300,500,800];
    game_score+=_points[_cleared]*game_level;
    total_lines+=_cleared; game_level=1+floor(total_lines/10);
    return _cleared;
};
lock_piece=function() {
    var _cells=tet_cells(active_type,active_rot); var _above=false;
    for(var _i=0;_i<4;_i++) {
        var _cx=active_x+_cells[_i][0]; var _cy=active_y+_cells[_i][1];
        board[_cy*cols+_cx]=active_type;
        if(_cy<hidden_rows) _above=true;
    }
    // Chosen tutorial rule: any hidden-row cell on lock causes top-out.
    if(_above) { game_over=true; return; }
    clear_lines(); spawn_piece();
};
fall_interval=function() { return max(0.06,0.8*power(0.8,game_level-1)); };
player_action=function(_dx,_rotation) {
    var _grounded=!fits(active_type,active_rot,active_x,active_y+1);
    var _ok=false;
    if(_rotation!=0) _ok=try_rotate(_rotation);
    else _ok=try_move(_dx,0);
    if(_ok && _grounded && lock_resets<max_lock_resets) {
        lock_timer=0; lock_resets++;
    }
    return _ok;
};
hard_drop=function() {
    var _distance=0;
    while(try_move(0,1)) _distance++;
    game_score+=2*_distance; lock_piece();
};
advance_fall=function(_dt) {
    var _interval=fall_interval(); var _soft=keyboard_check(vk_down);
    if(_soft) _interval=min(_interval,0.035);
    fall_timer+=_dt;
    while(fall_timer>=_interval) {
        fall_timer-=_interval;
        if(!try_move(0,1)) { fall_timer=0; break; }
        if(_soft) game_score++;
    }
    if(!fits(active_type,active_rot,active_x,active_y+1)) {
        lock_timer+=_dt;
        if(lock_timer>=lock_delay) lock_piece();
    } else lock_timer=0;
};
Step · Stage 5 · replace whole event
// Stage 5 Step: rules, tap movement and drop.
if(keyboard_check_pressed(vk_f1)) debug_grid=!debug_grid;
if(keyboard_check_pressed(ord("R"))) { reset_game(); exit; }
if(game_over) exit;
var _dt=min(delta_time/1000000,0.1);
if(keyboard_check_pressed(vk_left)) player_action(-1,0);
if(keyboard_check_pressed(vk_right)) player_action(1,0);
if(keyboard_check_pressed(vk_up) || keyboard_check_pressed(ord("X"))) player_action(0,1);
if(keyboard_check_pressed(ord("Z"))) player_action(0,-1);
if(keyboard_check_pressed(vk_space)) { hard_drop(); exit; }
advance_fall(_dt);
ConditionRule
Clear 1 / 2 / 3 / 4 lines100 / 300 / 500 / 800 × the level before the clear
Successful soft-drop cell+1 point
Hard-drop cell+2 points
Level1 + floor(total lines ÷ 10)
Seconds per normal rowmax(0.06, 0.8 × 0.8^(level−1))
Top-outAny cell locks in a hidden row, or spawn cells are occupied

clear_lines() uses separate read/write row indices: full rows are skipped and all other rows copied downward. Top rows are then emptied. This avoids skipping adjacent full rows. Under valid play at most four rows clear in one lock.

The chosen top-out rule checks hidden-row locking before clearing. Treat changing that order as a deliberate rule change. No Clean Up event is needed for arrays; this code creates no ds_grid or ds_list resources.

Stage 6

Add held controls, pause and ghost landing

  1. Append Part E to Create.
  2. Replace Step with the final Stage 6 event. Keep Draw unchanged.
  3. Compare tap movement with held movement, then compare ghost cells with a hard drop.

DAS is the initial held-key delay: 0.15 seconds. ARR is the repeat interval: 0.05 seconds. Pressing both horizontal keys cancels movement. Changing direction moves immediately. P pauses simulation and timers; R restarts. The ghost calls the same fits() function as the real piece and never writes to the board.

Create · append Part E
// Part E: append to Create after Part D.
ghost_enabled=true;
Step · Stage 6 · final complete replacement
// Final Step: replace the WHOLE Step event.
if(keyboard_check_pressed(vk_f1)) debug_grid=!debug_grid;
if(keyboard_check_pressed(ord("R"))) { reset_game(); exit; }
if(keyboard_check_pressed(ord("P"))) {
    paused=!paused; move_dir=0; repeat_timer=0; exit;
}
if(paused || game_over) exit;
// Intentional 0.1s cap avoids large jumps after a window stall.
var _dt=min(delta_time/1000000,0.1);
var _dir=keyboard_check(vk_right)-keyboard_check(vk_left);
if(_dir==0) { move_dir=0; repeat_timer=0; }
else if(_dir!=move_dir) {
    move_dir=_dir; repeat_timer=das_delay; player_action(_dir,0);
} else {
    repeat_timer-=_dt;
    while(repeat_timer<=0) {
        player_action(_dir,0); repeat_timer+=arr_delay;
    }
}
if(keyboard_check_pressed(vk_up) || keyboard_check_pressed(ord("X"))) player_action(0,1);
if(keyboard_check_pressed(ord("Z"))) player_action(0,-1);
if(keyboard_check_pressed(vk_space)) { hard_drop(); exit; }
advance_fall(_dt);

delta_time is measured in microseconds; divide by 1,000,000 for seconds. The 0.1-second cap avoids a large jump after a window stall. During sustained severe lag this deliberately slows simulation time, so test on the intended machine.

Stage 7

Prepare uneven artwork and exact square masks

Keep original image files and work on copies. Finish the logic using placeholders first. Do not independently stretch each shape to its visible bounding box: the underlying cell spacing must stay 64 pixels even if the painted edges vary.

A. Prepare seven reusable cell sprites

  1. Open your artwork in an image editor supporting transparency, rulers and guides. Add guides every 64 pixels at the intended cell boundaries. Identify each logical square behind the uneven outline.
  2. Prepare one reusable tile for each colour/style. Name the sprites spr_cell_I, spr_cell_O, spr_cell_T, spr_cell_S, spr_cell_Z, spr_cell_J and spr_cell_L.
  3. For each tile, use an 80 × 80 transparent canvas. Put the logical square from (8,8) to (71,71), inclusive. The surrounding 8-pixel padding holds intentional bumps and uneven edges. Keep the logical square at 64 × 64: changing canvas size is different from rescaling the painted content.
  4. If 8 pixels of padding is insufficient, use a consistent larger canvas. For padding p, size=64+2p and origin=(p,p). Adjust the mask bounds accordingly.
  5. Export transparent PNGs; import them into Sprite assets with the exact names above. Use one frame each. Set the origin to Custom (8,8), rather than Middle Centre.
  6. Expand Collision Mask. Choose Mode Manual, Type Rectangle, and bounds Left=8, Top=8, Right=71, Bottom=71. Inclusive width is 71−8+1=64. Repeat for all seven sprites.
  7. No instances of those sprites are required. The controller draws them at cell anchors at scale 1. Preview drawing alone uses scale 0.75.
Origin (8,8) = cell anchorCanvas: 80 × 80Artwork: intentionally unevenMask: (8,8) to (71,71)Logical footprint: 64 × 64Example only · shown at 3× scale
The red anchor is placed at the cell's grid position. Padding and uneven edges do not increase occupancy.
Mask versus gameplay collision: these are correctly configured square sprite masks, useful if you later create cell objects. This game's controller reads board[], not those sprite masks. Do not add Collision events, Solid wall objects or place_meeting() checks to the controller. One rectangular mask around a whole T/L incorrectly includes empty corners.

B. Calibrate the background grid

  1. Measure the interior between the first and last grid boundaries: ten columns require 640 pixels; twenty rows require 1280 pixels.
  2. If the graphic is a regular grid at another scale, scale a copy so each interval becomes 64. If its aspect ratio or individual intervals are wrong, redraw the grid using 64-pixel guides. Masks cannot compensate for a misdrawn background.
  3. For the simplest import, export just the interior as 640 × 1280, name it spr_grid, set origin (0,0), and use one frame. It is drawn at (64,64), scale 1.
  4. If keeping a border, use an image whose interior still measures 640 × 1280, and set its origin to (left border width, top border height). The interior then starts at the intended anchor.
  5. Do not also add a copy on a room background layer. Turn on F1 and compare all grid boundaries, especially the far right and bottom, to detect cumulative drift.

C. Connect the next frame and artwork

  1. Prepare a copy of the next-panel frame as 320 × 416, one frame, origin (0,0), named spr_next_panel. It is drawn at (768,64).
  2. Keep the preview area clear: x=768…1088 and y=180…372 in room coordinates. Preview cells are 48 pixels. The code writes NEXT at (792,96); remove that Draw line if the artwork already contains it.
  3. Create all nine sprites before pasting Part F. These direct asset references ensure they are retained by the compiler.
  4. Append Part F after Part E in Create. Run with F1 on and compare your art with the logical cell outlines.
Create · optional Part F · create all nine sprites first
// Part F OPTIONAL: create ALL these sprites BEFORE appending to Create.
cell_sprites=[spr_cell_I,spr_cell_O,spr_cell_T,spr_cell_S,
    spr_cell_Z,spr_cell_J,spr_cell_L];
grid_sprite=spr_grid; next_sprite=spr_next_panel; use_art=true;

If your graphics are complete tetromino shapes

The supplied renderer builds each piece from four reusable tiles. For whole-piece art with unique joins or an illustration spanning multiple cells, deliberately separate/repaint reusable tiles. Cutting the whole image into four equal rectangular quarters is not generally correct.

To keep a complete illustration for the falling piece, an optional alternative renderer can use four pre-aligned state images: a 192 × 192 logical matrix for T/J/L/S/Z, and a 256 × 256 matrix for I, plus consistent padding. Retain empty corners; place art on the exact occupied cells from tet_cells(). O can use a 256 × 256 matrix matching its supplied coordinates. Draw the selected state at the active matrix anchor while still using the four-cell data for collision. This extension is not implemented in the supplied renderer.

Fixed pieces must support removing individual cells during a line clear. Keeping their unique whole-piece art needs per-cell image fragments or texture regions recording type/rotation/local cell, with those records moving during compaction. Reusable cell tiles are the recommended route for this tutorial.

Small decorative overlaps are allowed and follow draw order. At board edges, up to 8 pixels of art may protrude into the margin; collision stays inside. If strict visual clipping is required, a board-sized render surface is a later extension. Reduce the overhang if it obscures placement.

Stage 8

Use repeatable tests and finish the development log

Natural play tests the overall experience; controlled board fixtures make specific bugs reproducible.

  1. Append Part G to the end of Create (after optional Part F).
  2. Insert the fixture-key checks at the very top of the final Step event, above pause/game-over exits. Keep the rest of Stage 6 beneath them.
  3. Run each fixture, record actual results and press R to return to normal play.
Create · append Part G · development only
// Part G: append to Create for development testing only.
load_fixture=function(_count) {
    reset_game(); bag=[];
    game_score=0; total_lines=0; game_level=1;
    if(_count==0) {
        next_type=0;
        var _spawn=tet_cells(0,0);
        for(var _i=0;_i<4;_i++)
            board[(hidden_rows-1+_spawn[_i][1])*cols+3+_spawn[_i][0]]=5;
        spawn_piece(); return;
    }
    for(var _y=rows-_count;_y<rows;_y++)
        for(var _x=0;_x<cols;_x++) if(_x!=4) board[_y*cols+_x]=5;
    active_type=0; active_rot=1; active_x=2; active_y=hidden_rows;
    next_type=2; fall_timer=0; lock_timer=0; lock_resets=0;
    if(_count==1) total_lines=9;
};
Step · insert ABOVE Stage 6 code · development only
// Insert at the VERY TOP of final Step, development only.
if(keyboard_check_pressed(vk_f5)) { load_fixture(1); exit; }
if(keyboard_check_pressed(vk_f6)) { load_fixture(2); exit; }
if(keyboard_check_pressed(vk_f7)) { load_fixture(4); exit; }
if(keyboard_check_pressed(vk_f8)) { load_fixture(0); exit; }
TestInputsExpected result
T25 · level boundaryF5 then SpaceOne line clears; lines 9→10, level 1→2. Score=132: 100 line points + 32 hard-drop points (16 rows × 2).
T26 · adjacent rowsF6 then SpaceTwo lines clear; lines=2, level=1, score=332. Two remaining I cells are in column 4 of the bottom two rows.
T27 · four rowsF7 then SpaceFour lines clear; fixed board empty, lines=4, level=1, score=832. Exactly one new piece spawns.
T28 · spawn blockedF8Game-over message, no invalid array read. R restarts correctly.
T29 · reset limitRepeated legal grounded moves/rotationsOnly the first 15 reset the lock delay. Further actions do not postpone locking indefinitely.
T30 · separated rowsDebugger setup belowTwo full non-adjacent rows removed; marker moves down two rows.
T31 · blocked rotationDebugger setup belowReturns false; active position and rotation unchanged.
T32 · hidden lockDebugger setup belowgame_over=true before clearing/spawning, with no out-of-range access.

Deterministic debugger setups

Pause execution and select the obj_game instance context in the debugger. Execute one setup at a time. If your IDE's expression evaluator does not accept multi-statement code, temporarily put that setup in a Key Press event, run it once, inspect the instance variables, then delete the event. Press R after each test.

// T30: separated full rows and a marker.
reset_game();
for(var _x=0;_x<cols;_x++) {
    board[23*cols+_x]=5;
    board[21*cols+_x]=5;
}
board[20*cols+2]=2;
clear_lines(); // Returns 2. Marker now board[22*cols+2].

// T31: only the active T cells are empty.
reset_game();
board=array_create(cols*rows,5);
active_type=2; active_rot=0; active_x=3; active_y=10;
board[10*cols+4]=-1;
board[11*cols+3]=-1; board[11*cols+4]=-1; board[11*cols+5]=-1;
try_rotate(1); // false; x=3, y=10, rotation=0 unchanged.

// T32: grounded O partly above the visible area.
reset_game();
active_type=1; active_rot=0; active_x=3; active_y=3;
board[5*cols+4]=5; board[5*cols+5]=5;
lock_piece(); // game_over=true; no new piece.

Development-log structure

Complete an entry at every checkpoint and after a substantial fix. Name screenshots by build and test ID. The text boxes save to browser storage where supported; use Export Notes to keep a portable backup before moving or closing the file.

FieldRecord
Date, build and aimSpecific intended behaviour.
Design decisionChosen representation/rule, alternatives and reason.
ImplementationResources/events changed; purpose of major functions.
TestingID, starting state, inputs, expected result, actual result, pass/fail.
EvidenceScreenshot/video filename and what it demonstrates.
Defect and correctionFailure, cause, change and same-test retest result.
Evaluation and next actionRemaining issue and next step.
Example prompt, not a claimed test result: “Build 04: added SRS. T09 expected a one-cell rightward kick at the left wall. Actual: [your observation]. Evidence: [filename]. The cell array prevents decorative edges changing occupancy.” Replace the brackets with your own findings.

Stage 9

Troubleshoot and get the complete final code

SymptomCheck / correction
Variable not set before readingUse Create parts once each in A→B→C→D→E order. Parts initialize before Step runs. Keep code in the named object events, not Room Creation Code.
Unknown sprite namesCreate all Stage 7 assets or remove Part F. No sprites are needed for the placeholder build.
Repeated input or doubled scoreOne obj_game instance only; Persistent off.
Art drifts from gridCheck 64-pixel pitch, tile origin (8,8), grid origin and normal Draw. Do not scale only one component.
Kick goes the wrong wayCopy all eight transitions and do not invert Y offsets again.
Blank roomCheck start room, controller instance and Visible setting. Draw belongs in normal Draw.
Background appears twiceRemove room-layer copies; the controller draws the background and next frame.
Text too smallOptionally create a larger Font asset and call draw_set_font() at the top of Draw. Test fit inside the 320-pixel panel.
Adjacent line skippedRe-copy clear_lines(); the independent read/write indices are intentional.
Pieces stop too highStored row 4 is visible row 0; check hidden-row conversion and stated top-out rule.

Complete final core code

The four complete resources below include Create Parts A–E and final controls. They are a reference/recovery version, so replace their target event instead of appending them. Optional Part F (art) and Part G (fixtures) are separate. GML files in the pack are copy/paste source, not an importable .yyp project.

Verification scope

The shape, collision, kick, compaction, scoring and fixture logic was checked using a JavaScript harness adapted from the supplied GML. This is a logic check, not GameMaker compilation or a runtime playtest. The code has not been compiled or played in GameMaker in this environment. Run the staged tests to verify resource settings, rendering and input on your target computer.

References

GameMaker API details were checked against the official manual on 28 October 2026. The SRS cross-check uses TetrisWiki's specialist community reference; it is not official GameMaker documentation.

Independent educational falling-block implementation. All illustrations are explanatory examples.