2023-08-18 12:02:59 -04:00
|
|
|
package splashmenu
|
|
|
|
|
|
|
|
|
|
import (
|
2023-08-23 01:24:43 -04:00
|
|
|
"cosmos/diego/groovy"
|
2023-08-18 12:02:59 -04:00
|
|
|
"image/color"
|
|
|
|
|
"log"
|
|
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/examples/resources/fonts"
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/text"
|
|
|
|
|
"golang.org/x/image/font"
|
|
|
|
|
"golang.org/x/image/font/opentype"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
splashFont font.Face
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
tt, err := opentype.Parse(fonts.PressStart2P_ttf)
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const dpi = 72
|
|
|
|
|
splashFont, err = opentype.NewFace(tt, &opentype.FaceOptions{
|
|
|
|
|
Size: 12,
|
|
|
|
|
DPI: dpi,
|
|
|
|
|
Hinting: font.HintingVertical,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Splash struct {
|
|
|
|
|
bgcolor color.RGBA
|
|
|
|
|
increment int
|
2023-08-23 01:24:43 -04:00
|
|
|
events map[groovy.SceneEvent]func()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetSceneEvents implements groovy.Scene.
|
|
|
|
|
func (*Splash) GetSceneEvents() []groovy.SceneEvent {
|
|
|
|
|
return nil
|
2023-08-18 12:02:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewSplash() Splash {
|
|
|
|
|
return Splash{
|
2023-08-23 01:24:43 -04:00
|
|
|
bgcolor: color.RGBA{0xFF, 0xFF, 0xFF, 0xFF},
|
|
|
|
|
events: make(map[groovy.SceneEvent]func()),
|
2023-08-18 12:02:59 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Splash) Draw(screen *ebiten.Image) {
|
|
|
|
|
screen.Fill(s.bgcolor)
|
|
|
|
|
text.Draw(screen, "splash", splashFont, 40, 40, color.White)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Splash) Update() error {
|
|
|
|
|
s.increment++
|
|
|
|
|
|
|
|
|
|
s.bgcolor.R = (s.bgcolor.R - 2) % 0xFF
|
|
|
|
|
s.bgcolor.G = (s.bgcolor.G - 2) % 0xFF
|
|
|
|
|
s.bgcolor.B = (s.bgcolor.B - 2) % 0xFF
|
|
|
|
|
|
|
|
|
|
if s.bgcolor.R == 0x00 {
|
2023-08-23 01:24:43 -04:00
|
|
|
s.events[groovy.COMPLETED]()
|
2023-08-18 12:02:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-23 01:24:43 -04:00
|
|
|
func (s Splash) SetEventHandler(event groovy.SceneEvent, f func()) {
|
|
|
|
|
s.events[event] = f
|
2023-08-18 12:02:59 -04:00
|
|
|
}
|