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.
- Create a blank GameMaker project named
GridDrop. Select GML Code, not GML Visual. Avoid a physics template. - Create a room named
rm_game. Set its width to 1152 and height to 1408. Make it the first/start room in Room Order. - Leave room physics and cameras/viewports disabled for this version. Use normal room coordinates for all drawing.
- 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. - In the room, add/select an Instance Layer named
Instances. Place exactly oneobj_gameinstance at (0,0). - 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.
| Resource | Purpose |
|---|---|
obj_game | Owns board state, input, active/next pieces, rules and drawing. |
scr_tetromino_data | A script containing cell-coordinate and rotation-offset functions, created next. |
| Nine optional sprites | Seven 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_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.
- 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. - Open
obj_game→ Add Event → Create. Paste Part A. - Add a Step event. Paste the Stage 2 Step code.
- 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 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]];
}// 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();// 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 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
- Keep Part A in Create. Append Part B below its last line.
- Replace the whole Step event with Stage 3 below. Keep Draw unchanged.
- 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.
// 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();// 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
- Append Part C to Create after Part B.
- Replace the whole Step event with Stage 4.
- 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.
// 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;
};// 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
- Append Part D after Part C in Create.
- Replace the whole Step event with Stage 5. This removes the temporary N control.
- 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.
// 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;
};// 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);| Condition | Rule |
|---|---|
| Clear 1 / 2 / 3 / 4 lines | 100 / 300 / 500 / 800 × the level before the clear |
| Successful soft-drop cell | +1 point |
| Hard-drop cell | +2 points |
| Level | 1 + floor(total lines ÷ 10) |
| Seconds per normal row | max(0.06, 0.8 × 0.8^(level−1)) |
| Top-out | Any 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
- Append Part E to Create.
- Replace Step with the final Stage 6 event. Keep Draw unchanged.
- 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.
// Part E: append to Create after Part D.
ghost_enabled=true;// 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
- 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.
- 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_Jandspr_cell_L. - 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.
- 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.
- 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.
- 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.
- No instances of those sprites are required. The controller draws them at cell anchors at scale 1. Preview drawing alone uses scale 0.75.
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
- Measure the interior between the first and last grid boundaries: ten columns require 640 pixels; twenty rows require 1280 pixels.
- 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.
- 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. - 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.
- 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
- 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). - 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.
- Create all nine sprites before pasting Part F. These direct asset references ensure they are retained by the compiler.
- Append Part F after Part E in Create. Run with F1 on and compare your art with the logical cell outlines.
// 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.
- Append Part G to the end of Create (after optional Part F).
- 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.
- Run each fixture, record actual results and press R to return to normal play.
// 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;
};// 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; }| Test | Inputs | Expected result |
|---|---|---|
| T25 · level boundary | F5 then Space | One line clears; lines 9→10, level 1→2. Score=132: 100 line points + 32 hard-drop points (16 rows × 2). |
| T26 · adjacent rows | F6 then Space | Two lines clear; lines=2, level=1, score=332. Two remaining I cells are in column 4 of the bottom two rows. |
| T27 · four rows | F7 then Space | Four lines clear; fixed board empty, lines=4, level=1, score=832. Exactly one new piece spawns. |
| T28 · spawn blocked | F8 | Game-over message, no invalid array read. R restarts correctly. |
| T29 · reset limit | Repeated legal grounded moves/rotations | Only the first 15 reset the lock delay. Further actions do not postpone locking indefinitely. |
| T30 · separated rows | Debugger setup below | Two full non-adjacent rows removed; marker moves down two rows. |
| T31 · blocked rotation | Debugger setup below | Returns false; active position and rotation unchanged. |
| T32 · hidden lock | Debugger setup below | game_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.
| Field | Record |
|---|---|
| Date, build and aim | Specific intended behaviour. |
| Design decision | Chosen representation/rule, alternatives and reason. |
| Implementation | Resources/events changed; purpose of major functions. |
| Testing | ID, starting state, inputs, expected result, actual result, pass/fail. |
| Evidence | Screenshot/video filename and what it demonstrates. |
| Defect and correction | Failure, cause, change and same-test retest result. |
| Evaluation and next action | Remaining issue and next step. |
Stage 9
Troubleshoot and get the complete final code
| Symptom | Check / correction |
|---|---|
| Variable not set before reading | Use 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 names | Create all Stage 7 assets or remove Part F. No sprites are needed for the placeholder build. |
| Repeated input or doubled score | One obj_game instance only; Persistent off. |
| Art drifts from grid | Check 64-pixel pitch, tile origin (8,8), grid origin and normal Draw. Do not scale only one component. |
| Kick goes the wrong way | Copy all eight transitions and do not invert Y offsets again. |
| Blank room | Check start room, controller instance and Visible setting. Draw belongs in normal Draw. |
| Background appears twice | Remove room-layer copies; the controller draws the background and next frame. |
| Text too small | Optionally create a larger Font asset and call draw_set_font() at the top of Draw. Test fit inside the 320-pixel panel. |
| Adjacent line skipped | Re-copy clear_lines(); the independent read/write indices are intentional. |
| Pieces stop too high | Stored 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.
- GameMaker Sprite Editor: origin and collision-mask settings
- GameMaker method variables: functions bound to instance scope
- GameMaker delta_time: microseconds to seconds
- GameMaker draw_sprite_ext
- TetrisWiki Super Rotation System: state and kick reference
Independent educational falling-block implementation. All illustrations are explanatory examples.