Added subtle bg color shift, hex values added to screen.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"cosmos/diego/groovy"
|
||||
"image/color"
|
||||
"log"
|
||||
"math"
|
||||
"strconv"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2"
|
||||
@@ -15,11 +16,15 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
titleFont font.Face
|
||||
menuFont font.Face
|
||||
titleFont font.Face
|
||||
menuFont font.Face
|
||||
backgroundBaseColor color.RGBA
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
||||
backgroundBaseColor = color.RGBA{0x33, 0x33, 0x99, 0xFF}
|
||||
|
||||
tt, err := opentype.Parse(fonts.PressStart2P_ttf)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -46,14 +51,15 @@ func init() {
|
||||
}
|
||||
|
||||
type Menu struct {
|
||||
bgcolor color.RGBA
|
||||
options map[int]MenuOption
|
||||
events map[groovy.SceneEvent]func()
|
||||
bgcolor color.RGBA
|
||||
increment int
|
||||
options map[int]MenuOption
|
||||
events map[groovy.SceneEvent]func()
|
||||
}
|
||||
|
||||
func NewMenu() Menu {
|
||||
return Menu{
|
||||
bgcolor: color.RGBA{0x33, 0x33, 0x99, 0xFF},
|
||||
bgcolor: backgroundBaseColor,
|
||||
events: make(map[groovy.SceneEvent]func()),
|
||||
}
|
||||
}
|
||||
@@ -62,6 +68,9 @@ func (m *Menu) Draw(screen *ebiten.Image) {
|
||||
screen.Fill(m.bgcolor)
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -89,6 +98,7 @@ func (m *Menu) RenderOptions(screen *ebiten.Image) {
|
||||
}
|
||||
|
||||
func (m *Menu) Update() error {
|
||||
m.increment++
|
||||
|
||||
var keysPressed []ebiten.Key
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user