|
|
|
@@ -4,6 +4,7 @@ import (
|
|
|
|
"cosmos/diego/groovy"
|
|
|
|
"cosmos/diego/groovy"
|
|
|
|
"image/color"
|
|
|
|
"image/color"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
|
|
|
|
"math"
|
|
|
|
"strconv"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
@@ -17,9 +18,13 @@ import (
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
titleFont font.Face
|
|
|
|
titleFont font.Face
|
|
|
|
menuFont font.Face
|
|
|
|
menuFont font.Face
|
|
|
|
|
|
|
|
backgroundBaseColor color.RGBA
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
func init() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backgroundBaseColor = color.RGBA{0x33, 0x33, 0x99, 0xFF}
|
|
|
|
|
|
|
|
|
|
|
|
tt, err := opentype.Parse(fonts.PressStart2P_ttf)
|
|
|
|
tt, err := opentype.Parse(fonts.PressStart2P_ttf)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
log.Fatal(err)
|
|
|
|
@@ -47,13 +52,14 @@ func init() {
|
|
|
|
|
|
|
|
|
|
|
|
type Menu struct {
|
|
|
|
type Menu struct {
|
|
|
|
bgcolor color.RGBA
|
|
|
|
bgcolor color.RGBA
|
|
|
|
|
|
|
|
increment int
|
|
|
|
options map[int]MenuOption
|
|
|
|
options map[int]MenuOption
|
|
|
|
events map[groovy.SceneEvent]func()
|
|
|
|
events map[groovy.SceneEvent]func()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewMenu() Menu {
|
|
|
|
func NewMenu() Menu {
|
|
|
|
return Menu{
|
|
|
|
return Menu{
|
|
|
|
bgcolor: color.RGBA{0x33, 0x33, 0x99, 0xFF},
|
|
|
|
bgcolor: backgroundBaseColor,
|
|
|
|
events: make(map[groovy.SceneEvent]func()),
|
|
|
|
events: make(map[groovy.SceneEvent]func()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -62,6 +68,9 @@ func (m *Menu) Draw(screen *ebiten.Image) {
|
|
|
|
screen.Fill(m.bgcolor)
|
|
|
|
screen.Fill(m.bgcolor)
|
|
|
|
text.Draw(screen, "menu", titleFont, 40, 40, color.White)
|
|
|
|
text.Draw(screen, "menu", titleFont, 40, 40, color.White)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bgcolor := " 0x" + strconv.FormatUint(uint64(m.bgcolor.R), 16) + " 0x" + strconv.FormatUint(uint64(m.bgcolor.G), 16) + " 0x" + strconv.FormatUint(uint64(m.bgcolor.B), 16)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
text.Draw(screen, bgcolor, menuFont, 40, 700, color.White)
|
|
|
|
m.RenderOptions(screen)
|
|
|
|
m.RenderOptions(screen)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -89,6 +98,7 @@ func (m *Menu) RenderOptions(screen *ebiten.Image) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (m *Menu) Update() error {
|
|
|
|
func (m *Menu) Update() error {
|
|
|
|
|
|
|
|
m.increment++
|
|
|
|
|
|
|
|
|
|
|
|
var keysPressed []ebiten.Key
|
|
|
|
var keysPressed []ebiten.Key
|
|
|
|
keysPressed = inpututil.AppendPressedKeys(keysPressed[:0])
|
|
|
|
keysPressed = inpututil.AppendPressedKeys(keysPressed[:0])
|
|
|
|
@@ -103,5 +113,11 @@ func (m *Menu) Update() error {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
colorOffset := uint8(int(math.Sin(float64(m.increment)/300) * 6))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m.bgcolor.R = (colorOffset + backgroundBaseColor.R) % 0xFF
|
|
|
|
|
|
|
|
m.bgcolor.G = (colorOffset + backgroundBaseColor.G) % 0xFF
|
|
|
|
|
|
|
|
m.bgcolor.B = (colorOffset + backgroundBaseColor.B) % 0xFF
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|