1
0
Fork 0

feat: add line clear animation

This commit is contained in:
Henrik Hautakoski 2025-10-18 11:28:26 +02:00
parent fdab0a1992
commit db9ec53d35
4 changed files with 112 additions and 20 deletions

View file

@ -1,6 +1,8 @@
package game
import (
"slices"
"tetris/engine/graphics"
)
@ -44,6 +46,16 @@ func (g *Grid) ClearFullRows() byte {
return completed
}
func (g *Grid) FullRows() []byte {
rows := []byte{}
for y := byte(0); y < byte(g.Height()); y++ {
if g.IsRowFull(y) {
rows = append(rows, y)
}
}
return rows
}
func (g *Grid) IsRowFull(y byte) bool {
for x := range byte(g.Width()) {
if g.At(x, y) == BLOCK_EMPTY {
@ -53,6 +65,17 @@ func (g *Grid) IsRowFull(y byte) bool {
return true
}
func (g *Grid) MoveRowsDown(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)
}
}
}
func (g *Grid) MoveRowDown(y, num_rows byte) {
w := uint16(g.Width())
src := uint16(y) * w