mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 19:28:57 +01:00
examples/2048: Make it smoother
This commit is contained in:
parent
ced66ff319
commit
2c4b9c1dbe
@ -69,6 +69,9 @@ func (b *Board) Update(input *Input) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *Board) Move(dir Dir) error {
|
func (b *Board) Move(dir Dir) error {
|
||||||
|
for t := range b.tiles {
|
||||||
|
t.stopAnimation()
|
||||||
|
}
|
||||||
if !MoveTiles(b.tiles, b.size, dir) {
|
if !MoveTiles(b.tiles, b.size, dir) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -100,14 +103,6 @@ func (b *Board) Move(dir Dir) error {
|
|||||||
}
|
}
|
||||||
return taskTerminated
|
return taskTerminated
|
||||||
})
|
})
|
||||||
b.tasks = append(b.tasks, func() error {
|
|
||||||
for t := range b.tiles {
|
|
||||||
if t.isAnimating() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return taskTerminated
|
|
||||||
})
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,8 +70,10 @@ func (t *Tile) IsMoving() bool {
|
|||||||
return 0 < t.movingCount
|
return 0 < t.movingCount
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tile) isAnimating() bool {
|
func (t *Tile) stopAnimation() {
|
||||||
return 0 < t.movingCount || 0 < t.startPoppingCount || 0 < t.poppingCount
|
t.movingCount = 0
|
||||||
|
t.startPoppingCount = 0
|
||||||
|
t.poppingCount = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func tileAt(tiles map[*Tile]struct{}, x, y int) *Tile {
|
func tileAt(tiles map[*Tile]struct{}, x, y int) *Tile {
|
||||||
|
Loading…
Reference in New Issue
Block a user