1
0
Fork 0

chore: rename Rows to Lines in Grid as Lines are more common in tetris.

This commit is contained in:
Henrik Hautakoski 2025-10-18 11:32:26 +02:00
parent db9ec53d35
commit 190c6ad914
3 changed files with 17 additions and 17 deletions

View file

@ -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])

View file

@ -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
}

View file

@ -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)))