mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Flush lines
This commit is contained in:
parent
ce97070f66
commit
51fa65bf2f
@ -62,9 +62,35 @@ func (f *Field) RotatePieceRight(piece *Piece, x, y int, angle Angle) Angle {
|
||||
return angle.RotateRight()
|
||||
}
|
||||
|
||||
|
||||
func (f *Field) AbsorbPiece(piece *Piece, x, y int, angle Angle) {
|
||||
piece.absorbInto(f, x, y, angle)
|
||||
piece.AbsorbInto(f, x, y, angle)
|
||||
f.Flush()
|
||||
}
|
||||
|
||||
func (f *Field) flushLine(j int) bool {
|
||||
for i := 0; i < fieldBlockNumX; i++ {
|
||||
if f.blocks[i][j] == BlockTypeNone {
|
||||
return false
|
||||
}
|
||||
}
|
||||
for j2 := j; 1 <= j2; j2-- {
|
||||
for i := 0; i < fieldBlockNumX; i++ {
|
||||
f.blocks[i][j2] = f.blocks[i][j2-1]
|
||||
}
|
||||
}
|
||||
for i := 0; i < fieldBlockNumX; i++ {
|
||||
f.blocks[i][0] = BlockTypeNone
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (f *Field) Flush() {
|
||||
flushedLineNum := 0
|
||||
for j := fieldBlockNumY - 1; 0 <= j; j-- {
|
||||
if f.flushLine(j + flushedLineNum) {
|
||||
flushedLineNum++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Field) Draw(context graphics.Context, geo matrix.Geometry) {
|
||||
|
@ -193,7 +193,7 @@ func (p *Piece) collides(field *Field, x, y int, angle Angle) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (p *Piece) absorbInto(field *Field, x, y int, angle Angle) {
|
||||
func (p *Piece) AbsorbInto(field *Field, x, y int, angle Angle) {
|
||||
size := len(p.blocks)
|
||||
for i := 0; i < size; i++ {
|
||||
for j := 0; j < size; j++ {
|
||||
|
Loading…
Reference in New Issue
Block a user