Files

68 lines
1.4 KiB
Go
Raw Permalink Normal View History

package splashmenu
import (
"cosmos/diego/groovy"
splashmenu "cosmos/diego/groovy/examples/splashmenu/fonts"
"image/color"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/text"
)
2023-09-05 07:53:12 -04:00
const (
2023-09-05 19:28:25 -04:00
splashText = "schmoopysoft®"
splashSubtext = "\"how was the gravy\"\n- christorpher hollick"
2023-09-05 07:53:12 -04:00
)
type Splash struct {
2023-08-25 11:59:41 -04:00
Dimensions groovy.Area
bgcolor color.RGBA
increment int
events map[groovy.SceneEvent]func()
}
func NewSplash() Splash {
return Splash{
bgcolor: color.RGBA{0xFF, 0xFF, 0xFF, 0xFF},
events: make(map[groovy.SceneEvent]func()),
}
}
func (s *Splash) Update() error {
s.increment++
2023-09-05 07:53:12 -04:00
s.bgcolor.R = (s.bgcolor.R - 1) % 0xFF
s.bgcolor.G = (s.bgcolor.G - 1) % 0xFF
s.bgcolor.B = (s.bgcolor.B - 1) % 0xFF
if s.bgcolor.R == 0x00 {
s.events[groovy.COMPLETED]()
2023-08-23 02:01:01 -04:00
//scene cleanup (for next time)
s.increment = 0
2023-09-05 07:53:12 -04:00
s.bgcolor.R = 0xFF
s.bgcolor.G = 0xFF
s.bgcolor.B = 0xFF
}
return nil
}
func (s *Splash) Draw(screen *ebiten.Image) {
screen.Fill(s.bgcolor)
2023-09-05 07:53:12 -04:00
x := s.Dimensions.Width/2 - 400
y := s.Dimensions.Height / 2
text.Draw(screen, splashText, splashmenu.SplashFont.MegaTitle, x, y, color.White)
2023-09-05 19:28:25 -04:00
text.Draw(screen, splashSubtext, splashmenu.SplashFont.Title, x, y+40, color.White)
2023-08-25 11:59:41 -04:00
}
func (s *Splash) SetEventHandler(event groovy.SceneEvent, f func()) {
s.events[event] = f
}
// sets sene dimensions
func (s *Splash) SetDimensions(a groovy.Area) {
s.Dimensions = a
}