From 5c8b397d7b74d62c8adc1ce680fb7df740218ef1 Mon Sep 17 00:00:00 2001 From: enzotar Date: Fri, 27 Feb 2026 12:52:13 -0800 Subject: [PATCH] =?UTF-8?q?fix:=20piece-type=20aware=20collision=20?= =?UTF-8?q?=E2=80=94=20only=20T-piece=20checks=20bottom=20cell?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit grid[py+2] at px+1 now only checked when piece==6 (T-piece). Other pieces (I, J, L, O, S, Z) only check grid[py+1] for top row collision. Flat pieces stack flush; T-pieces correctly account for their protruding foot. --- examples/game-tetris.ds | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/examples/game-tetris.ds b/examples/game-tetris.ds index f3ef41d..2c861bc 100644 --- a/examples/game-tetris.ds +++ b/examples/game-tetris.ds @@ -85,16 +85,13 @@ on keydown(ev) -> paused = if ev.key == "p" then (if paused then 0 else 1) else -- ================================================================ -- Collision detection: can the piece move down? --- T-piece at py: top row at py (3 cells), bottom cell at py+1 (1 cell). --- Moving down: top row -> py+1, bottom cell -> py+2. --- Must check BOTH: --- grid[py+1] at px, px+1, px+2 (top row destination) --- grid[py+2] at px+1 (bottom cell destination) +-- All pieces: check grid[py+1] at px, px+1, px+2 (top row destination). +-- T-piece (6) only: also check grid[py+2] at px+1 (protruding bottom cell). -- Bottom wall: py >= 18. let blocked = 0 --- Full collision: top row (grid[py+1]) + bottom cell (grid[py+2]) -every 33 -> blocked = if py > 17 then 1 else (if py == 17 then (if g18[px] > 0 then 1 else (if g18[px + 1] > 0 then 1 else (if g18[px + 2] > 0 then 1 else (if g19[px + 1] > 0 then 1 else 0)))) else (if py == 16 then (if g17[px] > 0 then 1 else (if g17[px + 1] > 0 then 1 else (if g17[px + 2] > 0 then 1 else (if g18[px + 1] > 0 then 1 else 0)))) else (if py == 15 then (if g16[px] > 0 then 1 else (if g16[px + 1] > 0 then 1 else (if g16[px + 2] > 0 then 1 else (if g17[px + 1] > 0 then 1 else 0)))) else (if py == 14 then (if g15[px] > 0 then 1 else (if g15[px + 1] > 0 then 1 else (if g15[px + 2] > 0 then 1 else (if g16[px + 1] > 0 then 1 else 0)))) else (if py == 13 then (if g14[px] > 0 then 1 else (if g14[px + 1] > 0 then 1 else (if g14[px + 2] > 0 then 1 else (if g15[px + 1] > 0 then 1 else 0)))) else (if py == 12 then (if g13[px] > 0 then 1 else (if g13[px + 1] > 0 then 1 else (if g13[px + 2] > 0 then 1 else (if g14[px + 1] > 0 then 1 else 0)))) else 0)))))) +-- Piece-aware collision: top row for all, bottom cell only for T-piece +every 33 -> blocked = if py > 17 then 1 else (if py == 17 then (if g18[px] > 0 then 1 else (if g18[px + 1] > 0 then 1 else (if g18[px + 2] > 0 then 1 else (if piece == 6 then (if g19[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 16 then (if g17[px] > 0 then 1 else (if g17[px + 1] > 0 then 1 else (if g17[px + 2] > 0 then 1 else (if piece == 6 then (if g18[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 15 then (if g16[px] > 0 then 1 else (if g16[px + 1] > 0 then 1 else (if g16[px + 2] > 0 then 1 else (if piece == 6 then (if g17[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 14 then (if g15[px] > 0 then 1 else (if g15[px + 1] > 0 then 1 else (if g15[px + 2] > 0 then 1 else (if piece == 6 then (if g16[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 13 then (if g14[px] > 0 then 1 else (if g14[px + 1] > 0 then 1 else (if g14[px + 2] > 0 then 1 else (if piece == 6 then (if g15[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 12 then (if g13[px] > 0 then 1 else (if g13[px + 1] > 0 then 1 else (if g13[px + 2] > 0 then 1 else (if piece == 6 then (if g14[px + 1] > 0 then 1 else 0) else 0)))) else 0)))))) -- Gravity tick every 33 -> gravityTick = if paused then gravityTick else (if gameOver then gravityTick else gravityTick + 1)