-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplash.go
106 lines (85 loc) · 1.99 KB
/
splash.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package splash
import (
"image/color"
"time"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/audio/mp3"
"github.com/FukuroNoOShiri/psyche/assets"
"github.com/FukuroNoOShiri/psyche/game"
"github.com/FukuroNoOShiri/psyche/tasks"
"github.com/FukuroNoOShiri/psyche/utils"
)
type scene struct {
Next game.Scene
bg color.RGBA
logo *utils.ImageWithOptions
sound1 *mp3.Stream
sound2 *mp3.Stream
canSkip bool
}
var Scene = &scene{}
var _ game.Scene = Scene
func (s *scene) Init() error {
s.bg = color.RGBA{249, 239, 214, 0}
logo, err := assets.Image("fukuronooshiri.jpg")
if err != nil {
return err
}
logoW, logoH := logo.Bounds().Dx(), logo.Bounds().Dy()
logoOpts := &ebiten.DrawImageOptions{}
logoOpts.GeoM.Translate(float64((1920-logoW)/2), float64((1080-logoH)/2))
s.logo = &utils.ImageWithOptions{Image: logo, Options: logoOpts}
sound1, err := assets.Mp3Stream("owl-sound-1.mp3")
if err != nil {
return err
}
s.sound1 = sound1
sound2, err := assets.Mp3Stream("owl-sound-2.mp3")
if err != nil {
return err
}
s.sound2 = sound2
game.Tasks.Add(tasks.After(500*time.Millisecond, func() error {
p, err := game.Audio.NewPlayer(sound1)
if err != nil {
return err
}
p.Play()
return nil
}))
game.Tasks.Add(tasks.After(3*time.Second, func() error {
s.canSkip = true
return nil
}))
game.Tasks.Add(tasks.After(6*time.Second, s.leave), "leave")
return nil
}
func (s *scene) Draw(screen *ebiten.Image) {
screen.Fill(s.bg)
s.logo.Draw(screen)
}
func (s *scene) Update() error {
if s.canSkip {
if ok, _ := utils.IsSomeKeyJustPressed(ebiten.KeySpace, ebiten.KeyEnter, ebiten.KeyEscape); ok {
game.Tasks.Cancel("leave")
s.canSkip = false
if err := s.leave(); err != nil {
return err
}
}
}
return nil
}
func (s *scene) leave() error {
p, err := game.Audio.NewPlayer(s.sound2)
if err != nil {
return err
}
p.Play()
return game.SetScene(s.Next)
}
func (s *scene) Dispose() {
s.logo = nil
s.sound1 = nil
s.sound2 = nil
}