fix: piece-type aware collision — only T-piece checks bottom cell

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.
This commit is contained in:
enzotar 2026-02-27 12:52:13 -08:00
parent 30a3485440
commit 5c8b397d7b

View file

@ -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)