krampus19/gut/animation.go
Sander Schobers 6cce47198b Imroved movement
- Player can only move to valid positions.
- Bricks are pushed when this is allowed.
- Bricks are sunken when they end up over water.
Added settings (at runtime).
Added new tile (sunken tile).
Fixed bug with clearing of console.
- When messages changed the new text was rendered on top of clearing the old text without clearing the buffer.
2019-12-23 18:10:11 +01:00

50 lines
921 B
Go

package gut
import "time"
type Animation interface {
Animate(start, now time.Duration) bool
}
type AnimationDoneFn func()
type Animations struct {
anis []animation
}
type animation struct {
start time.Duration
ani Animation
done AnimationDoneFn
}
func (a *Animations) Idle() bool {
return len(a.anis) == 0
}
func (a *Animations) Start(now time.Duration, ani Animation) {
a.StartFn(now, ani, nil)
}
func (a *Animations) StartFn(now time.Duration, ani Animation, done AnimationDoneFn) {
a.anis = append(a.anis, animation{now, ani, done})
}
func (a *Animations) Animate(now time.Duration) {
active := make([]animation, 0, len(a.anis))
done := make([]animation, 0)
for _, ani := range a.anis {
if ani.ani.Animate(ani.start, now) {
active = append(active, ani)
} else {
done = append(done, ani)
}
}
a.anis = active
for _, ani := range done {
if ani.done != nil {
ani.done()
}
}
}