From 190c6ad914430edbbedfa29612b6700071e9ab1e Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sat, 18 Oct 2025 11:32:26 +0200 Subject: [PATCH] chore: rename Rows to Lines in Grid as Lines are more common in tetris. --- game/grid.go | 30 +++++++++++++++--------------- game/line_clear_animation.go | 2 +- game/state/handlers/gameplay.go | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/game/grid.go b/game/grid.go index 3cf9b6b..d166cd0 100644 --- a/game/grid.go +++ b/game/grid.go @@ -33,30 +33,30 @@ func (g *Grid) Set(x, y byte, c Block) { (*g)[uint16(x)+(uint16(y)*GRID_WIDTH)] = c } -func (g *Grid) ClearFullRows() byte { +func (g *Grid) ClearFullLines() byte { completed := byte(0) for y := int(g.Height() - 1); y >= 0; y-- { - if g.IsRowFull(byte(y)) { + if g.IsLineFull(byte(y)) { completed++ - g.ClearRow(byte(y)) + g.ClearLine(byte(y)) } else if completed > 0 { - g.MoveRowDown(byte(y), completed) + g.MoveLineDown(byte(y), completed) } } return completed } -func (g *Grid) FullRows() []byte { - rows := []byte{} +func (g *Grid) FullLines() []byte { + lines := []byte{} for y := byte(0); y < byte(g.Height()); y++ { - if g.IsRowFull(y) { - rows = append(rows, y) + if g.IsLineFull(y) { + lines = append(lines, y) } } - return rows + return lines } -func (g *Grid) IsRowFull(y byte) bool { +func (g *Grid) IsLineFull(y byte) bool { for x := range byte(g.Width()) { if g.At(x, y) == BLOCK_EMPTY { return false @@ -65,26 +65,26 @@ func (g *Grid) IsRowFull(y byte) bool { return true } -func (g *Grid) MoveRowsDown(rows ...byte) { +func (g *Grid) MoveLinesDown(rows ...byte) { completed := byte(0) for y := int(g.Height() - 1); y >= 0; y-- { if slices.Contains(rows, byte(y)) { completed++ } else if completed > 0 { - g.MoveRowDown(byte(y), completed) + g.MoveLineDown(byte(y), completed) } } } -func (g *Grid) MoveRowDown(y, num_rows byte) { +func (g *Grid) MoveLineDown(y, num_lines byte) { w := uint16(g.Width()) src := uint16(y) * w - dst := uint16(y+num_rows) * w + dst := uint16(y+num_lines) * w copy(g[dst:dst+w], g[src:src+w]) clear(g[src : src+w]) } -func (g *Grid) ClearRow(y byte) { +func (g *Grid) ClearLine(y byte) { w := uint16(g.Width()) n := uint16(y) * w clear(g[n : n+w]) diff --git a/game/line_clear_animation.go b/game/line_clear_animation.go index b5885e9..5c650d5 100644 --- a/game/line_clear_animation.go +++ b/game/line_clear_animation.go @@ -38,7 +38,7 @@ func (lca *LineClearAnimation) Update(grid *Grid) { } if lca.leftIndex < 0 || lca.rightIndex > GRID_WIDTH { - grid.MoveRowsDown(lca.lines...) + grid.MoveLinesDown(lca.lines...) lca.Reset() return } diff --git a/game/state/handlers/gameplay.go b/game/state/handlers/gameplay.go index 19ff3b3..48a64f8 100644 --- a/game/state/handlers/gameplay.go +++ b/game/state/handlers/gameplay.go @@ -119,7 +119,7 @@ func (gp *GamePlay) Update(fsm state.Transitioner, delta float32) { if game.CheckShapeCollision(new_pos, &gp.shape, &gp.grid) { gp.LockShape() gp.SpawnShape() - lines := gp.grid.FullRows() + lines := gp.grid.FullLines() if len(lines) > 0 { gp.lineClearAnimation.SetLines(lines) gp.score.Lines(byte(len(lines)))