-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpop.go
More file actions
58 lines (49 loc) · 1.22 KB
/
Copy pathpop.go
File metadata and controls
58 lines (49 loc) · 1.22 KB
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
56
57
58
package main
import (
"github.com/creativeprojects/cavern/lib"
"github.com/hajimehoshi/ebiten/v2"
)
type PopType int
const (
PopFruit PopType = iota
PopOrb
)
// Pop animation
type Pop struct {
images [2][]*ebiten.Image
Type PopType
sprite *lib.Sprite
}
// NewPop creates a new blank pop animation.
func NewPop() *Pop {
i := &Pop{
images: [2][]*ebiten.Image{
{images["pop00"], images["pop01"], images["pop02"], images["pop03"], images["pop04"], images["pop05"], images["pop06"]},
{images["pop10"], images["pop11"], images["pop12"], images["pop13"], images["pop14"], images["pop15"], images["pop16"]},
},
sprite: lib.NewSprite(lib.XCentre, lib.YBottom),
}
return i
}
// Start (and restart) the pop animation on coordinates from another sprite (X centre & Y bottom)
func (i *Pop) Start(popType PopType, x, y float64) *Pop {
i.Type = popType
i.sprite.MoveTo(x, y).Animate(i.images[i.Type], nil, 2, false)
return i
}
func (i *Pop) Update() {
if i.HasExpired() {
return
}
i.sprite.Update()
}
func (i *Pop) Draw(screen *ebiten.Image) {
if i.HasExpired() {
return
}
i.sprite.Draw(screen)
}
// HasExpired returns true when the animation is finished
func (i *Pop) HasExpired() bool {
return i.sprite.IsFinished()
}