Files
groovy/examples/splashmenu/scenes/splash.go

56 lines
1.1 KiB
Go
Raw 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"
)
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++
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 {
s.events[groovy.COMPLETED]()
2023-08-23 02:01:01 -04:00
//scene cleanup (for next time)
s.increment = 0
}
return nil
}
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
}
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
}