diff --git a/examples/game-tetris.ds b/examples/game-tetris.ds index 6b460d9..f3ef41d 100644 --- a/examples/game-tetris.ds +++ b/examples/game-tetris.ds @@ -85,14 +85,16 @@ 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 has top cells at row py, bottom cell at py+1. --- To move down: top cells move to py+1, bottom cell to py+2. --- Check grid[py+1] at px, px+1, px+2 (top row would land here). --- Bottom wall: py >= 18 (piece can't go lower). +-- 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) +-- Bottom wall: py >= 18. let blocked = 0 --- Check collision against the CORRECT row: grid[py+1] for top cells -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 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 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 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 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 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 0))) else 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)))))) -- Gravity tick every 33 -> gravityTick = if paused then gravityTick else (if gameOver then gravityTick else gravityTick + 1)