-
Notifications
You must be signed in to change notification settings - Fork 5
/
explosion.go
55 lines (45 loc) · 1.13 KB
/
explosion.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
resource "github.com/quasilyte/ebitengine-resource"
"github.com/quasilyte/ge"
"github.com/quasilyte/gmath"
)
type explosion struct {
anim *ge.Animation
pos gmath.Vec
rotation gmath.Rad
Image resource.ImageID
Scale float64
Rotating bool
Hue gmath.Rad
AnimationSpeed float64
}
func newExplosion(pos gmath.Vec) *explosion {
return &explosion{
pos: pos,
Scale: 1,
AnimationSpeed: 1,
Image: ImageExplosion1,
}
}
func (e *explosion) Init(scene *ge.Scene) {
e.rotation = scene.Rand().Rad()
sprite := scene.NewSprite(e.Image)
sprite.Pos.Base = &e.pos
sprite.SetHue(e.Hue)
sprite.SetScale(e.Scale, e.Scale)
sprite.Rotation = &e.rotation
scene.AddGraphics(sprite)
e.anim = ge.NewAnimation(sprite, -1)
e.anim.SetSecondsPerFrame(0.04)
}
func (e *explosion) Dispose() { e.anim.Sprite().Dispose() }
func (e *explosion) IsDisposed() bool { return e.anim.IsDisposed() }
func (e *explosion) Update(delta float64) {
if e.anim.Tick(delta * e.AnimationSpeed) {
e.Dispose()
}
if e.Rotating {
e.rotation += gmath.Rad(delta * 4)
}
}