examples/2048: Make it smoother

This commit is contained in:
Hajime Hoshi 2016-08-01 02:42:06 +09:00
parent ced66ff319
commit 2c4b9c1dbe
2 changed files with 7 additions and 10 deletions

View File

@ -69,6 +69,9 @@ func (b *Board) Update(input *Input) error {
}
func (b *Board) Move(dir Dir) error {
for t := range b.tiles {
t.stopAnimation()
}
if !MoveTiles(b.tiles, b.size, dir) {
return nil
}
@ -100,14 +103,6 @@ func (b *Board) Move(dir Dir) error {
}
return taskTerminated
})
b.tasks = append(b.tasks, func() error {
for t := range b.tiles {
if t.isAnimating() {
return nil
}
}
return taskTerminated
})
return nil
}

View File

@ -70,8 +70,10 @@ func (t *Tile) IsMoving() bool {
return 0 < t.movingCount
}
func (t *Tile) isAnimating() bool {
return 0 < t.movingCount || 0 < t.startPoppingCount || 0 < t.poppingCount
func (t *Tile) stopAnimation() {
t.movingCount = 0
t.startPoppingCount = 0
t.poppingCount = 0
}
func tileAt(tiles map[*Tile]struct{}, x, y int) *Tile {