added Timer, Particle Render Delay (via Particle.Show) +new sprites

This commit is contained in:
2024-02-12 17:27:52 +01:00
parent 65ddec3fa4
commit 5a288035b3
14 changed files with 80 additions and 20 deletions

View File

@@ -11,6 +11,7 @@ type Renderable struct {
}
type Particle struct {
Show bool
Index int
Particles []*ebiten.Image
}

41
components/timer.go Normal file
View File

@@ -0,0 +1,41 @@
package components
import (
"time"
"github.com/hajimehoshi/ebiten/v2"
)
type Timer struct {
currentTicks int
targetTicks int
}
func NewTimer(d time.Duration) *Timer {
return &Timer{}
}
func (timer *Timer) Start(d time.Duration) {
min := int(1000 / ebiten.TPS()) // 16.66ms == 1 tick
useD := d
if int(d.Milliseconds()) < min {
useD = time.Duration(1000/ebiten.TPS()) * time.Millisecond
}
timer.targetTicks = int(useD.Milliseconds()) / min // id d=50, then 50 / 16.6 =
}
func (t *Timer) Update() {
if t.currentTicks < t.targetTicks {
t.currentTicks++
}
}
func (t *Timer) IsReady() bool {
return t.currentTicks >= t.targetTicks
}
func (t *Timer) Reset() {
t.currentTicks = 0
}