fix: I-piece now persists all 4 cells and renders at correct row
Added px+3 freeze writes for I-piece (piece==1) at all 20 rows. Fixed I-piece rendering from py+1 to py for consistent positioning. Extended collision to check px+3 for I-piece at every py level. I-piece now correctly shows and persists as 4 cells in a row.
This commit is contained in:
parent
7ad8bde38b
commit
d2cb302961
1 changed files with 29 additions and 7 deletions
|
|
@ -90,8 +90,8 @@ on keydown(ev) -> paused = if ev.key == "p" then (if paused then 0 else 1) else
|
|||
-- Bottom wall: py >= 18. Full grid coverage (py 0-17).
|
||||
let blocked = 0
|
||||
|
||||
-- Piece-aware collision: full grid, top row + T-piece bottom cell
|
||||
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 (if py == 11 then (if g12[px] > 0 then 1 else (if g12[px + 1] > 0 then 1 else (if g12[px + 2] > 0 then 1 else (if piece == 6 then (if g13[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 10 then (if g11[px] > 0 then 1 else (if g11[px + 1] > 0 then 1 else (if g11[px + 2] > 0 then 1 else (if piece == 6 then (if g12[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 9 then (if g10[px] > 0 then 1 else (if g10[px + 1] > 0 then 1 else (if g10[px + 2] > 0 then 1 else (if piece == 6 then (if g11[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 8 then (if g9[px] > 0 then 1 else (if g9[px + 1] > 0 then 1 else (if g9[px + 2] > 0 then 1 else (if piece == 6 then (if g10[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 7 then (if g8[px] > 0 then 1 else (if g8[px + 1] > 0 then 1 else (if g8[px + 2] > 0 then 1 else (if piece == 6 then (if g9[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 6 then (if g7[px] > 0 then 1 else (if g7[px + 1] > 0 then 1 else (if g7[px + 2] > 0 then 1 else (if piece == 6 then (if g8[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 5 then (if g6[px] > 0 then 1 else (if g6[px + 1] > 0 then 1 else (if g6[px + 2] > 0 then 1 else (if piece == 6 then (if g7[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 4 then (if g5[px] > 0 then 1 else (if g5[px + 1] > 0 then 1 else (if g5[px + 2] > 0 then 1 else (if piece == 6 then (if g6[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 3 then (if g4[px] > 0 then 1 else (if g4[px + 1] > 0 then 1 else (if g4[px + 2] > 0 then 1 else (if piece == 6 then (if g5[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 2 then (if g3[px] > 0 then 1 else (if g3[px + 1] > 0 then 1 else (if g3[px + 2] > 0 then 1 else (if piece == 6 then (if g4[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 1 then (if g2[px] > 0 then 1 else (if g2[px + 1] > 0 then 1 else (if g2[px + 2] > 0 then 1 else (if piece == 6 then (if g3[px + 1] > 0 then 1 else 0) else 0)))) else (if py == 0 then (if g1[px] > 0 then 1 else (if g1[px + 1] > 0 then 1 else (if g1[px + 2] > 0 then 1 else (if piece == 6 then (if g2[px + 1] > 0 then 1 else 0) else 0)))) else 0))))))))))))))))))
|
||||
-- Piece-aware collision: check px+3 for I-piece, py+2 at px+1 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 == 1 then (if g18[px + 3] > 0 then 1 else 0) 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 == 1 then (if g17[px + 3] > 0 then 1 else 0) 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 == 1 then (if g16[px + 3] > 0 then 1 else 0) 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 == 1 then (if g15[px + 3] > 0 then 1 else 0) 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 == 1 then (if g14[px + 3] > 0 then 1 else 0) 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 == 1 then (if g13[px + 3] > 0 then 1 else 0) else (if piece == 6 then (if g14[px + 1] > 0 then 1 else 0) else 0))))) else (if py == 11 then (if g12[px] > 0 then 1 else (if g12[px + 1] > 0 then 1 else (if g12[px + 2] > 0 then 1 else (if piece == 1 then (if g12[px + 3] > 0 then 1 else 0) else (if piece == 6 then (if g13[px + 1] > 0 then 1 else 0) else 0))))) else (if py == 10 then (if g11[px] > 0 then 1 else (if g11[px + 1] > 0 then 1 else (if g11[px + 2] > 0 then 1 else (if piece == 1 then (if g11[px + 3] > 0 then 1 else 0) else (if piece == 6 then (if g12[px + 1] > 0 then 1 else 0) else 0))))) else (if py == 9 then (if g10[px] > 0 then 1 else (if g10[px + 1] > 0 then 1 else (if g10[px + 2] > 0 then 1 else (if piece == 1 then (if g10[px + 3] > 0 then 1 else 0) else (if piece == 6 then (if g11[px + 1] > 0 then 1 else 0) else 0))))) else (if py == 8 then (if g9[px] > 0 then 1 else (if g9[px + 1] > 0 then 1 else (if g9[px + 2] > 0 then 1 else (if piece == 1 then (if g9[px + 3] > 0 then 1 else 0) else (if piece == 6 then (if g10[px + 1] > 0 then 1 else 0) else 0))))) else (if py == 7 then (if g8[px] > 0 then 1 else (if g8[px + 1] > 0 then 1 else (if g8[px + 2] > 0 then 1 else (if piece == 1 then (if g8[px + 3] > 0 then 1 else 0) else (if piece == 6 then (if g9[px + 1] > 0 then 1 else 0) else 0))))) else (if py == 6 then (if g7[px] > 0 then 1 else (if g7[px + 1] > 0 then 1 else (if g7[px + 2] > 0 then 1 else (if piece == 1 then (if g7[px + 3] > 0 then 1 else 0) else (if piece == 6 then (if g8[px + 1] > 0 then 1 else 0) else 0))))) else (if py == 5 then (if g6[px] > 0 then 1 else (if g6[px + 1] > 0 then 1 else (if g6[px + 2] > 0 then 1 else (if piece == 1 then (if g6[px + 3] > 0 then 1 else 0) else (if piece == 6 then (if g7[px + 1] > 0 then 1 else 0) else 0))))) else (if py == 4 then (if g5[px] > 0 then 1 else (if g5[px + 1] > 0 then 1 else (if g5[px + 2] > 0 then 1 else (if piece == 1 then (if g5[px + 3] > 0 then 1 else 0) else (if piece == 6 then (if g6[px + 1] > 0 then 1 else 0) else 0))))) else (if py == 3 then (if g4[px] > 0 then 1 else (if g4[px + 1] > 0 then 1 else (if g4[px + 2] > 0 then 1 else (if piece == 1 then (if g4[px + 3] > 0 then 1 else 0) else (if piece == 6 then (if g5[px + 1] > 0 then 1 else 0) else 0))))) else (if py == 2 then (if g3[px] > 0 then 1 else (if g3[px + 1] > 0 then 1 else (if g3[px + 2] > 0 then 1 else (if piece == 1 then (if g3[px + 3] > 0 then 1 else 0) else (if piece == 6 then (if g4[px + 1] > 0 then 1 else 0) else 0))))) else (if py == 1 then (if g2[px] > 0 then 1 else (if g2[px + 1] > 0 then 1 else (if g2[px + 2] > 0 then 1 else (if piece == 1 then (if g2[px + 3] > 0 then 1 else 0) else (if piece == 6 then (if g3[px + 1] > 0 then 1 else 0) else 0))))) else (if py == 0 then (if g1[px] > 0 then 1 else (if g1[px + 1] > 0 then 1 else (if g1[px + 2] > 0 then 1 else (if piece == 1 then (if g1[px + 3] > 0 then 1 else 0) else (if piece == 6 then (if g2[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)
|
||||
|
|
@ -190,6 +190,28 @@ every 33 -> g17[px + 1] = if lockTick == 3 then (if py == 16 then (if piece == 6
|
|||
every 33 -> g18[px + 1] = if lockTick == 3 then (if py == 17 then (if piece == 6 then 6 else g18[px + 1]) else g18[px + 1]) else g18[px + 1]
|
||||
every 33 -> g19[px + 1] = if lockTick == 3 then (if py == 18 then (if piece == 6 then 6 else g19[px + 1]) else g19[px + 1]) else g19[px + 1]
|
||||
|
||||
-- Freeze I-piece 4th cell into grid[py] at px+3 (all rows)
|
||||
every 33 -> g0[px + 3] = if lockTick == 3 then (if py == 0 then (if piece == 1 then 1 else g0[px + 3]) else g0[px + 3]) else g0[px + 3]
|
||||
every 33 -> g1[px + 3] = if lockTick == 3 then (if py == 1 then (if piece == 1 then 1 else g1[px + 3]) else g1[px + 3]) else g1[px + 3]
|
||||
every 33 -> g2[px + 3] = if lockTick == 3 then (if py == 2 then (if piece == 1 then 1 else g2[px + 3]) else g2[px + 3]) else g2[px + 3]
|
||||
every 33 -> g3[px + 3] = if lockTick == 3 then (if py == 3 then (if piece == 1 then 1 else g3[px + 3]) else g3[px + 3]) else g3[px + 3]
|
||||
every 33 -> g4[px + 3] = if lockTick == 3 then (if py == 4 then (if piece == 1 then 1 else g4[px + 3]) else g4[px + 3]) else g4[px + 3]
|
||||
every 33 -> g5[px + 3] = if lockTick == 3 then (if py == 5 then (if piece == 1 then 1 else g5[px + 3]) else g5[px + 3]) else g5[px + 3]
|
||||
every 33 -> g6[px + 3] = if lockTick == 3 then (if py == 6 then (if piece == 1 then 1 else g6[px + 3]) else g6[px + 3]) else g6[px + 3]
|
||||
every 33 -> g7[px + 3] = if lockTick == 3 then (if py == 7 then (if piece == 1 then 1 else g7[px + 3]) else g7[px + 3]) else g7[px + 3]
|
||||
every 33 -> g8[px + 3] = if lockTick == 3 then (if py == 8 then (if piece == 1 then 1 else g8[px + 3]) else g8[px + 3]) else g8[px + 3]
|
||||
every 33 -> g9[px + 3] = if lockTick == 3 then (if py == 9 then (if piece == 1 then 1 else g9[px + 3]) else g9[px + 3]) else g9[px + 3]
|
||||
every 33 -> g10[px + 3] = if lockTick == 3 then (if py == 10 then (if piece == 1 then 1 else g10[px + 3]) else g10[px + 3]) else g10[px + 3]
|
||||
every 33 -> g11[px + 3] = if lockTick == 3 then (if py == 11 then (if piece == 1 then 1 else g11[px + 3]) else g11[px + 3]) else g11[px + 3]
|
||||
every 33 -> g12[px + 3] = if lockTick == 3 then (if py == 12 then (if piece == 1 then 1 else g12[px + 3]) else g12[px + 3]) else g12[px + 3]
|
||||
every 33 -> g13[px + 3] = if lockTick == 3 then (if py == 13 then (if piece == 1 then 1 else g13[px + 3]) else g13[px + 3]) else g13[px + 3]
|
||||
every 33 -> g14[px + 3] = if lockTick == 3 then (if py == 14 then (if piece == 1 then 1 else g14[px + 3]) else g14[px + 3]) else g14[px + 3]
|
||||
every 33 -> g15[px + 3] = if lockTick == 3 then (if py == 15 then (if piece == 1 then 1 else g15[px + 3]) else g15[px + 3]) else g15[px + 3]
|
||||
every 33 -> g16[px + 3] = if lockTick == 3 then (if py == 16 then (if piece == 1 then 1 else g16[px + 3]) else g16[px + 3]) else g16[px + 3]
|
||||
every 33 -> g17[px + 3] = if lockTick == 3 then (if py == 17 then (if piece == 1 then 1 else g17[px + 3]) else g17[px + 3]) else g17[px + 3]
|
||||
every 33 -> g18[px + 3] = if lockTick == 3 then (if py == 18 then (if piece == 1 then 1 else g18[px + 3]) else g18[px + 3]) else g18[px + 3]
|
||||
every 33 -> g19[px + 3] = if lockTick == 3 then (if py == 19 then (if piece == 1 then 1 else g19[px + 3]) else g19[px + 3]) else g19[px + 3]
|
||||
|
||||
-- Spawn new piece after lock
|
||||
every 33 -> piece = if lockTick == 3 then nextPiece else piece
|
||||
every 33 -> nextPiece = if lockTick == 3 then (gravityTick % 7 + 1) else nextPiece
|
||||
|
|
@ -321,17 +343,17 @@ view tetris_game = column [
|
|||
|
||||
-- Active piece: 4 cells (Layer 1 data + Layer 3 input -> Layer 5 UI)
|
||||
-- Cell 0: top-left of piece
|
||||
column { style: "position:absolute; width:28px; height:28px; border-radius:4px; background:linear-gradient(180deg,#c084fc,#a855f7); box-shadow:0 0 12px rgba(168,85,247,0.5); transition:left 0.05s,top 0.05s; top:{(if piece == 1 then py + 1 else py) * 30 + 1}px; left:{(if piece == 5 then px + 1 else px) * 30 + 1}px" } []
|
||||
column { style: "position:absolute; width:28px; height:28px; border-radius:4px; background:linear-gradient(180deg,#c084fc,#a855f7); box-shadow:0 0 12px rgba(168,85,247,0.5); transition:left 0.05s,top 0.05s; top:{py * 30 + 1}px; left:{(if piece == 5 then px + 1 else px) * 30 + 1}px" } []
|
||||
|
||||
-- Cell 1
|
||||
column { style: "position:absolute; width:28px; height:28px; border-radius:4px; background:linear-gradient(180deg,#c084fc,#a855f7); box-shadow:0 0 12px rgba(168,85,247,0.5); transition:left 0.05s,top 0.05s; top:{(if piece == 1 then py + 1 else py) * 30 + 1}px; left:{(if piece == 2 then px else px + 1) * 30 + 1}px" } []
|
||||
column { style: "position:absolute; width:28px; height:28px; border-radius:4px; background:linear-gradient(180deg,#c084fc,#a855f7); box-shadow:0 0 12px rgba(168,85,247,0.5); transition:left 0.05s,top 0.05s; top:{py * 30 + 1}px; left:{(if piece == 2 then px else px + 1) * 30 + 1}px" } []
|
||||
|
||||
-- Cell 2
|
||||
column { style: "position:absolute; width:28px; height:28px; border-radius:4px; background:linear-gradient(180deg,#c084fc,#a855f7); box-shadow:0 0 12px rgba(168,85,247,0.5); transition:left 0.05s,top 0.05s; top:{(if piece == 1 then py + 1 else py) * 30 + 1}px; left:{(if piece == 1 then px + 2 else (if piece == 3 then px + 2 else px + 2)) * 30 + 1}px" } []
|
||||
column { style: "position:absolute; width:28px; height:28px; border-radius:4px; background:linear-gradient(180deg,#c084fc,#a855f7); box-shadow:0 0 12px rgba(168,85,247,0.5); transition:left 0.05s,top 0.05s; top:{py * 30 + 1}px; left:{(px + 2) * 30 + 1}px" } []
|
||||
|
||||
-- Cell 3 (second row: T-piece center bottom, I-piece 4th cell)
|
||||
-- Cell 3 (T-piece foot at py+1, I-piece 4th cell at py)
|
||||
-- Only visible for T-piece (piece==6) and I-piece (piece==1)
|
||||
column { style: "position:absolute; width:28px; height:28px; border-radius:4px; background:linear-gradient(180deg,#c084fc,#a855f7); box-shadow:0 0 12px rgba(168,85,247,0.5); transition:left 0.05s,top 0.05s; opacity:{if piece == 6 then 1 else (if piece == 1 then 1 else 0)}; top:{(if piece == 1 then py + 1 else py + 1) * 30 + 1}px; left:{(if piece == 1 then px + 3 else (if piece == 6 then px + 1 else (if piece == 4 then px + 2 else px + 2))) * 30 + 1}px" } []
|
||||
column { style: "position:absolute; width:28px; height:28px; border-radius:4px; background:linear-gradient(180deg,#c084fc,#a855f7); box-shadow:0 0 12px rgba(168,85,247,0.5); transition:left 0.05s,top 0.05s; opacity:{if piece == 6 then 1 else (if piece == 1 then 1 else 0)}; top:{(if piece == 1 then py else py + 1) * 30 + 1}px; left:{(if piece == 1 then px + 3 else (if piece == 6 then px + 1 else px + 2)) * 30 + 1}px" } []
|
||||
|
||||
-- Ghost piece (Layer 4 derived -> Layer 5 UI)
|
||||
-- Shows where piece will land (row 18)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue