-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.go
60 lines (42 loc) · 1.32 KB
/
menu.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package homebrawlapp
import (
"image/color"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
)
type Menu struct {
buttons []*Button
}
func InitMenu() *Menu {
startGameButton := InitButton(float64(ScreenWidth)/4, float64(ScreenHeight)/4, ScreenWidth/2, ScreenHeight/4, "start", color.White, ViewGameResult)
settingsButton := InitButton(float64(ScreenWidth)/4, float64(ScreenHeight)/2, ScreenWidth/2, ScreenHeight/4, "settings", color.White, ViewOptions)
return &Menu{
buttons: []*Button{
startGameButton,
settingsButton,
},
}
// Menu := ebiten.NewImage(ScreenWidth/2, ScreenHeight/2)
}
func (g *Game) DrawMenu(screen *ebiten.Image) {
// fmt.Println(ScreenHeight, ScreenWidth)
for _, button := range g.Menu.buttons {
screen.DrawImage(button.image, button.opts)
}
}
func (g *Game) UpdateMenu() {
// ScreenWidth, ScreenHeight := g.Layout()
// fmt.Println(ScreenHeight, ScreenWidth)
cursorX, cursorY := ebiten.CursorPosition()
for _, button := range g.Menu.buttons {
if button.LocationInside(cursorX, cursorY) {
button.image = button.highlightedImage
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
g.StartMatch()
return
}
} else {
button.image = button.normalImage
}
}
}