-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsys_menu.go
75 lines (65 loc) · 1.47 KB
/
sys_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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package kar
import (
"image/color"
"kar/res"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/text/v2"
"github.com/hajimehoshi/ebiten/v2/vector"
)
type Menu struct {
drawOpt *text.DrawOptions
line int
text string
menuOffset Vec
}
func (m *Menu) Init() {
m.drawOpt = &text.DrawOptions{
DrawImageOptions: ebiten.DrawImageOptions{},
LayoutOptions: text.LayoutOptions{
LineSpacing: 18,
},
}
m.text = "SAVE\nMAIN MENU"
m.menuOffset = ScreenSize.Scale(0.5).Sub(Vec{20, 30})
m.drawOpt.ColorScale.ScaleWithColor(color.Gray{200})
}
func (m *Menu) Update() {
if inpututil.IsKeyJustPressed(ebiten.KeyArrowRight) {
switch m.line {
case 0:
SaveGame()
// previousGameState = "menu"
currentGameState = "playing"
colorM.Reset()
textDO.ColorScale.Reset()
case 1:
// previousGameState = "menu"
currentGameState = "mainmenu"
colorM.Reset()
textDO.ColorScale.Reset()
}
}
if inpututil.IsKeyJustPressed(ebiten.KeyW) {
m.line = (m.line - 1 + 2) % 2
}
if inpututil.IsKeyJustPressed(ebiten.KeyS) {
m.line = (m.line + 1) % 2
}
}
func (m *Menu) Draw() {
m.drawOpt.GeoM.Reset()
m.drawOpt.GeoM.Translate(m.menuOffset.X, m.menuOffset.Y)
// draw menu text
text.Draw(Screen, m.text, res.Font, m.drawOpt)
// draw selection box
vector.DrawFilledRect(
Screen,
float32(m.menuOffset.X-8),
float32(m.menuOffset.Y+float64(m.line*18))+5,
3,
7,
color.White,
false,
)
}