2023-08-18 12:02:59 -04:00
|
|
|
package splashmenu
|
|
|
|
|
|
|
|
|
|
import (
|
2023-08-23 01:24:43 -04:00
|
|
|
"cosmos/diego/groovy"
|
2023-08-31 17:02:21 -04:00
|
|
|
splashmenu "cosmos/diego/groovy/examples/splashmenu/fonts"
|
2023-08-18 12:02:59 -04:00
|
|
|
"image/color"
|
|
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2/text"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Splash struct {
|
2023-08-25 11:59:41 -04:00
|
|
|
Dimensions groovy.Area
|
|
|
|
|
bgcolor color.RGBA
|
|
|
|
|
increment int
|
|
|
|
|
events map[groovy.SceneEvent]func()
|
2023-08-23 01:24:43 -04:00
|
|
|
}
|
|
|
|
|
|
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) 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-23 02:01:01 -04:00
|
|
|
|
|
|
|
|
//scene cleanup (for next time)
|
|
|
|
|
s.increment = 0
|
2023-08-18 12:02:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-31 17:02:21 -04:00
|
|
|
func (s *Splash) Draw(screen *ebiten.Image) {
|
|
|
|
|
screen.Fill(s.bgcolor)
|
|
|
|
|
text.Draw(screen, "splash", splashmenu.SplashFont.Splash, 40, 40, color.White)
|
2023-08-25 11:59:41 -04:00
|
|
|
}
|
|
|
|
|
|
2023-08-31 17:02:21 -04:00
|
|
|
func (s *Splash) SetEventHandler(event groovy.SceneEvent, f func()) {
|
2023-08-23 01:24:43 -04:00
|
|
|
s.events[event] = f
|
2023-08-18 12:02:59 -04:00
|
|
|
}
|
2023-08-31 17:02:21 -04:00
|
|
|
|
|
|
|
|
// sets sene dimensions
|
|
|
|
|
func (s *Splash) SetDimensions(a groovy.Area) {
|
|
|
|
|
s.Dimensions = a
|
|
|
|
|
}
|