Thomas von Dein 20fa2639c6 Changes:
- fixed collectible detonation animation timing
- replaced those animatin sprites
- also replaced the collectible sprite with one created with asesprite
- more todo stuff added
2024-04-01 19:43:37 +02:00

51 lines
937 B
Go

package components
import (
"math/rand"
"time"
"github.com/hajimehoshi/ebiten/v2"
)
type Timer struct {
CurrentTicks int
TargetTicks int
Running bool
Id int
}
func NewTimer() *Timer {
return &Timer{}
}
func (timer *Timer) Start(duration time.Duration) {
timer.Reset()
min := int(1000 / ebiten.TPS()) // 16.66ms == 1 tick
dur := duration
if int(duration.Milliseconds()) < min {
dur = time.Duration(1000/ebiten.TPS()) * time.Millisecond
}
timer.TargetTicks = int(dur.Milliseconds()) / min // id d=50, then 50 / 16.6 =
timer.Running = true
timer.Id = rand.Int()
}
func (timer *Timer) Update() {
if (timer.CurrentTicks < timer.TargetTicks) && timer.Running {
timer.CurrentTicks++
}
}
func (timer *Timer) IsReady() bool {
return (timer.CurrentTicks >= timer.TargetTicks) && timer.Running
}
func (timer *Timer) Reset() {
timer.CurrentTicks = 0
timer.TargetTicks = 0
timer.Running = false
}