fix: complete collision — checks both top row and bottom cell
Added grid[py+2] at px+1 check for the T-piece's protruding bottom cell. Collision now checks 4 cells total per piece: - grid[py+1] at px, px+1, px+2 (top row destination) - grid[py+2] at px+1 (bottom cell destination) This prevents pieces from passing through the angled/protruding parts of frozen T-shaped blocks.
This commit is contained in:
parent
d4f353394f
commit
30a3485440
1 changed files with 8 additions and 6 deletions
|
|
@ -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?
|
-- Collision detection: can the piece move down?
|
||||||
-- T-piece at py has top cells at row py, bottom cell at py+1.
|
-- T-piece at py: top row at py (3 cells), bottom cell at py+1 (1 cell).
|
||||||
-- To move down: top cells move to py+1, bottom cell to py+2.
|
-- Moving down: top row -> py+1, bottom cell -> py+2.
|
||||||
-- Check grid[py+1] at px, px+1, px+2 (top row would land here).
|
-- Must check BOTH:
|
||||||
-- Bottom wall: py >= 18 (piece can't go lower).
|
-- 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
|
let blocked = 0
|
||||||
|
|
||||||
-- Check collision against the CORRECT row: grid[py+1] for top cells
|
-- 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 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))))))
|
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
|
-- Gravity tick
|
||||||
every 33 -> gravityTick = if paused then gravityTick else (if gameOver then gravityTick else gravityTick + 1)
|
every 33 -> gravityTick = if paused then gravityTick else (if gameOver then gravityTick else gravityTick + 1)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue