fix: collision off-by-one — pieces now stack adjacently
Collision was checking grid[py+2] instead of grid[py+1]. Pieces stopped one row too early, creating gaps. Now checks grid[py+1] (where top cells would land) with full 3-column width (px, px+1, px+2). Pieces now stack directly on top of each other.
This commit is contained in:
parent
df8b74bab3
commit
b8fb60d8c4
1 changed files with 7 additions and 12 deletions
|
|
@ -84,20 +84,15 @@ on keydown(ev) -> paused = if ev.key == "p" then (if paused then 0 else 1) else
|
|||
-- LAYER 4: DERIVED SIGNALS — Collision, gravity, lock, line clear
|
||||
-- ================================================================
|
||||
|
||||
-- Collision detection signal: is the row BELOW the piece occupied?
|
||||
-- For a standard piece (3 wide, 2 tall like T), the bottom cells are at py+1.
|
||||
-- We check if grid row py+2 has any blocks at the piece's x positions.
|
||||
-- `blocked` = 1 means can't move down, 0 means safe to drop.
|
||||
--
|
||||
-- Since grid rows are individual signals, we branch on py to check the right row.
|
||||
-- Also blocked at the bottom wall (py >= 18 for standard pieces).
|
||||
-- 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).
|
||||
let blocked = 0
|
||||
|
||||
-- Check collision: at bottom wall OR frozen cells below
|
||||
-- T/J/L/S/Z pieces: bottom at py+1, so check py+2
|
||||
-- I piece: bottom at py+1, check py+2
|
||||
-- Piece bottom row = py+1, next row down = py+2
|
||||
every 33 -> blocked = if py > 17 then 1 else (if py == 17 then (if g19[px] > 0 then 1 else (if g19[px + 1] > 0 then 1 else 0)) else (if py == 16 then (if g18[px] > 0 then 1 else (if g18[px + 1] > 0 then 1 else 0)) else (if py == 15 then (if g17[px] > 0 then 1 else (if g17[px + 1] > 0 then 1 else 0)) else (if py == 14 then (if g16[px] > 0 then 1 else (if g16[px + 1] > 0 then 1 else 0)) else (if py == 13 then (if g15[px] > 0 then 1 else (if g15[px + 1] > 0 then 1 else 0)) else (if py == 12 then (if g14[px] > 0 then 1 else (if g14[px + 1] > 0 then 1 else 0)) else 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))))))
|
||||
|
||||
-- Gravity tick
|
||||
every 33 -> gravityTick = if paused then gravityTick else (if gameOver then gravityTick else gravityTick + 1)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue