krampus19/gut/animation.go
Sander Schobers 7bd737af94 Added basic movement/animation.
Refactored entity to entityType.
2019-12-23 15:54:15 +01:00

35 lines
606 B
Go

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