added Timer, Particle Render Delay (via Particle.Show) +new sprites
This commit is contained in:
@@ -11,6 +11,7 @@ type Renderable struct {
|
||||
}
|
||||
|
||||
type Particle struct {
|
||||
Show bool
|
||||
Index int
|
||||
Particles []*ebiten.Image
|
||||
}
|
||||
|
||||
41
components/timer.go
Normal file
41
components/timer.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user